From fbc082dcc65d5bb37a4af09b731b01e860b8c5bf Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 26 Apr 2016 10:51:14 -0700 Subject: move auxiliary builds to a test-relative `aux` Instead of finding aux-build files in `auxiliary`, we now search for an `aux` directory relative to the test. So if your test is `compile-fail/foo.rs`, we would look in `compile-fail/aux`. Similarly, we ignore the `aux` directory when searching for tets. --- src/tools/compiletest/src/header.rs | 4 +- src/tools/compiletest/src/main.rs | 78 ++++++++++++++++++------------------ src/tools/compiletest/src/runtest.rs | 23 ++++++++--- 3 files changed, 61 insertions(+), 44 deletions(-) (limited to 'src/tools') diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index d75b3b71a99..b5cebe2e3ea 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -134,7 +134,9 @@ pub struct TestProps { // If present, the name of a file that this test should match when // pretty-printed pub pp_exact: Option, - // Modules from aux directory that should be compiled + // Other crates that should be compiled (typically from the same + // directory as the test, but for backwards compatibility reasons + // we also check the auxiliary directory) pub aux_builds: Vec , // Environment settings to use for compiling pub rustc_env: Vec<(String,String)> , diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index 45c69eec542..3ab08021717 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -30,6 +30,7 @@ extern crate log; extern crate env_logger; use std::env; +use std::ffi::OsString; use std::fs; use std::io; use std::path::{Path, PathBuf}; @@ -335,21 +336,24 @@ fn collect_tests_from_dir(config: &Config, } } + // If we find a test foo/bar.rs, we have to build the + // output directory `$build/foo` so we can write + // `$build/foo/bar` into it. We do this *now* in this + // sequential loop because otherwise, if we do it in the + // tests themselves, they race for the privilege of + // creating the directories and sometimes fail randomly. + let build_dir = config.build_base.join(&relative_dir_path); + fs::create_dir_all(&build_dir).unwrap(); + + // Add each `.rs` file as a test, and recurse further on any + // subdirectories we find, except for `aux` directories. let dirs = fs::read_dir(dir)?; for file in dirs { let file = file?; let file_path = file.path(); - debug!("inspecting file {:?}", file_path.display()); - if is_test(config, &file_path) { - // If we find a test foo/bar.rs, we have to build the - // output directory `$build/foo` so we can write - // `$build/foo/bar` into it. We do this *now* in this - // sequential loop because otherwise, if we do it in the - // tests themselves, they race for the privilege of - // creating the directories and sometimes fail randomly. - let build_dir = config.build_base.join(&relative_dir_path); - fs::create_dir_all(&build_dir).unwrap(); - + let file_name = file.file_name(); + if is_test(&file_name) { + debug!("found test file: {:?}", file_path.display()); let paths = TestPaths { file: file_path, base: base.to_path_buf(), @@ -358,41 +362,39 @@ fn collect_tests_from_dir(config: &Config, tests.push(make_test(config, &paths)) } else if file_path.is_dir() { let relative_file_path = relative_dir_path.join(file.file_name()); - collect_tests_from_dir(config, - base, - &file_path, - &relative_file_path, - tests)?; + if &file_name == "aux" { + // `aux` directories contain other crates used for + // cross-crate tests. Don't search them for tests, but + // do create a directory in the build dir for them, + // since we will dump intermediate output in there + // sometimes. + let build_dir = config.build_base.join(&relative_file_path); + fs::create_dir_all(&build_dir).unwrap(); + } else { + debug!("found directory: {:?}", file_path.display()); + collect_tests_from_dir(config, + base, + &file_path, + &relative_file_path, + tests)?; + } + } else { + debug!("found other file/directory: {:?}", file_path.display()); } } Ok(()) } -pub fn is_test(config: &Config, testfile: &Path) -> bool { - // Pretty-printer does not work with .rc files yet - let valid_extensions = - match config.mode { - Pretty => vec!(".rs".to_owned()), - _ => vec!(".rc".to_owned(), ".rs".to_owned()) - }; - let invalid_prefixes = vec!(".".to_owned(), "#".to_owned(), "~".to_owned()); - let name = testfile.file_name().unwrap().to_str().unwrap(); - - let mut valid = false; +pub fn is_test(file_name: &OsString) -> bool { + let file_name = file_name.to_str().unwrap(); - for ext in &valid_extensions { - if name.ends_with(ext) { - valid = true; - } - } - - for pre in &invalid_prefixes { - if name.starts_with(pre) { - valid = false; - } + if !file_name.ends_with(".rs") { + return false; } - return valid; + // `.`, `#`, and `~` are common temp-file prefixes. + let invalid_prefixes = &[".", "#", "~"]; + !invalid_prefixes.iter().any(|p| file_name.starts_with(p)) } pub fn make_test(config: &Config, testpaths: &TestPaths) -> test::TestDescAndFn { diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 98dfdb08a7f..858cecf8612 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1147,14 +1147,27 @@ actual:\n\ } } + /// For each `aux-build: foo/bar` annotation, we check to find the + /// file in a `aux` directory relative to the test itself. fn compute_aux_test_paths(&self, rel_ab: &str) -> TestPaths { - let abs_ab = self.config.aux_base.join(rel_ab); + let test_ab = self.testpaths.file + .parent() + .expect("test file path has no parent") + .join("aux") + .join(rel_ab); + if !test_ab.exists() { + self.fatal(&format!("aux-build `{}` source not found", test_ab.display())) + } + TestPaths { - file: abs_ab, + file: test_ab, base: self.testpaths.base.clone(), - relative_dir: Path::new(rel_ab).parent() - .map(|p| p.to_path_buf()) - .unwrap_or_else(|| PathBuf::new()) + relative_dir: self.testpaths.relative_dir + .join("aux") + .join(rel_ab) + .parent() + .expect("aux-build path has no parent") + .to_path_buf() } } -- cgit 1.4.1-3-g733a5