]> git.lizzy.rs Git - rust.git/blob - tests/compile-test.rs
c7cdb974caea75a0bffd9099e9350b5f4a13da51
[rust.git] / tests / compile-test.rs
1 use std::{env, fs};
2 use std::process::{Command, Output};
3
4 fn run_miri(file: &str, sysroot: &str) -> Output {
5     Command::new("cargo")
6         .args(&["run", "--", "--sysroot", sysroot, file])
7         .output()
8         .unwrap_or_else(|e| panic!("failed to execute process: {}", e))
9 }
10
11 #[test]
12 fn run_pass() {
13     let sysroot = env::var("RUST_SYSROOT").expect("env variable `RUST_SYSROOT` not set");
14
15     let test_files = fs::read_dir("./tests/run-pass/")
16                          .expect("Can't read `run-pass` directory")
17                          .filter_map(|entry| entry.ok())
18                          .filter(|entry| {
19                              entry.clone()
20                                   .file_type()
21                                   .map(|x| x.is_file())
22                                   .unwrap_or(false)
23                          })
24                          .filter_map(|entry| entry.path().to_str().map(|x| x.to_string()));
25
26     for file in test_files {
27         println!("{}: compile test running", file);  
28
29         let test_run = run_miri(&file, &sysroot);
30
31         if test_run.status.code().unwrap_or(-1) != 0 {
32             println!("{}: error {:?}", file, test_run);
33         } else {
34             println!("{}: ok", file);
35         }
36     }
37 }