1 //! The common code for `tests/lang_tests_*.rs`
3 env::{self, current_dir},
8 use lang_tester::LangTester;
11 /// Controls the compile options (e.g., optimization level) used to compile
13 #[allow(dead_code)] // Each test crate picks one variant
19 pub fn main_inner(profile: Profile) {
20 let tempdir = TempDir::new().expect("temp dir");
21 let current_dir = current_dir().expect("current dir");
22 let current_dir = current_dir.to_str().expect("current dir").to_string();
23 let gcc_path = include_str!("../gcc_path");
24 let gcc_path = gcc_path.trim();
25 env::set_var("LD_LIBRARY_PATH", gcc_path);
27 .test_dir("tests/run")
28 .test_file_filter(|path| path.extension().expect("extension").to_str().expect("to_str") == "rs")
29 .test_extract(|source| {
32 .skip_while(|l| !l.starts_with("//"))
33 .take_while(|l| l.starts_with("//"))
39 .test_cmds(move |path| {
40 // Test command 1: Compile `x.rs` into `tempdir/x`.
41 let mut exe = PathBuf::new();
43 exe.push(path.file_stem().expect("file_stem"));
44 let mut compiler = Command::new("rustc");
46 &format!("-Zcodegen-backend={}/target/debug/librustc_codegen_gcc.so", current_dir),
47 "--sysroot", &format!("{}/build_sysroot/sysroot/", current_dir),
51 "-o", exe.to_str().expect("to_str"),
52 path.to_str().expect("to_str"),
63 // Test command 2: run `tempdir/x`.
64 let runtime = Command::new(exe);
65 vec![("Compiler", compiler), ("Run-time", runtime)]