From f6f393996b5d6f0ba010faaa55f41564ceda8dee Mon Sep 17 00:00:00 2001 From: Pascal Hertleif Date: Thu, 14 Apr 2016 12:31:42 +0200 Subject: [PATCH] Add Compile Test --- tests/compile-test.rs | 37 ++++++++++++++++++++++ {test => tests/run-pass}/arrays.rs | 0 {test => tests/run-pass}/bools.rs | 0 {test => tests/run-pass}/c_enums.rs | 0 {test => tests/run-pass}/calls.rs | 0 {test => tests/run-pass}/closures.rs | 0 {test => tests/run-pass}/errors.rs | 0 {test => tests/run-pass}/heap.rs | 0 {test => tests/run-pass}/ints.rs | 0 {test => tests/run-pass}/loops.rs | 0 {test => tests/run-pass}/pointers.rs | 0 {test => tests/run-pass}/products.rs | 0 {test => tests/run-pass}/specialization.rs | 0 {test => tests/run-pass}/std.rs | 0 {test => tests/run-pass}/strings.rs | 0 {test => tests/run-pass}/sums.rs | 0 {test => tests/run-pass}/trivial.rs | 0 {test => tests/run-pass}/vecs.rs | 0 18 files changed, 37 insertions(+) create mode 100644 tests/compile-test.rs rename {test => tests/run-pass}/arrays.rs (100%) rename {test => tests/run-pass}/bools.rs (100%) rename {test => tests/run-pass}/c_enums.rs (100%) rename {test => tests/run-pass}/calls.rs (100%) rename {test => tests/run-pass}/closures.rs (100%) rename {test => tests/run-pass}/errors.rs (100%) rename {test => tests/run-pass}/heap.rs (100%) rename {test => tests/run-pass}/ints.rs (100%) rename {test => tests/run-pass}/loops.rs (100%) rename {test => tests/run-pass}/pointers.rs (100%) rename {test => tests/run-pass}/products.rs (100%) rename {test => tests/run-pass}/specialization.rs (100%) rename {test => tests/run-pass}/std.rs (100%) rename {test => tests/run-pass}/strings.rs (100%) rename {test => tests/run-pass}/sums.rs (100%) rename {test => tests/run-pass}/trivial.rs (100%) rename {test => tests/run-pass}/vecs.rs (100%) diff --git a/tests/compile-test.rs b/tests/compile-test.rs new file mode 100644 index 000000000000..c7cdb974caea --- /dev/null +++ b/tests/compile-test.rs @@ -0,0 +1,37 @@ +use std::{env, fs}; +use std::process::{Command, Output}; + +fn run_miri(file: &str, sysroot: &str) -> Output { + Command::new("cargo") + .args(&["run", "--", "--sysroot", sysroot, file]) + .output() + .unwrap_or_else(|e| panic!("failed to execute process: {}", e)) +} + +#[test] +fn run_pass() { + let sysroot = env::var("RUST_SYSROOT").expect("env variable `RUST_SYSROOT` not set"); + + let test_files = fs::read_dir("./tests/run-pass/") + .expect("Can't read `run-pass` directory") + .filter_map(|entry| entry.ok()) + .filter(|entry| { + entry.clone() + .file_type() + .map(|x| x.is_file()) + .unwrap_or(false) + }) + .filter_map(|entry| entry.path().to_str().map(|x| x.to_string())); + + for file in test_files { + println!("{}: compile test running", file); + + let test_run = run_miri(&file, &sysroot); + + if test_run.status.code().unwrap_or(-1) != 0 { + println!("{}: error {:?}", file, test_run); + } else { + println!("{}: ok", file); + } + } +} diff --git a/test/arrays.rs b/tests/run-pass/arrays.rs similarity index 100% rename from test/arrays.rs rename to tests/run-pass/arrays.rs diff --git a/test/bools.rs b/tests/run-pass/bools.rs similarity index 100% rename from test/bools.rs rename to tests/run-pass/bools.rs diff --git a/test/c_enums.rs b/tests/run-pass/c_enums.rs similarity index 100% rename from test/c_enums.rs rename to tests/run-pass/c_enums.rs diff --git a/test/calls.rs b/tests/run-pass/calls.rs similarity index 100% rename from test/calls.rs rename to tests/run-pass/calls.rs diff --git a/test/closures.rs b/tests/run-pass/closures.rs similarity index 100% rename from test/closures.rs rename to tests/run-pass/closures.rs diff --git a/test/errors.rs b/tests/run-pass/errors.rs similarity index 100% rename from test/errors.rs rename to tests/run-pass/errors.rs diff --git a/test/heap.rs b/tests/run-pass/heap.rs similarity index 100% rename from test/heap.rs rename to tests/run-pass/heap.rs diff --git a/test/ints.rs b/tests/run-pass/ints.rs similarity index 100% rename from test/ints.rs rename to tests/run-pass/ints.rs diff --git a/test/loops.rs b/tests/run-pass/loops.rs similarity index 100% rename from test/loops.rs rename to tests/run-pass/loops.rs diff --git a/test/pointers.rs b/tests/run-pass/pointers.rs similarity index 100% rename from test/pointers.rs rename to tests/run-pass/pointers.rs diff --git a/test/products.rs b/tests/run-pass/products.rs similarity index 100% rename from test/products.rs rename to tests/run-pass/products.rs diff --git a/test/specialization.rs b/tests/run-pass/specialization.rs similarity index 100% rename from test/specialization.rs rename to tests/run-pass/specialization.rs diff --git a/test/std.rs b/tests/run-pass/std.rs similarity index 100% rename from test/std.rs rename to tests/run-pass/std.rs diff --git a/test/strings.rs b/tests/run-pass/strings.rs similarity index 100% rename from test/strings.rs rename to tests/run-pass/strings.rs diff --git a/test/sums.rs b/tests/run-pass/sums.rs similarity index 100% rename from test/sums.rs rename to tests/run-pass/sums.rs diff --git a/test/trivial.rs b/tests/run-pass/trivial.rs similarity index 100% rename from test/trivial.rs rename to tests/run-pass/trivial.rs diff --git a/test/vecs.rs b/tests/run-pass/vecs.rs similarity index 100% rename from test/vecs.rs rename to tests/run-pass/vecs.rs