From 60d583d8722524bf4bb30b4ea3d6d9bc6bdd669f Mon Sep 17 00:00:00 2001 From: Evgenii Ponomarev Date: Fri, 1 Nov 2019 16:48:48 +0800 Subject: [PATCH] Use trybuild for compiletest Closes #193. --- .travis.yml | 2 +- test_suite/Cargo.toml | 5 +-- .../tests/compile-fail/private_flags.rs | 2 +- .../tests/compile-fail/private_flags.stderr | 5 +++ test_suite/tests/compiletest.rs | 34 ++----------------- 5 files changed, 11 insertions(+), 37 deletions(-) create mode 100644 test_suite/tests/compile-fail/private_flags.stderr diff --git a/.travis.yml b/.travis.yml index 9dd45c4..79fdda2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ matrix: - LABEL="compiletest" script: - cargo test - - cargo test -p test_suite --features unstable + - cargo test -p test_suite - rust: stable - rust: stable os: osx diff --git a/test_suite/Cargo.toml b/test_suite/Cargo.toml index 2a02d80..057a022 100644 --- a/test_suite/Cargo.toml +++ b/test_suite/Cargo.toml @@ -2,12 +2,9 @@ name = "test_suite" version = "0.0.0" -[features] -unstable = ["compiletest_rs"] - [dependencies] bitflags = { path = "../" } -compiletest_rs = { version = "0.3.18", optional = true, features=["stable"] } +trybuild = "1.0" serde = "1.0" serde_derive = "1.0" serde_json = "1.0" diff --git a/test_suite/tests/compile-fail/private_flags.rs b/test_suite/tests/compile-fail/private_flags.rs index d31c28d..35089bc 100644 --- a/test_suite/tests/compile-fail/private_flags.rs +++ b/test_suite/tests/compile-fail/private_flags.rs @@ -16,5 +16,5 @@ mod example { fn main() { let flag1 = example::Flags1::FLAG_A; - let flag2 = example::Flags2::FLAG_B; //~ ERROR struct `Flags2` is private + let flag2 = example::Flags2::FLAG_B; } diff --git a/test_suite/tests/compile-fail/private_flags.stderr b/test_suite/tests/compile-fail/private_flags.stderr new file mode 100644 index 0000000..6374819 --- /dev/null +++ b/test_suite/tests/compile-fail/private_flags.stderr @@ -0,0 +1,5 @@ +error[E0603]: struct `Flags2` is private + --> $DIR/private_flags.rs:19:26 + | +19 | let flag2 = example::Flags2::FLAG_B; + | ^^^^^^ diff --git a/test_suite/tests/compiletest.rs b/test_suite/tests/compiletest.rs index 2beeae0..db50dfd 100644 --- a/test_suite/tests/compiletest.rs +++ b/test_suite/tests/compiletest.rs @@ -1,33 +1,5 @@ -#![cfg(feature = "unstable")] - -extern crate compiletest_rs as compiletest; - -use std::fs; -use std::result::Result; - -use compiletest::common::Mode; - -fn run_mode(mode: Mode) { - let config = compiletest::Config { - mode: mode, - src_base: format!("tests/{}", mode).into(), - target_rustcflags: fs::read_dir("../target/debug/deps") - .unwrap() - .map(Result::unwrap) - .filter(|entry| { - let file_name = entry.file_name(); - let file_name = file_name.to_string_lossy(); - file_name.starts_with("libbitflags-") && file_name.ends_with(".rlib") - }) - .max_by_key(|entry| entry.metadata().unwrap().modified().unwrap()) - .map(|entry| format!("--extern bitflags={}", entry.path().to_string_lossy())), - ..Default::default() - }; - - compiletest::run_tests(&config); -} - #[test] -fn compile_test() { - run_mode(Mode::CompileFail); +fn compile_fail() { + let t = trybuild::TestCases::new(); + t.compile_fail("tests/compile-fail/*.rs"); }