Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -36,5 +36,5 @@ winapi = { version = "0.3", features = ["winerror"] }

[features]
tmp = ["tempfile"]
norustc = []
stable = ["norustc", "tester"]
rustc = []
stable = [] # Does nothing. Should be removed at next major release
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
5 changes: 3 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ 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

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:
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
@@ -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());
}
Expand Down
12 changes: 6 additions & 6 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
12 changes: 2 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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(),
Expand All @@ -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,
}
}

Expand Down Expand Up @@ -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),
}
Expand Down Expand Up @@ -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)
}))
Expand Down
2 changes: 1 addition & 1 deletion test-project/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ path = ".."
features = ["tmp"]

[features]
stable = ["compiletest_rs/stable"]
rustc = ["compiletest_rs/rustc"]
4 changes: 2 additions & 2 deletions test-project/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}