Skip to content

Commit

Permalink
Use stable libtest
Browse files Browse the repository at this point in the history
  • Loading branch information
gnzlbg committed Mar 20, 2019
1 parent 3e99253 commit 82c259a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 51 deletions.
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ language: rust
matrix:
include:
- rust: nightly
env: FEATURES=""
env: FEATURES="--features unstable"
- rust: beta
env: FEATURES="--features stable"
- rust: stable
env: FEATURES="--features stable"
- rust: nightly
env: FEATURES="--features stable"

script: cd test-project && cargo test $FEATURES

Expand Down
8 changes: 3 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "compiletest_rs"
version = "0.3.20"
version = "0.4.0"
authors = [ "The Rust Project Developers"
, "Thomas Bracht Laumann Jespersen <laumann.thomas@gmail.com>"
, "Manish Goregaokar <manishsmail@gmail.com>"
Expand All @@ -25,8 +25,7 @@ serde = "1.0"
serde_json = "1.0"
serde_derive = "1.0"
rustfix = "0.4.1"
tester = { version = "0.5", optional = true }
libtest = "0.0.1"
libtest = { git = "https://github.com/gnzlbg/libtest", branch = "clippy_ci" }

[target."cfg(unix)".dependencies]
libc = "0.2"
Expand All @@ -37,5 +36,4 @@ winapi = { version = "0.3", features = ["winerror"] }

[features]
tmp = ["tempfile"]
norustc = []
stable = ["norustc", "tester"]
unstable = [ "libtest/unstable" ]
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_UNSTABLE").is_err() {
println!("cargo:rustc-env=TARGET={}", env::var("TARGET").unwrap());
println!("cargo:rustc-env=HOST={}", env::var("HOST").unwrap());
}
Expand Down
29 changes: 15 additions & 14 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ use std::fmt;
use std::fs::{read_dir, remove_file};
use std::str::FromStr;
use std::path::PathBuf;
#[cfg(not(feature = "norustc"))]
#[cfg(feature = "unstable")]
use rustc;

use test::ColorConfig;
use libtest::ColorChoice;
use runtest::dylib_env_var;

