on master help sign in
Let the compile-tests crate build for non-test builds
commitc0017ed98b2d09786f855d3325489cf5815187c7 authorNick Fitzgerald <fitzgen@gmail.com> dateWed 30 Jan 2019, 09:57 (8 years ago) parent47ac911
1 file changed+19−17
compile-tests/src/main.rs+19−17
compile-tests/src/main.rs+19−17
@@ -1,24 +1,26 @@
1−#![cfg(test)]
1+fn main() {}
22
3−extern crate compiletest_rs as compiletest;
3+#[cfg(test)]
4+mod tests {
5+ extern crate compiletest_rs as compiletest;
6+ use std::path::PathBuf;
47
5−use std::path::PathBuf;
8+ fn run_mode(mode: &'static str) {
9+ let mut config = self::compiletest::Config::default();
610
7−fn run_mode(mode: &'static str) {
8− let mut config = compiletest::Config::default();
11+ config.mode = mode.parse().expect("Invalid mode");
12+ config.src_base = PathBuf::from(format!("{}", mode));
913
10− config.mode = mode.parse().expect("Invalid mode");
11− config.src_base = PathBuf::from(format!("{}", mode));
14+ // Populate config.target_rustcflags with dependencies on the path.
15+ config.link_deps();
16+ // If your tests import the parent crate, this helps with E0464
17+ config.clean_rmeta();
1218
13− // Populate config.target_rustcflags with dependencies on the path.
14− config.link_deps();
15− // If your tests import the parent crate, this helps with E0464
16− config.clean_rmeta();
19+ compiletest::run_tests(&config);
20+ }
1721
18− compiletest::run_tests(&config);
19−}
20−
21−#[test]
22−fn compile_test() {
23− run_mode("compile-fail");
22+ #[test]
23+ fn compile_test() {
24+ run_mode("compile-fail");
25+ }
2426}