diff --git a/Cargo.toml b/Cargo.toml index 50cec8a..b198a67 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "compiletest_rs" -version = "0.2.2" +version = "0.2.3" authors = [ "The Rust Project Developers" , "Thomas Bracht Laumann Jespersen " , "Manish Goregaokar " diff --git a/src/common.rs b/src/common.rs index 5d52273..81cb927 100644 --- a/src/common.rs +++ b/src/common.rs @@ -183,4 +183,5 @@ pub struct Config { pub cflags: String, pub llvm_components: String, pub llvm_cxxflags: String, + pub nodejs: Option, } diff --git a/src/compiletest.rs b/src/compiletest.rs index 68e6f3a..f6ae497 100644 --- a/src/compiletest.rs +++ b/src/compiletest.rs @@ -82,6 +82,7 @@ pub fn default_config() -> Config { cflags: "cflags".to_string(), llvm_components: "llvm-components".to_string(), llvm_cxxflags: "llvm-cxxflags".to_string(), + nodejs: None, } } @@ -288,7 +289,7 @@ pub fn make_test_name(config: &Config, testpaths: &TestPaths) -> test::TestName pub fn make_test_closure(config: &Config, testpaths: &TestPaths) -> test::TestFn { let config = config.clone(); let testpaths = testpaths.clone(); - test::DynTestFn(Box::new(move || { + test::DynTestFn(Box::new(move |()| { runtest::run(config, &testpaths) })) } diff --git a/src/header.rs b/src/header.rs index 899a366..503a851 100644 --- a/src/header.rs +++ b/src/header.rs @@ -182,42 +182,32 @@ pub struct TestProps { // testing harness and used when generating compilation // arguments. (In particular, it propagates to the aux-builds.) pub incremental_dir: Option, + // Specifies that a cfail test must actually compile without errors. + pub must_compile_successfully: bool, } impl TestProps { pub fn new() -> Self { - let error_patterns = Vec::new(); - let aux_builds = Vec::new(); - let exec_env = Vec::new(); - let run_flags = None; - let pp_exact = None; - let check_lines = Vec::new(); - let build_aux_docs = false; - let force_host = false; - let check_stdout = false; - let no_prefer_dynamic = false; - let pretty_expanded = false; - let pretty_compare_only = false; - let forbid_output = Vec::new(); TestProps { - error_patterns: error_patterns, + error_patterns: vec![], compile_flags: vec![], - run_flags: run_flags, - pp_exact: pp_exact, - aux_builds: aux_builds, + run_flags: None, + pp_exact: None, + aux_builds: vec![], revisions: vec![], rustc_env: vec![], - exec_env: exec_env, - check_lines: check_lines, - build_aux_docs: build_aux_docs, - force_host: force_host, - check_stdout: check_stdout, - no_prefer_dynamic: no_prefer_dynamic, - pretty_expanded: pretty_expanded, + exec_env: vec![], + check_lines: vec![], + build_aux_docs: false, + force_host: false, + check_stdout: false, + no_prefer_dynamic: false, + pretty_expanded: false, pretty_mode: format!("normal"), - pretty_compare_only: pretty_compare_only, - forbid_output: forbid_output, + pretty_compare_only: false, + forbid_output: vec![], incremental_dir: None, + must_compile_successfully: false, } } @@ -313,6 +303,10 @@ impl TestProps { if let Some(of) = parse_forbid_output(ln) { self.forbid_output.push(of); } + + if !self.must_compile_successfully { + self.must_compile_successfully = parse_must_compile_successfully(ln); + } }); for key in vec!["RUST_TEST_NOCAPTURE", "RUST_TEST_THREADS"] { @@ -420,6 +414,10 @@ fn parse_pretty_compare_only(line: &str) -> bool { parse_name_directive(line, "pretty-compare-only") } +fn parse_must_compile_successfully(line: &str) -> bool { + parse_name_directive(line, "must-compile-successfully") +} + fn parse_env(line: &str, name: &str) -> Option<(String, String)> { parse_name_value_directive(line, name).map(|nv| { // nv is either FOO or FOO=BAR diff --git a/src/runtest.rs b/src/runtest.rs index 905791c..2030738 100644 --- a/src/runtest.rs +++ b/src/runtest.rs @@ -129,13 +129,21 @@ impl<'test> TestCx<'test> { fn run_cfail_test(&self) { let proc_res = self.compile_test(); - if proc_res.status.success() { - self.fatal_proc_rec( - &format!("{} test compiled successfully!", self.config.mode)[..], - &proc_res); - } + if self.props.must_compile_successfully { + if !proc_res.status.success() { + self.fatal_proc_rec( + "test compilation failed although it shouldn't!", + &proc_res); + } + } else { + if proc_res.status.success() { + self.fatal_proc_rec( + &format!("{} test compiled successfully!", self.config.mode)[..], + &proc_res); + } - self.check_correct_failure_status(&proc_res); + self.check_correct_failure_status(&proc_res); + } let output_to_check = self.get_output(&proc_res); let expected_errors = errors::load_errors(&self.testpaths.file, self.revision); @@ -147,6 +155,7 @@ impl<'test> TestCx<'test> { } else { self.check_error_patterns(&output_to_check, &proc_res); } + self.check_no_compiler_crash(&proc_res); self.check_forbid_output(&output_to_check, &proc_res); } @@ -943,8 +952,12 @@ actual:\n\ output_to_check: &str, proc_res: &ProcRes) { if self.props.error_patterns.is_empty() { - self.fatal(&format!("no error pattern specified in {:?}", - self.testpaths.file.display())); + if self.props.must_compile_successfully { + return + } else { + self.fatal(&format!("no error pattern specified in {:?}", + self.testpaths.file.display())); + } } let mut next_err_idx = 0; let mut next_err_pat = self.props.error_patterns[next_err_idx].trim(); @@ -1155,7 +1168,6 @@ actual:\n\ "arm-linux-androideabi" | "armv7-linux-androideabi" | "aarch64-linux-android" => { self._arm_exec_compiled_test(env) } - _=> { let aux_dir = self.aux_output_dir_name(); self.compose_and_run(self.make_run_args(), @@ -1408,7 +1420,7 @@ actual:\n\ fn make_exe_name(&self) -> PathBuf { let mut f = self.output_base_name(); // FIXME: This is using the host architecture exe suffix, not target! - if self.config.target == "asmjs-unknown-emscripten" { + if self.config.target.contains("emscripten") { let mut fname = f.file_name().unwrap().to_os_string(); fname.push(".js"); f.set_file_name(&fname); @@ -1426,8 +1438,9 @@ actual:\n\ let mut args = self.split_maybe_args(&self.config.runtool); // If this is emscripten, then run tests under nodejs - if self.config.target == "asmjs-unknown-emscripten" { - args.push("nodejs".to_owned()); + if self.config.target.contains("emscripten") { + let nodejs = self.config.nodejs.clone().unwrap_or("nodejs".to_string()); + args.push(nodejs); } let exe_file = self.make_exe_name(); diff --git a/src/util.rs b/src/util.rs index 2db5394..cad71c5 100644 --- a/src/util.rs +++ b/src/util.rs @@ -17,6 +17,7 @@ const OS_TABLE: &'static [(&'static str, &'static str)] = &[("android", "android ("darwin", "macos"), ("dragonfly", "dragonfly"), ("freebsd", "freebsd"), + ("haiku", "haiku"), ("ios", "ios"), ("linux", "linux"), ("mingw32", "windows"), @@ -42,7 +43,8 @@ const ARCH_TABLE: &'static [(&'static str, &'static str)] = &[("aarch64", "aarch ("sparc", "sparc"), ("x86_64", "x86_64"), ("xcore", "xcore"), - ("asmjs", "asmjs")]; + ("asmjs", "asmjs"), + ("wasm32", "wasm32")]; pub fn get_os(triple: &str) -> &'static str { for &(triple_os, os) in OS_TABLE {