diff options
author | Andrey Pushkar <mail@apushkar.me> | 2020-08-01 19:26:16 +0300 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2021-01-10 15:39:20 +0100 |
commit | 51778893c4cb18eb11cbfe83a72046f7cb0f3eac (patch) | |
tree | dff6e83c252ab6c6475274445f28b3933123d33a /tests/tests.rs | |
parent | 9de0d64fc041633c6d0a386a577ddf8ba25dafc3 (diff) |
Use absolute paths for unsaved files passed to clang and prepend -include directives to them.
Fixes #1771
Closes #1857
Diffstat (limited to 'tests/tests.rs')
-rw-r--r-- | tests/tests.rs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/tests.rs b/tests/tests.rs index 8b5a91f7..cd621177 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -474,6 +474,60 @@ fn test_multiple_header_calls_in_builder() { } #[test] +fn test_multiple_header_contents() { + let actual = builder() + .header_contents("test.h", "int foo(const char* a);") + .header_contents("test2.h", "float foo2(const char* b);") + .clang_arg("--target=x86_64-unknown-linux") + .generate() + .unwrap() + .to_string(); + + let (actual, stderr) = rustfmt(actual); + println!("{}", stderr); + + let (expected, _) = rustfmt( + "extern \"C\" { + pub fn foo2(b: *const ::std::os::raw::c_char) -> f32; +} +extern \"C\" { + pub fn foo(a: *const ::std::os::raw::c_char) -> ::std::os::raw::c_int; +} +" + .to_string(), + ); + + assert_eq!(expected, actual); +} + +#[test] +fn test_mixed_header_and_header_contents() { + let actual = builder() + .header(concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/headers/func_ptr.h" + )) + .header(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/headers/char.h")) + .header_contents("test.h", "int bar(const char* a);") + .header_contents("test2.h", "float bar2(const char* b);") + .clang_arg("--target=x86_64-unknown-linux") + .generate() + .unwrap() + .to_string(); + + let (actual, stderr) = rustfmt(actual); + println!("{}", stderr); + + let expected = include_str!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/expectations/tests/test_mixed_header_and_header_contents.rs" + )); + let (expected, _) = rustfmt(expected.to_string()); + + assert_eq!(expected, actual); +} + +#[test] // Doesn't support executing sh file on Windows. // We may want to implement it in Rust so that we support all systems. #[cfg(not(target_os = "windows"))] |