diff options
author | Nick Fitzgerald <fitzgen@gmail.com> | 2017-11-28 11:34:43 -0800 |
---|---|---|
committer | Nick Fitzgerald <fitzgen@gmail.com> | 2017-11-28 11:34:43 -0800 |
commit | 1c2172f7516ae90edfcfdc9a71849c8a37fc97fa (patch) | |
tree | 21cb259fec5d80aa8f186de949419971c3dc39df | |
parent | 5011ddcf97ac7f09eb967dfe24f7d40d3fb3eb80 (diff) |
Ensure that we run layout tests from libclang version-specific expectations
This adds a build.rs to generate
#[path="$FILE"]
mod $FILE_AS_IDENT;
for each $FILE in our libclang version-specific directories. We need to do this
to get those files' layout tests to run because cargo doesn't automatically pick
up tests in subdirectories.
-rw-r--r-- | tests/expectations/build.rs | 60 | ||||
-rw-r--r-- | tests/expectations/tests/libclang_version_specific_generated_tests.rs | 1 |
2 files changed, 61 insertions, 0 deletions
diff --git a/tests/expectations/build.rs b/tests/expectations/build.rs new file mode 100644 index 00000000..0727ce51 --- /dev/null +++ b/tests/expectations/build.rs @@ -0,0 +1,60 @@ +//! Generate a module with a custom `#[path=...]` for each of the files in our +//! libclang version-specific test expectations so that they get their layout +//! tests run. We need to do this because cargo doesn't automatically detect +//! tests subdirectories. + +use std::env; +use std::fs; +use std::io::Write; +use std::path::Path; + +const LIBCLANG_VERSION_DIRS: &'static [&'static str] = + &["libclang-3.8", "libclang-3.9", "libclang-4"]; + +fn main() { + println!("cargo:rerun-if-changed=build.rs"); + + let mut test_string = String::new(); + + for dir in LIBCLANG_VERSION_DIRS { + let dir = Path::new(&env::var_os("CARGO_MANIFEST_DIR").unwrap()) + .join("tests") + .join(dir); + + println!("cargo:rerun-if-changed={}", dir.display()); + + for entry in fs::read_dir(dir).unwrap() { + let entry = entry.unwrap(); + let path = entry.path(); + let path = path.canonicalize().unwrap_or_else(|_| path.into()); + if path.extension().map(|e| e.to_string_lossy()) != Some("rs".into()) { + continue; + } + + println!("cargo:rerun-if-changed={}", path.display()); + + let module_name: String = path.display() + .to_string() + .chars() + .map(|c| match c { + 'a'...'z' | 'A'...'Z' | '0'...'9' => c, + _ => '_', + }) + .collect(); + + test_string.push_str(&format!( + r###" +#[path = "{}"] +mod {}; +"###, + path.display(), + module_name, + )); + } + } + + let out_path = Path::new(&env::var_os("OUT_DIR").unwrap()) + .join("libclang_version_specific_generated_tests.rs"); + let mut test_file = fs::File::create(out_path).unwrap(); + test_file.write_all(test_string.as_bytes()).unwrap(); +} diff --git a/tests/expectations/tests/libclang_version_specific_generated_tests.rs b/tests/expectations/tests/libclang_version_specific_generated_tests.rs new file mode 100644 index 00000000..93cf0d47 --- /dev/null +++ b/tests/expectations/tests/libclang_version_specific_generated_tests.rs @@ -0,0 +1 @@ +include!(concat!(env!("OUT_DIR"), "/libclang_version_specific_generated_tests.rs")); |