Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use stable libtest #165

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about nightly for the feature name?

- 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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't do version bumps in this commit, I do that separately.

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" ]
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,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%==stable (cargo build) else (cargo build --features=unstable)
- cd test-project && if %CHANNEL%==stable (cargo test) else (cargo test --features=unstable)

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_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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the rename to libtest?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't want it to try and link with the local test crate that is unstable and broken now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But an as import will never change what gets linked. So why not keep 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
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"]
unstable = ["compiletest_rs/unstable"]
2 changes: 1 addition & 1 deletion test-project/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ fn compile_test() {
run_mode("run-pass");
run_mode("ui");

#[cfg(not(feature = "stable"))]
#[cfg(feature = "unstable")]
run_mode("pretty");
}