From c631049efcadca8b07940c794cce2be58fa48444 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 3 Nov 2018 17:02:41 +0100 Subject: v0.4.0 closes #32 closes #33 --- tests/compiletest.rs | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/compiletest.rs (limited to 'tests/compiletest.rs') diff --git a/tests/compiletest.rs b/tests/compiletest.rs new file mode 100644 index 0000000..acc8954 --- /dev/null +++ b/tests/compiletest.rs @@ -0,0 +1,59 @@ +use std::{fs, path::PathBuf, process::Command}; + +use compiletest_rs::{common::Mode, Config}; +use tempdir::TempDir; + +#[test] +fn cfail() { + let mut config = Config::default(); + + config.mode = Mode::CompileFail; + config.src_base = PathBuf::from("tests/cfail"); + config.link_deps(); + + // remove duplicate and trailing `-L` flags + let mut s = String::new(); + if let Some(flags) = config.target_rustcflags.as_mut() { + let mut iter = flags.split_whitespace().peekable(); + + while let Some(flag) = iter.next() { + if flag == "-L" && (iter.peek() == Some(&"-L") || iter.peek() == None) { + iter.next(); + continue; + } + + s += flag; + s += " "; + } + + // path to proc-macro crate + s += "-L target/debug/deps "; + + // avoid "error: language item required, but not found: `eh_personality`" + s += "-C panic=abort "; + } + + let td = TempDir::new("rtfm").unwrap(); + for f in fs::read_dir("tests/cpass").unwrap() { + let f = f.unwrap().path(); + let name = f.file_stem().unwrap().to_str().unwrap(); + + assert!( + Command::new("rustc") + .args(s.split_whitespace()) + .arg(f.display().to_string()) + .arg("-o") + .arg(td.path().join(name).display().to_string()) + .arg("-C") + .arg("linker=true") + .status() + .unwrap() + .success() + ); + } + + config.target_rustcflags = Some(s); + config.clean_rmeta(); + + compiletest_rs::run_tests(&config); +} -- cgit v1.2.3