From e42efed9c8de98b7f5344a39f4f7cd61a43627d9 Mon Sep 17 00:00:00 2001 From: Philip Munksgaard Date: Wed, 13 Nov 2019 12:09:35 +0100 Subject: [PATCH 1/3] Make rustc an opt-in feature, use tester for test crate --- .travis.yml | 8 ++++---- Cargo.toml | 5 ++--- appveyor.yml | 5 +++-- build.rs | 2 +- src/common.rs | 12 ++++++------ src/lib.rs | 12 ++---------- test-project/Cargo.toml | 2 +- test-project/tests/tests.rs | 4 ++-- 8 files changed, 21 insertions(+), 29 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7d5e75d..08c5042 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,15 +2,15 @@ language: rust matrix: include: - rust: nightly - env: FEATURES="" + env: FEATURES="--features rustc" before_script: rustup component add rustc-dev - rust: beta - env: FEATURES="--features stable" + env: FEATURES="" - rust: stable - env: FEATURES="--features stable" + env: FEATURES="" - rust: nightly - env: FEATURES="--features stable" + env: FEATURES="" script: cd test-project && cargo test $FEATURES diff --git a/Cargo.toml b/Cargo.toml index e310347..bf5da92 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ serde = "1.0" serde_json = "1.0" serde_derive = "1.0" rustfix = "0.4.1" -tester = { version = "0.5", optional = true } +tester = { version = "0.5" } [target."cfg(unix)".dependencies] libc = "0.2" @@ -36,5 +36,4 @@ winapi = { version = "0.3", features = ["winerror"] } [features] tmp = ["tempfile"] -norustc = [] -stable = ["norustc", "tester"] +rustc = [] diff --git a/appveyor.yml b/appveyor.yml index ad4a569..ca321fd 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -9,6 +9,7 @@ install: - curl -sSf -o rustup-init.exe https://win.rustup.rs - rustup-init.exe --default-host %TARGET% --default-toolchain %CHANNEL% -y - set PATH=%PATH%;C:\Users\appveyor\.cargo\bin;C:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin + - if %CHANNEL%==nightly (rustup component add rustc-dev) else (true) - gcc --version - rustc -Vv - cargo -V @@ -16,8 +17,8 @@ install: build: false test_script: - - if %CHANNEL%==stable (cargo build --features stable) else (cargo build) - - cd test-project && if %CHANNEL%==stable (cargo test --features stable) else (cargo test) + - if %CHANNEL%==nightly (cargo build --features rustc) else (cargo build) + - cd test-project && if %CHANNEL%==nightly (cargo test --features rustc) else (cargo test) branches: only: diff --git a/build.rs b/build.rs index 4976ab5..c72d9e5 100644 --- a/build.rs +++ b/build.rs @@ -1,7 +1,7 @@ use std::env; pub fn main() { - if env::var("CARGO_FEATURE_NORUSTC").is_ok() { + if env::var("CARGO_FEATURE_RUSTC").is_err() { println!("cargo:rustc-env=TARGET={}", env::var("TARGET").unwrap()); println!("cargo:rustc-env=HOST={}", env::var("HOST").unwrap()); } diff --git a/src/common.rs b/src/common.rs index 644175c..898a443 100644 --- a/src/common.rs +++ b/src/common.rs @@ -14,7 +14,7 @@ use std::fmt; use std::fs::{read_dir, remove_file}; use std::str::FromStr; use std::path::PathBuf; -#[cfg(not(feature = "norustc"))] +#[cfg(feature = "rustc")] use rustc; use test::ColorConfig; @@ -331,7 +331,7 @@ pub use self::config_tempdir::ConfigWithTemp; impl Default for Config { fn default() -> Config { - #[cfg(not(feature = "norustc"))] + #[cfg(feature = "rustc")] let platform = rustc::session::config::host_triple().to_string(); Config { @@ -355,13 +355,13 @@ impl Default for Config { runtool: None, host_rustcflags: None, target_rustcflags: None, - #[cfg(not(feature = "norustc"))] + #[cfg(feature = "rustc")] target: platform.clone(), - #[cfg(feature = "norustc")] + #[cfg(not(feature = "rustc"))] target: env!("TARGET").to_string(), - #[cfg(not(feature = "norustc"))] + #[cfg(feature = "rustc")] host: platform.clone(), - #[cfg(feature = "norustc")] + #[cfg(not(feature = "rustc"))] host: env!("HOST").to_string(), rustfix_coverage: false, gdb: None, diff --git a/src/lib.rs b/src/lib.rs index ea80202..96f8f89 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,12 +10,11 @@ #![crate_type = "lib"] -#![cfg_attr(not(feature = "norustc"), feature(rustc_private))] -#![cfg_attr(not(feature = "stable"), feature(test))] +#![cfg_attr(feature = "rustc", feature(rustc_private))] #![deny(unused_imports)] -#[cfg(not(feature = "norustc"))] +#[cfg(feature = "rustc")] extern crate rustc; #[cfg(unix)] @@ -110,8 +109,6 @@ pub fn test_opts(config: &Config) -> test::TestOpts { test::TestOpts { filter: config.filter.clone(), filter_exact: config.filter_exact, - #[cfg(not(feature = "stable"))] - exclude_should_panic: false, run_ignored: if config.run_ignored { test::RunIgnored::Yes } else { test::RunIgnored::No }, format: if config.quiet { test::OutputFormat::Terse } else { test::OutputFormat::Pretty }, logfile: config.logfile.clone(), @@ -126,8 +123,6 @@ pub fn test_opts(config: &Config) -> test::TestOpts { skip: vec![], list: false, options: test::Options::new(), - #[cfg(not(feature = "stable"))] - time_options: None, } } @@ -259,8 +254,6 @@ pub fn make_test(config: &Config, testpaths: &TestPaths) -> test::TestDescAndFn ignore: early_props.ignore, should_panic: should_panic, allow_fail: false, - #[cfg(not(feature = "stable"))] - test_type: test::TestType::IntegrationTest, }, testfn: make_test_closure(config, testpaths), } @@ -291,7 +284,6 @@ pub fn make_test_closure(config: &Config, testpaths: &TestPaths) -> test::TestFn let config = config.clone(); let testpaths = testpaths.clone(); test::DynTestFn(Box::new(move || { - #[cfg(feature = "stable")] let config = config.clone(); // FIXME: why is this needed? runtest::run(config, &testpaths) })) diff --git a/test-project/Cargo.toml b/test-project/Cargo.toml index cb45865..14be8cb 100644 --- a/test-project/Cargo.toml +++ b/test-project/Cargo.toml @@ -10,4 +10,4 @@ path = ".." features = ["tmp"] [features] -stable = ["compiletest_rs/stable"] +rustc = ["compiletest_rs/rustc"] diff --git a/test-project/tests/tests.rs b/test-project/tests/tests.rs index 193a630..f4f6ab4 100644 --- a/test-project/tests/tests.rs +++ b/test-project/tests/tests.rs @@ -22,8 +22,8 @@ fn compile_test() { run_mode("run-pass", None); run_mode("ui", None); - #[cfg(not(feature = "stable"))] + #[cfg(feature = "rustc")] run_mode("pretty", None); - #[cfg(not(feature = "stable"))] + #[cfg(feature = "rustc")] run_mode("ui", Some("nightly")); } From 61c05bb19a581c11e9a568845f8a741e40396975 Mon Sep 17 00:00:00 2001 From: Philip Munksgaard Date: Wed, 13 Nov 2019 17:17:16 +0100 Subject: [PATCH 2/3] Update README.md to reflect changes to features --- README.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7339e84..6db34fd 100644 --- a/README.md +++ b/README.md @@ -17,12 +17,18 @@ To use `compiletest-rs` in your application, add the following to `Cargo.toml` compiletest_rs = "*" ``` -This will require you to use rust nightly. If you want to use rust stable -set the feature `stable`: +By default, `compiletest-rs` should be able to run on both stable, beta and +nightly channels of rust. We use the [`tester`](tester) fork of Rust's builtin +`test` crate, so that we don't have require nightly. If you are running nightly +and want to use Rust's `test` crate directly, you to have the rustc development +libraries install (which you can get by running `rustup component add rustc-dev +--target nightly`). Once you have the rustc development libraries installed, you +can use the `rustc` feature to make compiletest use them instead of the `tester` +crate. ```toml [dev-dependencies] -compiletest_rs = { version = "*", features = [ "stable" ] } +compiletest_rs = { version = "*", features = [ "rustc" ] } ``` Create a `tests` folder in the root folder of your project. Create a test file @@ -112,3 +118,4 @@ If you are unsure, open a pull request anyway and we would be glad to help! [upstream]: https://github.com/rust-lang/rust/tree/master/src/tools/compiletest [src]: https://github.com/rust-lang/rust/tree/master/src/tools/compiletest/src [tests]: https://rust-lang.github.io/rustc-guide/tests/adding.html#header-commands-configuring-rustc +[tester]: https://crates.io/crates/tester From a8b4c34b253433a747ff7e1a58e728c5b0b95094 Mon Sep 17 00:00:00 2001 From: Philip Munksgaard Date: Thu, 14 Nov 2019 12:04:01 +0100 Subject: [PATCH 3/3] Add `stable` feature to not break existing users It doesn't do anything and should be removed at next major release --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index bf5da92..fe80206 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,3 +37,4 @@ winapi = { version = "0.3", features = ["winerror"] } [features] tmp = ["tempfile"] rustc = [] +stable = [] # Does nothing. Should be removed at next major release