#[derive(Clone, Copy, PartialEq, Debug)]
Expand Down Expand Up @@ -210,7 +210,7 @@ pub struct Config {
pub quiet: bool,

/// Whether to use colors in test.
pub color: ColorConfig,
pub color: ColorChoice,

/// where to find the remote test client process, if we're using it
pub remote_test_client: Option<PathBuf>,
Expand Down Expand Up @@ -327,8 +327,15 @@ pub use self::config_tempdir::ConfigWithTemp;

impl Default for Config {
fn default() -> Config {
#[cfg(not(feature = "norustc"))]
let platform = rustc::session::config::host_triple().to_string();
#[cfg(feature = "unstable")]
let (target, host) = {
let platform = rustc::session::config::host_triple().to_string();
(platform.clone(), platform.clone())
};
#[cfg(not(feature = "unstable"))]
let (target, host) = {
(env!("TARGET").to_string(), env!("HOST").to_string())
};

Config {
compile_lib_path: PathBuf::from(""),
Expand All @@ -351,14 +358,8 @@ impl Default for Config {
runtool: None,
host_rustcflags: None,
target_rustcflags: None,
#[cfg(not(feature = "norustc"))]
target: platform.clone(),
#[cfg(feature = "norustc")]
target: env!("TARGET").to_string(),
#[cfg(not(feature = "norustc"))]
host: platform.clone(),
#[cfg(feature = "norustc")]
host: env!("HOST").to_string(),
target,
host,
gdb: None,
gdb_version: None,
gdb_native_rust: false,
Expand All @@ -372,7 +373,7 @@ impl Default for Config {
lldb_python_dir: None,
verbose: false,
quiet: false,
color: ColorConfig::AutoColor,
color: ColorChoice::Auto,
remote_test_client: None,
cc: "cc".to_string(),
cxx: "cxx".to_string(),
Expand Down
50 changes: 23 additions & 27 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@
// except according to those terms.

#![crate_type = "lib"]

#![cfg_attr(not(feature = "norustc"), feature(rustc_private))]
#![cfg_attr(not(feature = "stable"), feature(test))]

#![deny(unused_imports)]
#![cfg_attr(feature = "unstable", feature(rustc_private))]

#[cfg(not(feature = "norustc"))]
#[cfg(feature = "unstable")]
extern crate rustc;

#[cfg(unix)]
extern crate libc;
extern crate libtest as test;
extern crate libtest;

#[cfg(feature = "tmp")] extern crate tempfile;

Expand Down Expand Up @@ -84,7 +81,7 @@ pub fn run_tests(config: &Config) {
// Prevent issue #21352 UAC blocking .exe containing 'patch' etc. on Windows
// If #11207 is resolved (adding manifest to .exe) this becomes unnecessary
env::set_var("__COMPAT_LAYER", "RunAsInvoker");
let res = test::run_tests_console(&opts, tests.into_iter().collect());
let res = libtest::run_tests_console(&opts, tests.into_iter().collect());
match res {
Ok(true) => {}
Ok(false) => panic!("Some tests failed"),
Expand All @@ -94,30 +91,30 @@ pub fn run_tests(config: &Config) {
}
}

pub fn test_opts(config: &Config) -> test::TestOpts {
test::TestOpts {
pub fn test_opts(config: &Config) -> libtest::TestOpts {
libtest::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 },
run_ignored: if config.run_ignored { libtest::RunIgnored::Yes } else { libtest::RunIgnored::No },
format: if config.quiet { libtest::OutputFormat::Terse } else { libtest::OutputFormat::Pretty },
logfile: config.logfile.clone(),
run_tests: true,
bench_benchmarks: true,
nocapture: match env::var("RUST_TEST_NOCAPTURE") {
Ok(val) => &val != "0",
Err(_) => false
},
color: test::AutoColor,
color: libtest::ColorChoice::Auto,
test_threads: None,
skip: vec![],
list: false,
options: test::Options::new(),
options: libtest::Options::new(),
}
}

pub fn make_tests(config: &Config) -> Vec<test::TestDescAndFn> {
pub fn make_tests(config: &Config) -> Vec<libtest::TestDescAndFn> {
debug!("making tests from {:?}",
config.src_base.display());
let mut tests = Vec::new();
Expand All @@ -134,7 +131,7 @@ fn collect_tests_from_dir(config: &Config,
base: &Path,
dir: &Path,
relative_dir_path: &Path,
tests: &mut Vec<test::TestDescAndFn>)
tests: &mut Vec<libtest::TestDescAndFn>)
-> io::Result<()> {
// Ignore directories that contain a file
// `compiletest-ignore-dir`.
Expand Down Expand Up @@ -224,23 +221,23 @@ pub fn is_test(file_name: &OsString) -> bool {
!invalid_prefixes.iter().any(|p| file_name.starts_with(p))
}

pub fn make_test(config: &Config, testpaths: &TestPaths) -> test::TestDescAndFn {
pub fn make_test(config: &Config, testpaths: &TestPaths) -> libtest::TestDescAndFn {
let early_props = EarlyProps::from_file(config, &testpaths.file);

// The `should-fail` annotation doesn't apply to pretty tests,
// since we run the pretty printer across all tests by default.
// If desired, we could add a `should-fail-pretty` annotation.
let should_panic = match config.mode {
Pretty => test::ShouldPanic::No,
Pretty => libtest::ShouldPanic::No,
_ => if early_props.should_fail {
test::ShouldPanic::Yes
libtest::ShouldPanic::Yes
} else {
test::ShouldPanic::No
libtest::ShouldPanic::No
}
};

test::TestDescAndFn {
desc: test::TestDesc {
libtest::TestDescAndFn {
desc: libtest::TestDesc {
name: make_test_name(config, testpaths),
ignore: early_props.ignore,
should_panic: should_panic,
Expand All @@ -260,23 +257,22 @@ fn stamp(config: &Config, testpaths: &TestPaths) -> PathBuf {
.join(stamp_name)
}

pub fn make_test_name(config: &Config, testpaths: &TestPaths) -> test::TestName {
pub fn make_test_name(config: &Config, testpaths: &TestPaths) -> libtest::TestName {
// Convert a complete path to something like
//
// run-pass/foo/bar/baz.rs
let path =
PathBuf::from(config.src_base.file_name().unwrap())
.join(&testpaths.relative_dir)
.join(&testpaths.file.file_name().unwrap());
test::DynTestName(format!("[{}] {}", config.mode, path.display()))
libtest::TestName::DynTestName(format!("[{}] {}", config.mode, path.display()))
}

pub fn make_test_closure(config: &Config, testpaths: &TestPaths) -> test::TestFn {
pub fn make_test_closure(config: &Config, testpaths: &TestPaths) -> libtest::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?
libtest::TestFn::DynTestFn(Box::new(move || {
let config = config.clone();
runtest::run(config, &testpaths)
}))
}
Expand Down

0 comments on commit 82c259a

Please sign in to comment.