From 40baa36b42939ecfdb0023c850c550431959b9b9 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Tue, 19 Mar 2019 23:31:12 +0100 Subject: [PATCH 01/18] Add integration test: compiletest-rs --- .travis.yml | 3 +++ ci/integration.sh | 11 +++++++++++ 2 files changed, 14 insertions(+) create mode 100644 ci/integration.sh diff --git a/.travis.yml b/.travis.yml index 88542af..160fda8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,9 @@ matrix: - name: "Tools" install: true script: sh ci/tools.sh + - name: "Integration" + install: true + script: sh ci/integration.sh # cross targets: - name: "aarch64-linux-android" diff --git a/ci/integration.sh b/ci/integration.sh new file mode 100644 index 0000000..b629b49 --- /dev/null +++ b/ci/integration.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env sh + +set -ex + +# compile-test +git clone git@github.com:laumann/compiletest-rs.git +( + cd compiletest-rs + sed -i '' 's@libtest = "0.0.1"@libtest = { path = ".." }@g' Cargo.toml + cargo build +) From 46991d7ff03401ef19e6fbd8938913226b8a5d33 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Wed, 20 Mar 2019 00:46:44 +0100 Subject: [PATCH 02/18] Use termcolor --- ci/integration.sh | 7 +++++-- libtest/Cargo.toml | 6 +++++- libtest/formatters/pretty.rs | 22 +++++++++++--------- libtest/formatters/terse.rs | 22 +++++++++++--------- libtest/lib.rs | 39 +++++++++++++----------------------- 5 files changed, 48 insertions(+), 48 deletions(-) diff --git a/ci/integration.sh b/ci/integration.sh index b629b49..8b5b479 100644 --- a/ci/integration.sh +++ b/ci/integration.sh @@ -3,9 +3,12 @@ set -ex # compile-test -git clone git@github.com:laumann/compiletest-rs.git +rm -r compiletest-rs || true +git clone git@github.com:gnzlbg/compiletest-rs.git ( cd compiletest-rs - sed -i '' 's@libtest = "0.0.1"@libtest = { path = ".." }@g' Cargo.toml + git checkout libtest + sed -i '' 's@libtest = { git = "https://github.com/gnzlbg/libtest", branch = "clippy_ci" }@libtest = { path = "../libtest" }@g' Cargo.toml + echo "[workspace]" >> Cargo.toml cargo build ) diff --git a/libtest/Cargo.toml b/libtest/Cargo.toml index c1ce6b4..5a57b4f 100644 --- a/libtest/Cargo.toml +++ b/libtest/Cargo.toml @@ -17,4 +17,8 @@ crate-type = ["dylib", "rlib"] [dependencies] getopts = "0.2" -term = "0.5" \ No newline at end of file +termcolor = "1.0" + +[features] +default = [] +unstable = [] \ No newline at end of file diff --git a/libtest/formatters/pretty.rs b/libtest/formatters/pretty.rs index 8552dfe..395a076 100644 --- a/libtest/formatters/pretty.rs +++ b/libtest/formatters/pretty.rs @@ -1,4 +1,5 @@ use super::*; +use termcolor::Color; pub(crate) struct PrettyFormatter { out: OutputLocation, @@ -31,29 +32,29 @@ impl PrettyFormatter { } pub fn write_ok(&mut self) -> io::Result<()> { - self.write_short_result("ok", term::color::GREEN) + self.write_short_result("ok", Color::Green) } pub fn write_failed(&mut self) -> io::Result<()> { - self.write_short_result("FAILED", term::color::RED) + self.write_short_result("FAILED", Color::Red) } pub fn write_ignored(&mut self) -> io::Result<()> { - self.write_short_result("ignored", term::color::YELLOW) + self.write_short_result("ignored", Color::Yellow) } pub fn write_allowed_fail(&mut self) -> io::Result<()> { - self.write_short_result("FAILED (allowed)", term::color::YELLOW) + self.write_short_result("FAILED (allowed)", Color::Yellow) } pub fn write_bench(&mut self) -> io::Result<()> { - self.write_pretty("bench", term::color::CYAN) + self.write_pretty("bench", Color::Cyan) } pub fn write_short_result( &mut self, result: &str, - color: term::color::Color, + color: Color, ) -> io::Result<()> { self.write_pretty(result, color)?; self.write_plain("\n") @@ -62,12 +63,13 @@ impl PrettyFormatter { pub fn write_pretty( &mut self, word: &str, - color: term::color::Color, + color: Color, ) -> io::Result<()> { + use termcolor::WriteColor; match self.out { OutputLocation::Pretty(ref mut term) => { if self.use_color { - term.fg(color)?; + term.set_color(termcolor::ColorSpec::new().set_fg(Some(color)))?; } term.write_all(word.as_bytes())?; if self.use_color { @@ -223,9 +225,9 @@ impl OutputFormatter for PrettyFormatter { if success { // There's no parallelism at this point so it's safe to use color - self.write_pretty("ok", term::color::GREEN)?; + self.write_pretty("ok", Color::Green)?; } else { - self.write_pretty("FAILED", term::color::RED)?; + self.write_pretty("FAILED", Color::Red)?; } let s = if state.allowed_fail > 0 { diff --git a/libtest/formatters/terse.rs b/libtest/formatters/terse.rs index a7b25be..4dccbd2 100644 --- a/libtest/formatters/terse.rs +++ b/libtest/formatters/terse.rs @@ -1,4 +1,5 @@ use super::*; +use termcolor::Color; pub(crate) struct TerseFormatter { out: OutputLocation, @@ -29,29 +30,29 @@ impl TerseFormatter { } pub fn write_ok(&mut self) -> io::Result<()> { - self.write_short_result(".", term::color::GREEN) + self.write_short_result(".", Color::Green) } pub fn write_failed(&mut self) -> io::Result<()> { - self.write_short_result("F", term::color::RED) + self.write_short_result("F", Color::Red) } pub fn write_ignored(&mut self) -> io::Result<()> { - self.write_short_result("i", term::color::YELLOW) + self.write_short_result("i", Color::Yellow) } pub fn write_allowed_fail(&mut self) -> io::Result<()> { - self.write_short_result("a", term::color::YELLOW) + self.write_short_result("a", Color::Yellow) } pub fn write_bench(&mut self) -> io::Result<()> { - self.write_pretty("bench", term::color::CYAN) + self.write_pretty("bench", Color::Cyan) } pub fn write_short_result( &mut self, result: &str, - color: term::color::Color, + color: Color, ) -> io::Result<()> { self.write_pretty(result, color)?; if self.test_count % QUIET_MODE_MAX_COLUMN == QUIET_MODE_MAX_COLUMN - 1 @@ -74,12 +75,13 @@ impl TerseFormatter { pub fn write_pretty( &mut self, word: &str, - color: term::color::Color, + color: Color, ) -> io::Result<()> { + use termcolor::WriteColor; match self.out { OutputLocation::Pretty(ref mut term) => { if self.use_color { - term.fg(color)?; + term.set_color(termcolor::ColorSpec::new().set_fg(Some(color)))?; } term.write_all(word.as_bytes())?; if self.use_color { @@ -233,9 +235,9 @@ impl OutputFormatter for TerseFormatter { if success { // There's no parallelism at this point so it's safe to use color - self.write_pretty("ok", term::color::GREEN)?; + self.write_pretty("ok", Color::Green)?; } else { - self.write_pretty("FAILED", term::color::RED)?; + self.write_pretty("FAILED", Color::Red)?; } let s = if state.allowed_fail > 0 { diff --git a/libtest/lib.rs b/libtest/lib.rs index f8f5284..ccd6f47 100644 --- a/libtest/lib.rs +++ b/libtest/lib.rs @@ -48,6 +48,7 @@ use std::{ thread, time::{Duration, Instant}, }; +use termcolor::ColorChoice; const TEST_WARN_TIMEOUT_S: u64 = 60; const QUIET_MODE_MAX_COLUMN: usize = 100; // insert a '\n' after 100 tests in quiet mode @@ -315,13 +316,6 @@ pub fn assert_test_result(result: T) { } } -#[derive(Copy, Clone, Debug)] -pub enum ColorConfig { - AutoColor, - AlwaysColor, - NeverColor, -} - #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub enum OutputFormat { Pretty, @@ -347,7 +341,7 @@ pub struct TestOpts { pub bench_benchmarks: bool, pub logfile: Option, pub nocapture: bool, - pub color: ColorConfig, + pub color: ColorChoice, pub format: OutputFormat, pub test_threads: Option, pub skip: Vec, @@ -367,7 +361,7 @@ impl TestOpts { bench_benchmarks: false, logfile: None, nocapture: false, - color: ColorConfig::AutoColor, + color: ColorChoice::Auto, format: OutputFormat::Pretty, test_threads: None, skip: vec![], @@ -597,9 +591,9 @@ pub fn parse_opts(args: &[String]) -> Option { }; let color = match matches.opt_str("color").as_ref().map(|s| &**s) { - Some("auto") | None => ColorConfig::AutoColor, - Some("always") => ColorConfig::AlwaysColor, - Some("never") => ColorConfig::NeverColor, + Some("auto") | None => ColorChoice::Auto, + Some("always") => ColorChoice::Always, + Some("never") => ColorChoice::Never, Some(v) => { return Some(Err(format!( @@ -671,7 +665,7 @@ pub enum TestResult { unsafe impl Send for TestResult {} enum OutputLocation { - Pretty(Box), + Pretty(termcolor::StandardStream), Raw(T), } @@ -823,10 +817,8 @@ pub fn list_tests_console( } } - let mut output = match term::stdout() { - None => OutputLocation::Raw(io::stdout()), - Some(t) => OutputLocation::Pretty(t), - }; + let mut output: OutputLocation> + = OutputLocation::Pretty(termcolor::StandardStream::stdout(opts.color)); let quiet = opts.format == OutputFormat::Terse; let mut st = ConsoleTestState::new(opts)?; @@ -935,11 +927,8 @@ pub fn run_tests_console( } } - let output = match term::stdout() { - None => OutputLocation::Raw(io::stdout()), - Some(t) => OutputLocation::Pretty(t), - }; - + let output: OutputLocation> + = OutputLocation::Pretty(termcolor::StandardStream::stdout(opts.color)); let max_name_len = tests .iter() .max_by_key(|t| len_if_padded(*t)) @@ -1023,9 +1012,9 @@ fn should_sort_failures_before_printing_them() { fn use_color(opts: &TestOpts) -> bool { match opts.color { - ColorConfig::AutoColor => !opts.nocapture && stdout_isatty(), - ColorConfig::AlwaysColor => true, - ColorConfig::NeverColor => false, + ColorChoice::Auto => !opts.nocapture && stdout_isatty(), + ColorChoice::Always | ColorChoice::AlwaysAnsi => true, + ColorChoice::Never => false, } } From 425cb603d5a6f513f33a3ecd527ddb54ad6715e6 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Wed, 20 Mar 2019 02:26:48 +0100 Subject: [PATCH 03/18] Add unstable cargo feature enabled by default --- Cargo.toml | 27 ++++- ci/run.sh | 3 + libtest/Cargo.toml | 24 ----- libtest/README.md | 1 - {libtest => src}/formatters/json.rs | 0 {libtest => src}/formatters/mod.rs | 0 {libtest => src}/formatters/pretty.rs | 0 {libtest => src}/formatters/terse.rs | 0 {libtest => src}/lib.rs | 145 +++++++++++++++++++------- {libtest => src}/stats.rs | 22 ++-- 10 files changed, 144 insertions(+), 78 deletions(-) delete mode 100644 libtest/Cargo.toml delete mode 120000 libtest/README.md rename {libtest => src}/formatters/json.rs (100%) rename {libtest => src}/formatters/mod.rs (100%) rename {libtest => src}/formatters/pretty.rs (100%) rename {libtest => src}/formatters/terse.rs (100%) rename {libtest => src}/lib.rs (95%) rename {libtest => src}/stats.rs (99%) diff --git a/Cargo.toml b/Cargo.toml index 811738f..1317cf9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,25 @@ -[workspace] -members = [ "libtest" ] \ No newline at end of file +[package] +authors = ["The Rust Project Developers"] +name = "libtest" +version = "0.0.1" +edition = "2018" +description = "Rust's built in unit-test and micro-benchmarking framework" +license = "MIT/Apache-2.0" +documentation = "https://docs.rs/libterm" +homepage = "https://github.com/rust-lang/libtest" +repository = "https://github.com/rust-lang/libtest" +readme = "README.md" + +[lib] +name = "libtest" +path = "src/lib.rs" +crate-type = ["dylib", "rlib"] + +[dependencies] +getopts = "0.2" +termcolor = "1.0" +libc = "0.2" + +[features] +default = [ "unstable" ] +unstable = [] \ No newline at end of file diff --git a/ci/run.sh b/ci/run.sh index d6120da..eaaa6e6 100644 --- a/ci/run.sh +++ b/ci/run.sh @@ -16,3 +16,6 @@ fi "${CARGO}" "${CMD}" -vv --all --target="${TARGET}" "${CARGO}" "${CMD}" -vv --all --target="${TARGET}" --release + +"${CARGO}" "${CMD}" -vv --all --target="${TARGET}" --features=unstable +"${CARGO}" "${CMD}" -vv --all --target="${TARGET}" --features=unstable --release diff --git a/libtest/Cargo.toml b/libtest/Cargo.toml deleted file mode 100644 index 5a57b4f..0000000 --- a/libtest/Cargo.toml +++ /dev/null @@ -1,24 +0,0 @@ -[package] -authors = ["The Rust Project Developers"] -name = "libtest" -version = "0.0.1" -edition = "2018" -description = "Rust's built in unit-test and micro-benchmarking framework" -license = "MIT/Apache-2.0" -documentation = "https://docs.rs/libterm" -homepage = "https://github.com/rust-lang/libtest" -repository = "https://github.com/rust-lang/libtest" -readme = "README.md" - -[lib] -name = "libtest" -path = "lib.rs" -crate-type = ["dylib", "rlib"] - -[dependencies] -getopts = "0.2" -termcolor = "1.0" - -[features] -default = [] -unstable = [] \ No newline at end of file diff --git a/libtest/README.md b/libtest/README.md deleted file mode 120000 index 32d46ee..0000000 --- a/libtest/README.md +++ /dev/null @@ -1 +0,0 @@ -../README.md \ No newline at end of file diff --git a/libtest/formatters/json.rs b/src/formatters/json.rs similarity index 100% rename from libtest/formatters/json.rs rename to src/formatters/json.rs diff --git a/libtest/formatters/mod.rs b/src/formatters/mod.rs similarity index 100% rename from libtest/formatters/mod.rs rename to src/formatters/mod.rs diff --git a/libtest/formatters/pretty.rs b/src/formatters/pretty.rs similarity index 100% rename from libtest/formatters/pretty.rs rename to src/formatters/pretty.rs diff --git a/libtest/formatters/terse.rs b/src/formatters/terse.rs similarity index 100% rename from libtest/formatters/terse.rs rename to src/formatters/terse.rs diff --git a/libtest/lib.rs b/src/lib.rs similarity index 95% rename from libtest/lib.rs rename to src/lib.rs index ccd6f47..2c3f199 100644 --- a/libtest/lib.rs +++ b/src/lib.rs @@ -1,10 +1,23 @@ //! Rust's built-in unit-test and micro-benchmarking framework. -#![cfg_attr(any(unix, target_os = "cloudabi"), feature(libc, rustc_private))] -#![feature(fnbox)] -#![feature(set_stdio)] -#![feature(panic_unwind)] -#![feature(termination_trait_lib)] -#![feature(test)] +#![cfg_attr( + all( + feature = "unstable", + any(unix, target_os = "cloudabi") + ), + feature( + rustc_private + ) +)] +#![cfg_attr( + feature = "unstable", + feature( + fnbox, + set_stdio, + panic_unwind, + termination_trait_lib, + test, + ) +)] #![deny(rust_2018_idioms)] #![allow( clippy::pub_enum_variant_names, @@ -15,6 +28,7 @@ use getopts; +#[cfg(feature = "unstable")] extern crate test; #[cfg(any(unix, target_os = "cloudabi"))] @@ -26,13 +40,12 @@ extern crate libc; // libtest won't be fully functional on this platform. // // See also: https://github.com/rust-lang/rust/issues/54190#issuecomment-422904437 -#[cfg(not(all(windows, target_arch = "aarch64")))] +#[cfg(all(features = "unstable", not(all(windows, target_arch = "aarch64"))))] extern crate panic_unwind; use std::{ any::Any, borrow::Cow, - boxed::FnBox, cmp, collections::BTreeMap, env, fmt, @@ -40,7 +53,7 @@ use std::{ io::{self, prelude::*}, panic::{catch_unwind, AssertUnwindSafe}, path::PathBuf, - process::{self, Termination}, + process::{self}, sync::{ mpsc::{channel, Sender}, Arc, Mutex, @@ -48,14 +61,44 @@ use std::{ thread, time::{Duration, Instant}, }; + +#[cfg(feature = "unstable")] +use std::{ + process::Termination, + boxed::FnBox, +}; use termcolor::ColorChoice; +#[cfg(feature = "unstable")] +type FnOnceBoxed = Box; + +#[cfg(not(feature = "unstable"))] +type FnOnceBoxed = Box; + const TEST_WARN_TIMEOUT_S: u64 = 60; const QUIET_MODE_MAX_COLUMN: usize = 100; // insert a '\n' after 100 tests in quiet mode mod formatters; pub mod stats; +fn set_print(sink: Option>) -> Option> { + #[cfg(feature = "unstable")] { + io::set_print(sink) + } + #[cfg(not(feature = "unstable"))] { + sink + } +} + +fn set_panic(sink: Option>) -> Option> { + #[cfg(feature = "unstable")] { + io::set_panic(sink) + } + #[cfg(not(feature = "unstable"))] { + sink + } +} + use crate::formatters::{ JsonFormatter, OutputFormatter, PrettyFormatter, TerseFormatter, }; @@ -143,10 +186,11 @@ pub trait TDynBenchFn: Send { pub enum TestFn { StaticTestFn(fn()), StaticBenchFn(fn(&mut Bencher)), - DynTestFn(Box), + DynTestFn(FnOnceBoxed), DynBenchFn(Box), } + impl TestFn { fn padding(&self) -> NamePadding { match *self { @@ -304,6 +348,7 @@ pub fn test_main_static(tests: &[&TestDescAndFn]) { /// Invoked when unit tests terminate. Should panic if the unit /// Tests is considered a failure. By default, invokes `report()` /// and checks for a `0` result. +#[cfg(feature = "unstable")] pub fn assert_test_result(result: T) { let code = result.report(); if code != 0 { @@ -1460,7 +1505,7 @@ pub fn run_test( desc: TestDesc, monitor_ch: Sender, nocapture: bool, - testfn: Box, + testfn: FnOnceBoxed, concurrency: Concurrent, ) { // Buffer for capturing standard I/O @@ -1473,16 +1518,23 @@ pub fn run_test( None } else { Some(( - io::set_print(Some(Box::new(Sink(data2.clone())))), - io::set_panic(Some(Box::new(Sink(data2)))), + crate::set_print(Some(Box::new(Sink(data2.clone())))), + crate::set_panic(Some(Box::new(Sink(data2)))), )) }; - let result = catch_unwind(AssertUnwindSafe(testfn)); + let result = { + #[cfg(feature = "unstable")] { + catch_unwind(AssertUnwindSafe(move || testfn())) + } + #[cfg(not(feature = "unstable"))] { + catch_unwind(|| testfn()) + } + }; if let Some((printio, panicio)) = oldio { - io::set_print(printio); - io::set_panic(panicio); + crate::set_print(printio); + crate::set_panic(panicio); }; let test_result = calc_result(&desc, result); @@ -1536,20 +1588,32 @@ pub fn run_test( ); } TestFn::DynTestFn(f) => { - let cb = move || __rust_begin_short_backtrace(f); - run_test_inner( - desc, - monitor_ch, - opts.nocapture, - Box::new(cb), - concurrency, - ) + #[cfg(feature = "unstable")] { + let cb = move || __rust_begin_short_backtrace(move || f()); + + run_test_inner( + desc, + monitor_ch, + opts.nocapture, + Box::new(cb), + concurrency, + ) + } + #[cfg(not(feature = "unstable"))] { + run_test_inner( + desc, + monitor_ch, + opts.nocapture, + f, + concurrency, + ) + } } TestFn::StaticTestFn(f) => run_test_inner( desc, monitor_ch, opts.nocapture, - Box::new(move || __rust_begin_short_backtrace(f)), + Box::new(move || __rust_begin_short_backtrace(move || f())), concurrency, ), } @@ -1656,13 +1720,22 @@ fn ns_from_dur(dur: Duration) -> u64 { dur.as_secs() * 1_000_000_000 + u64::from(dur.subsec_nanos()) } +fn black_box(x: T) -> T { + #[cfg(feature = "unstable")] { + test::black_box(x) + } + #[cfg(not(feature = "unstable"))] { + unsafe { std::ptr::read_volatile(&x as *const T) } + } +} + fn ns_iter_inner(inner: &mut F, k: u64) -> u64 where F: FnMut() -> T, { let start = Instant::now(); for _ in 0..k { - test::black_box(inner()); + black_box(inner()); } ns_from_dur(start.elapsed()) } @@ -1738,13 +1811,13 @@ where pub mod bench { use super::{ BenchMode, BenchSamples, Bencher, MonitorMsg, Sender, Sink, TestDesc, - TestResult, + TestResult, stats, + }; + use std::{ + cmp, + panic::{catch_unwind, AssertUnwindSafe}, + sync::{Arc, Mutex} }; - use crate::stats; - use std::cmp; - use std::io; - use std::panic::{catch_unwind, AssertUnwindSafe}; - use std::sync::{Arc, Mutex}; pub fn benchmark( desc: TestDesc, @@ -1767,16 +1840,16 @@ pub mod bench { None } else { Some(( - io::set_print(Some(Box::new(Sink(data2.clone())))), - io::set_panic(Some(Box::new(Sink(data2)))), + crate::set_print(Some(Box::new(Sink(data2.clone())))), + crate::set_panic(Some(Box::new(Sink(data2)))), )) }; let result = catch_unwind(AssertUnwindSafe(|| bs.bench(f))); if let Some((printio, panicio)) = oldio { - io::set_print(printio); - io::set_panic(panicio); + crate::set_print(printio); + crate::set_panic(panicio); }; let test_result = match result { diff --git a/libtest/stats.rs b/src/stats.rs similarity index 99% rename from libtest/stats.rs rename to src/stats.rs index 45e0938..329b7e2 100644 --- a/libtest/stats.rs +++ b/src/stats.rs @@ -895,30 +895,22 @@ mod tests { fn test_sum_f64_between_ints_that_sum_to_0() { assert_eq!([1e30f64, 1.2f64, -1e30f64].sum(), 1.2); } -} -#[cfg(test)] -mod bench { - extern crate test; - use self::test::Bencher; - use crate::stats::Stats; - - #[bench] - pub fn sum_three_items(b: &mut Bencher) { + #[test] + pub fn sum_three_items() { + let mut b = crate::Bencher { mode: crate::BenchMode::Auto, summary: None, bytes: 1 }; b.iter(|| { [1e20f64, 1.5f64, -1e20f64].sum(); }) } - #[bench] - pub fn sum_many_f64(b: &mut Bencher) { + + #[test] + pub fn sum_many_f64() { + let mut b = crate::Bencher { mode: crate::BenchMode::Auto, summary: None, bytes: 1 }; let nums = [-1e30f64, 1e60, 1e30, 1.0, -1e60]; let v = (0..500).map(|i| nums[i % 5]).collect::>(); - b.iter(|| { v.sum(); }) } - - #[bench] - pub fn no_iter(_: &mut Bencher) {} } From ac69870594c1b9219964c88f1e1890f24ce3f9dd Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Wed, 20 Mar 2019 10:21:18 +0100 Subject: [PATCH 04/18] Remove dependency on FnBox; Bump version --- Cargo.toml | 4 +- src/formatters/pretty.rs | 4 +- src/formatters/terse.rs | 4 +- src/lib.rs | 124 +++++++++++++++------------------------ src/stats.rs | 12 +++- 5 files changed, 65 insertions(+), 83 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1317cf9..0c1a55a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["The Rust Project Developers"] name = "libtest" -version = "0.0.1" +version = "0.0.2" edition = "2018" description = "Rust's built in unit-test and micro-benchmarking framework" license = "MIT/Apache-2.0" @@ -21,5 +21,5 @@ termcolor = "1.0" libc = "0.2" [features] -default = [ "unstable" ] +default = [] unstable = [] \ No newline at end of file diff --git a/src/formatters/pretty.rs b/src/formatters/pretty.rs index 395a076..f31716c 100644 --- a/src/formatters/pretty.rs +++ b/src/formatters/pretty.rs @@ -69,7 +69,9 @@ impl PrettyFormatter { match self.out { OutputLocation::Pretty(ref mut term) => { if self.use_color { - term.set_color(termcolor::ColorSpec::new().set_fg(Some(color)))?; + term.set_color( + termcolor::ColorSpec::new().set_fg(Some(color)), + )?; } term.write_all(word.as_bytes())?; if self.use_color { diff --git a/src/formatters/terse.rs b/src/formatters/terse.rs index 4dccbd2..f57a71f 100644 --- a/src/formatters/terse.rs +++ b/src/formatters/terse.rs @@ -81,7 +81,9 @@ impl TerseFormatter { match self.out { OutputLocation::Pretty(ref mut term) => { if self.use_color { - term.set_color(termcolor::ColorSpec::new().set_fg(Some(color)))?; + term.set_color( + termcolor::ColorSpec::new().set_fg(Some(color)), + )?; } term.write_all(word.as_bytes())?; if self.use_color { diff --git a/src/lib.rs b/src/lib.rs index 2c3f199..48a89a7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,22 +1,7 @@ //! Rust's built-in unit-test and micro-benchmarking framework. -#![cfg_attr( - all( - feature = "unstable", - any(unix, target_os = "cloudabi") - ), - feature( - rustc_private - ) -)] #![cfg_attr( feature = "unstable", - feature( - fnbox, - set_stdio, - panic_unwind, - termination_trait_lib, - test, - ) + feature(set_stdio, panic_unwind, termination_trait_lib, test,) )] #![deny(rust_2018_idioms)] #![allow( @@ -53,7 +38,7 @@ use std::{ io::{self, prelude::*}, panic::{catch_unwind, AssertUnwindSafe}, path::PathBuf, - process::{self}, + process, sync::{ mpsc::{channel, Sender}, Arc, Mutex, @@ -63,38 +48,37 @@ use std::{ }; #[cfg(feature = "unstable")] -use std::{ - process::Termination, - boxed::FnBox, -}; +use std::process::Termination; use termcolor::ColorChoice; -#[cfg(feature = "unstable")] -type FnOnceBoxed = Box; - -#[cfg(not(feature = "unstable"))] -type FnOnceBoxed = Box; - const TEST_WARN_TIMEOUT_S: u64 = 60; const QUIET_MODE_MAX_COLUMN: usize = 100; // insert a '\n' after 100 tests in quiet mode mod formatters; pub mod stats; -fn set_print(sink: Option>) -> Option> { - #[cfg(feature = "unstable")] { +fn set_print( + sink: Option>, +) -> Option> { + #[cfg(feature = "unstable")] + { io::set_print(sink) } - #[cfg(not(feature = "unstable"))] { + #[cfg(not(feature = "unstable"))] + { sink } } -fn set_panic(sink: Option>) -> Option> { - #[cfg(feature = "unstable")] { +fn set_panic( + sink: Option>, +) -> Option> { + #[cfg(feature = "unstable")] + { io::set_panic(sink) } - #[cfg(not(feature = "unstable"))] { + #[cfg(not(feature = "unstable"))] + { sink } } @@ -186,11 +170,10 @@ pub trait TDynBenchFn: Send { pub enum TestFn { StaticTestFn(fn()), StaticBenchFn(fn(&mut Bencher)), - DynTestFn(FnOnceBoxed), + DynTestFn(Box), DynBenchFn(Box), } - impl TestFn { fn padding(&self) -> NamePadding { match *self { @@ -711,7 +694,8 @@ unsafe impl Send for TestResult {} enum OutputLocation { Pretty(termcolor::StandardStream), - Raw(T), + #[allow(dead_code)] + Raw(T), // used in tests } impl Write for OutputLocation { @@ -862,8 +846,8 @@ pub fn list_tests_console( } } - let mut output: OutputLocation> - = OutputLocation::Pretty(termcolor::StandardStream::stdout(opts.color)); + let mut output: OutputLocation> = + OutputLocation::Pretty(termcolor::StandardStream::stdout(opts.color)); let quiet = opts.format == OutputFormat::Terse; let mut st = ConsoleTestState::new(opts)?; @@ -972,8 +956,8 @@ pub fn run_tests_console( } } - let output: OutputLocation> - = OutputLocation::Pretty(termcolor::StandardStream::stdout(opts.color)); + let output: OutputLocation> = + OutputLocation::Pretty(termcolor::StandardStream::stdout(opts.color)); let max_name_len = tests .iter() .max_by_key(|t| len_if_padded(*t)) @@ -1494,6 +1478,7 @@ pub fn convert_benchmarks_to_tests( .collect() } +#[allow(clippy::redundant_closure)] pub fn run_test( opts: &TestOpts, force_ignore: bool, @@ -1505,7 +1490,7 @@ pub fn run_test( desc: TestDesc, monitor_ch: Sender, nocapture: bool, - testfn: FnOnceBoxed, + mut testfn: Box, concurrency: Concurrent, ) { // Buffer for capturing standard I/O @@ -1523,14 +1508,7 @@ pub fn run_test( )) }; - let result = { - #[cfg(feature = "unstable")] { - catch_unwind(AssertUnwindSafe(move || testfn())) - } - #[cfg(not(feature = "unstable"))] { - catch_unwind(|| testfn()) - } - }; + let result = catch_unwind(AssertUnwindSafe(move || testfn())); if let Some((printio, panicio)) = oldio { crate::set_print(printio); @@ -1587,33 +1565,21 @@ pub fn run_test( |harness| (benchfn)(harness), ); } - TestFn::DynTestFn(f) => { - #[cfg(feature = "unstable")] { - let cb = move || __rust_begin_short_backtrace(move || f()); - - run_test_inner( - desc, - monitor_ch, - opts.nocapture, - Box::new(cb), - concurrency, - ) - } - #[cfg(not(feature = "unstable"))] { - run_test_inner( - desc, - monitor_ch, - opts.nocapture, - f, - concurrency, - ) - } + TestFn::DynTestFn(mut f) => { + let cb = move || __rust_begin_short_backtrace(|| f()); + run_test_inner( + desc, + monitor_ch, + opts.nocapture, + Box::new(cb), + concurrency, + ) } TestFn::StaticTestFn(f) => run_test_inner( desc, monitor_ch, opts.nocapture, - Box::new(move || __rust_begin_short_backtrace(move || f())), + Box::new(move || __rust_begin_short_backtrace(f)), concurrency, ), } @@ -1621,7 +1587,7 @@ pub fn run_test( /// Fixed frame used to clean the backtrace with `RUST_BACKTRACE=1`. #[inline(never)] -fn __rust_begin_short_backtrace(f: F) { +fn __rust_begin_short_backtrace(mut f: F) { f() } @@ -1720,11 +1686,15 @@ fn ns_from_dur(dur: Duration) -> u64 { dur.as_secs() * 1_000_000_000 + u64::from(dur.subsec_nanos()) } +#[inline(never)] +#[allow(clippy::needless_pass_by_value)] fn black_box(x: T) -> T { - #[cfg(feature = "unstable")] { + #[cfg(feature = "unstable")] + { test::black_box(x) } - #[cfg(not(feature = "unstable"))] { + #[cfg(not(feature = "unstable"))] + { unsafe { std::ptr::read_volatile(&x as *const T) } } } @@ -1810,13 +1780,13 @@ where pub mod bench { use super::{ - BenchMode, BenchSamples, Bencher, MonitorMsg, Sender, Sink, TestDesc, - TestResult, stats, + stats, BenchMode, BenchSamples, Bencher, MonitorMsg, Sender, Sink, + TestDesc, TestResult, }; use std::{ cmp, panic::{catch_unwind, AssertUnwindSafe}, - sync::{Arc, Mutex} + sync::{Arc, Mutex}, }; pub fn benchmark( diff --git a/src/stats.rs b/src/stats.rs index 329b7e2..9b912e7 100644 --- a/src/stats.rs +++ b/src/stats.rs @@ -898,7 +898,11 @@ mod tests { #[test] pub fn sum_three_items() { - let mut b = crate::Bencher { mode: crate::BenchMode::Auto, summary: None, bytes: 1 }; + let mut b = crate::Bencher { + mode: crate::BenchMode::Auto, + summary: None, + bytes: 1, + }; b.iter(|| { [1e20f64, 1.5f64, -1e20f64].sum(); }) @@ -906,7 +910,11 @@ mod tests { #[test] pub fn sum_many_f64() { - let mut b = crate::Bencher { mode: crate::BenchMode::Auto, summary: None, bytes: 1 }; + let mut b = crate::Bencher { + mode: crate::BenchMode::Auto, + summary: None, + bytes: 1, + }; let nums = [-1e30f64, 1e60, 1e30, 1.0, -1e60]; let v = (0..500).map(|i| nums[i % 5]).collect::>(); b.iter(|| { From 88b03289baef9986f8a272346d77700f61436dcc Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Wed, 20 Mar 2019 10:27:00 +0100 Subject: [PATCH 05/18] Update integration tests --- ci/integration.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ci/integration.sh b/ci/integration.sh index 8b5b479..e5dd28a 100644 --- a/ci/integration.sh +++ b/ci/integration.sh @@ -4,11 +4,10 @@ set -ex # compile-test rm -r compiletest-rs || true -git clone git@github.com:gnzlbg/compiletest-rs.git +git clone git@github.com:laumann/compiletest-rs.git ( cd compiletest-rs - git checkout libtest - sed -i '' 's@libtest = { git = "https://github.com/gnzlbg/libtest", branch = "clippy_ci" }@libtest = { path = "../libtest" }@g' Cargo.toml + sed -i '' 's@libtest = "0.0.1"@libtest = { path = "..", features = [ "unstable" ] }@g' Cargo.toml echo "[workspace]" >> Cargo.toml cargo build ) From e2d9b8d4b8e1073c62e483c104b8aad0258a54c4 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Wed, 20 Mar 2019 10:34:28 +0100 Subject: [PATCH 06/18] Document unstable cargo feature --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 709c31f..6736361 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,18 @@ libtest - Rust's built-in unit-testing and benchmarking framework See [The Rust Programming Language chapter on Testing](https://doc.rust-lang.org/book/ch11-00-testing.html). +## Cargo features + +* `unstable` (disabled by default): enables nightly features. Currently, this enables: + * `feature(set_stdio)`: better output reporting + * `feature(panic_unwind)`: explicitly links against the `panic_unwind` crate + on platforms that support it, but avoid that on platforms that do not. This + allows using `libtest` on platforms like `aarch64-pc-windows-msvc` which do + not yet support `panic_unwind`. + * `feature(termination_trait_lib)`: exposes the `assert_test_result` API + * `feature(test)`: uses `test::black_box` in benchmarks. On stable Rust, this is + worked around with volatile loads and stores which aren't as good. + ## Platform support * "build" shows whether the library compiles From 44b024a90fefcfe186aa25e6461f980527019529 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Wed, 20 Mar 2019 10:39:21 +0100 Subject: [PATCH 07/18] Test the beta and stable release channels --- .travis.yml | 48 ++++++++++++++++++++++++++++++++++++++++++------ ci/run.sh | 6 ++++-- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 160fda8..f12d61e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,8 +11,6 @@ matrix: - name: "Integration" install: true script: sh ci/integration.sh - - # cross targets: - name: "aarch64-linux-android" env: TARGET=aarch64-linux-android CROSS=1 - name: "aarch64-unknown-linux-gnu" @@ -42,9 +40,19 @@ matrix: packages: - gcc-multilib - - name: "i686-apple-darwin" + - name: "i686-apple-darwin (nightly)" + env: TARGET=i686-apple-darwin + os: osx + osx_image: xcode10 + - name: "i686-apple-darwin (beta)" + env: TARGET=i686-apple-darwin + os: osx + rust: beta + osx_image: xcode10 + - name: "i686-apple-darwin (stable)" env: TARGET=i686-apple-darwin os: osx + rust: stable osx_image: xcode10 - name: "i686-linux-android" env: TARGET=i686-linux-android CROSS=1 @@ -52,9 +60,17 @@ matrix: env: TARGET=i686-pc-windows-gnu CROSS=1 - name: "i686-unknown-freebsd" env: TARGET=i686-unknown-freebsd NORUN=1 CROSS=1 - - name: "i686-unknown-linux-gnu" + - name: "i686-unknown-linux-gnu (nightly)" + env: TARGET=i686-unknown-linux-gnu CROSS=1 + addons: *gcc_multilib + - name: "i686-unknown-linux-gnu (beta)" env: TARGET=i686-unknown-linux-gnu CROSS=1 addons: *gcc_multilib + rust: beta + - name: "i686-unknown-linux-gnu (stable)" + env: TARGET=i686-unknown-linux-gnu CROSS=1 + addons: *gcc_multilib + rust: stable - name: "i686-unknown-linux-musl" env: TARGET=i686-unknown-linux-musl CROSS=1 - name: "mips-unknown-linux-gnu" @@ -75,20 +91,40 @@ matrix: env: TARGET=s390x-unknown-linux-gnu CROSS=1 NORUN=1 - name: "sparc64-unknown-linux-gnu" env: TARGET=sparc64-unknown-linux-gnu CROSS=1 NORUN=1 - - name: "x86_64-apple-darwin" + - name: "x86_64-apple-darwin (nightly)" env: TARGET=x86_64-apple-darwin os: osx osx_image: xcode10 install: true + - name: "x86_64-apple-darwin (beta)" + env: TARGET=x86_64-apple-darwin + os: osx + osx_image: xcode10 + install: true + rust: beta + - name: "x86_64-apple-darwin (stable)" + env: TARGET=x86_64-apple-darwin + os: osx + osx_image: xcode10 + install: true + rust: stable - name: "x86_64-linux-android" env: TARGET=x86_64-linux-android CROSS=1 - name: "x86_64-sun-solaris" env: TARGET=x86_64-sun-solaris NORUN=1 CROSS=1 - name: "x86_64-unknown-freebsd" env: TARGET=x86_64-unknown-freebsd NORUN=1 CROSS=1 - - name: "x86_64-unknown-linux-gnu" + - name: "x86_64-unknown-linux-gnu (nightly)" + env: TARGET=x86_64-unknown-linux-gnu + install: true + - name: "x86_64-unknown-linux-gnu (beta)" + env: TARGET=x86_64-unknown-linux-gnu + install: true + rust: beta + - name: "x86_64-unknown-linux-gnu (stable)" env: TARGET=x86_64-unknown-linux-gnu install: true + rust: stable - name: "x86_64-unknown-linux-musl" env: TARGET=x86_64-unknown-linux-musl CROSS=1 - name: "x86_64-unknown-netbsd" diff --git a/ci/run.sh b/ci/run.sh index eaaa6e6..1d87b44 100644 --- a/ci/run.sh +++ b/ci/run.sh @@ -17,5 +17,7 @@ fi "${CARGO}" "${CMD}" -vv --all --target="${TARGET}" "${CARGO}" "${CMD}" -vv --all --target="${TARGET}" --release -"${CARGO}" "${CMD}" -vv --all --target="${TARGET}" --features=unstable -"${CARGO}" "${CMD}" -vv --all --target="${TARGET}" --features=unstable --release +if [ "${TRAVIS_RUST_VERSION}" = "nightly" ]; then + "${CARGO}" "${CMD}" -vv --all --target="${TARGET}" --features=unstable + "${CARGO}" "${CMD}" -vv --all --target="${TARGET}" --features=unstable --release +fi From a745caa1a525d36846caeb318b16258aff4438d1 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Wed, 20 Mar 2019 10:43:40 +0100 Subject: [PATCH 08/18] Test the beta and stable release channels on Windows --- .azure-pipelines.yml | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml index d6be177..5b98ad2 100644 --- a/.azure-pipelines.yml +++ b/.azure-pipelines.yml @@ -5,11 +5,36 @@ jobs: - template: ci/azure-job-test-all.yml parameters: vmImage: vs2017-win2016 - name: x86_64_msvc + name: x86_64_msvc_nightly target: x86_64-pc-windows-msvc + toolchain: nightly-x86_64-msvc +- template: ci/azure-job-test-all.yml + parameters: + vmImage: vs2017-win2016 + name: x86_64_msvc_beta + target: x86_64-pc-windows-msvc + toolchain: beta-x86_64-msvc +- template: ci/azure-job-test-all.yml + parameters: + vmImage: vs2017-win2016 + name: x86_64_msvc_stable + target: x86_64-pc-windows-msvc + toolchain: stable-x86_64-msvc - template: ci/azure-job-test-all.yml parameters: vmImage: vs2017-win2016 toolchain: nightly-x86_64-gnu - name: x86_64_mingw + name: x86_64_mingw_nightly + target: x86_64-pc-windows-gnu +- template: ci/azure-job-test-all.yml + parameters: + vmImage: vs2017-win2016 + toolchain: beta-x86_64-gnu + name: x86_64_mingw_beta + target: x86_64-pc-windows-gnu +- template: ci/azure-job-test-all.yml + parameters: + vmImage: vs2017-win2016 + toolchain: stable-x86_64-gnu + name: x86_64_mingw_stable target: x86_64-pc-windows-gnu From 42760f5c59be7280c1430a5890921901b764cfaa Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Wed, 20 Mar 2019 10:48:11 +0100 Subject: [PATCH 09/18] Allow the integration test to fail --- .travis.yml | 4 ++++ ci/integration.sh | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f12d61e..6c0609a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -130,6 +130,10 @@ matrix: - name: "x86_64-unknown-netbsd" env: TARGET=x86_64-unknown-netbsd NORUN=1 CROSS=1 + allow_failures: + # FIXME: the compiletest-rs crate needs to be updated to libtest 0.0.2 + - name: "Integration" + install: - travis_retry rustup target add $TARGET - | diff --git a/ci/integration.sh b/ci/integration.sh index e5dd28a..f0e2a41 100644 --- a/ci/integration.sh +++ b/ci/integration.sh @@ -7,7 +7,8 @@ rm -r compiletest-rs || true git clone git@github.com:laumann/compiletest-rs.git ( cd compiletest-rs - sed -i '' 's@libtest = "0.0.1"@libtest = { path = "..", features = [ "unstable" ] }@g' Cargo.toml + sed -i '' 's@libtest = "0.0.2"@libtest = { path = "..", features = [ "unstable" ] }@g' Cargo.toml echo "[workspace]" >> Cargo.toml cargo build + cargo build --features=unstable ) From 4ed55238f4f948fd898bb469b7a782355f7579fc Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Wed, 20 Mar 2019 11:16:47 +0100 Subject: [PATCH 10/18] Clone compiletest-rs via https instead of ssh --- ci/integration.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/integration.sh b/ci/integration.sh index f0e2a41..70ac3fe 100644 --- a/ci/integration.sh +++ b/ci/integration.sh @@ -4,7 +4,7 @@ set -ex # compile-test rm -r compiletest-rs || true -git clone git@github.com:laumann/compiletest-rs.git +git clone https://github.com/laumann/compiletest-rs ( cd compiletest-rs sed -i '' 's@libtest = "0.0.2"@libtest = { path = "..", features = [ "unstable" ] }@g' Cargo.toml From 71195993741c1cbe54fc5e3522437425257ccabe Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Wed, 20 Mar 2019 11:42:29 +0100 Subject: [PATCH 11/18] Test the unstable cargo feature on Azure --- .azure-pipelines.yml | 12 ++++++------ ci/azure-job-test-nightly.yml | 17 +++++++++++++++++ ...b-test-all.yml => azure-job-test-stable.yml} | 0 3 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 ci/azure-job-test-nightly.yml rename ci/{azure-job-test-all.yml => azure-job-test-stable.yml} (100%) diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml index 5b98ad2..f9064ac 100644 --- a/.azure-pipelines.yml +++ b/.azure-pipelines.yml @@ -2,37 +2,37 @@ trigger: - master jobs: -- template: ci/azure-job-test-all.yml +- template: ci/azure-job-test-nightly.yml parameters: vmImage: vs2017-win2016 name: x86_64_msvc_nightly target: x86_64-pc-windows-msvc toolchain: nightly-x86_64-msvc -- template: ci/azure-job-test-all.yml +- template: ci/azure-job-test-stable.yml parameters: vmImage: vs2017-win2016 name: x86_64_msvc_beta target: x86_64-pc-windows-msvc toolchain: beta-x86_64-msvc -- template: ci/azure-job-test-all.yml +- template: ci/azure-job-test-stable.yml parameters: vmImage: vs2017-win2016 name: x86_64_msvc_stable target: x86_64-pc-windows-msvc toolchain: stable-x86_64-msvc -- template: ci/azure-job-test-all.yml +- template: ci/azure-job-test-nightly.yml parameters: vmImage: vs2017-win2016 toolchain: nightly-x86_64-gnu name: x86_64_mingw_nightly target: x86_64-pc-windows-gnu -- template: ci/azure-job-test-all.yml +- template: ci/azure-job-test-stable.yml parameters: vmImage: vs2017-win2016 toolchain: beta-x86_64-gnu name: x86_64_mingw_beta target: x86_64-pc-windows-gnu -- template: ci/azure-job-test-all.yml +- template: ci/azure-job-test-stable.yml parameters: vmImage: vs2017-win2016 toolchain: stable-x86_64-gnu diff --git a/ci/azure-job-test-nightly.yml b/ci/azure-job-test-nightly.yml new file mode 100644 index 0000000..0b9fc2c --- /dev/null +++ b/ci/azure-job-test-nightly.yml @@ -0,0 +1,17 @@ +parameters: + toolchain: 'nightly' + vmImage: 'ubuntu-16.04' + name: '' + +jobs: +- job: ${{ parameters.name }} + pool: + vmImage: ${{ parameters.vmImage }} + steps: + - template: azure-install-rust.yml + parameters: + toolchain: ${{ parameters.toolchain }} + - script: cargo test -vv --all --target ${{ parameters.target }} + - script: cargo test -vv --all --release --target ${{ parameters.target }} + - script: cargo test -vv --all --target ${{ parameters.target }} --features=unstable + - script: cargo test -vv --all --release --target ${{ parameters.target }} --features=unstable diff --git a/ci/azure-job-test-all.yml b/ci/azure-job-test-stable.yml similarity index 100% rename from ci/azure-job-test-all.yml rename to ci/azure-job-test-stable.yml From 4f474cbd2f790887dcabbd01dc9df5e745be8412 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Wed, 20 Mar 2019 12:04:52 +0100 Subject: [PATCH 12/18] Make ColorChoice public --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 48a89a7..2a1c156 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,7 +49,7 @@ use std::{ #[cfg(feature = "unstable")] use std::process::Termination; -use termcolor::ColorChoice; +pub use termcolor::ColorChoice; const TEST_WARN_TIMEOUT_S: u64 = 60; const QUIET_MODE_MAX_COLUMN: usize = 100; // insert a '\n' after 100 tests in quiet mode From 584b2b35d3cb82ff1eb262fbefdb95f3884516fe Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Wed, 20 Mar 2019 23:37:01 +0100 Subject: [PATCH 13/18] Cosmetic changes --- Cargo.toml | 7 +------ src/lib.rs | 2 -- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0c1a55a..1b545f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,16 +5,11 @@ version = "0.0.2" edition = "2018" description = "Rust's built in unit-test and micro-benchmarking framework" license = "MIT/Apache-2.0" -documentation = "https://docs.rs/libterm" +documentation = "https://docs.rs/libtest" homepage = "https://github.com/rust-lang/libtest" repository = "https://github.com/rust-lang/libtest" readme = "README.md" -[lib] -name = "libtest" -path = "src/lib.rs" -crate-type = ["dylib", "rlib"] - [dependencies] getopts = "0.2" termcolor = "1.0" diff --git a/src/lib.rs b/src/lib.rs index 2a1c156..f3d42e7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,8 +11,6 @@ clippy::cast_precision_loss )] -use getopts; - #[cfg(feature = "unstable")] extern crate test; From 719256356b565a138e0005cabbc56153e5902dca Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Tue, 26 Mar 2019 15:55:31 +0100 Subject: [PATCH 14/18] Do not rely on the test crate during stage0 --- src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f3d42e7..7179402 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,7 +11,7 @@ clippy::cast_precision_loss )] -#[cfg(feature = "unstable")] +#[cfg(all(feature = "unstable", not(stage0)))] extern crate test; #[cfg(any(unix, target_os = "cloudabi"))] @@ -1687,11 +1687,11 @@ fn ns_from_dur(dur: Duration) -> u64 { #[inline(never)] #[allow(clippy::needless_pass_by_value)] fn black_box(x: T) -> T { - #[cfg(feature = "unstable")] + #[cfg(all(feature = "unstable", not(stage0)))] { test::black_box(x) } - #[cfg(not(feature = "unstable"))] + #[cfg(any(not(feature = "unstable"), stage0))] { unsafe { std::ptr::read_volatile(&x as *const T) } } From 2cb20561a6162879801a08a606cec9c72dbc3f10 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Tue, 26 Mar 2019 23:20:15 +0100 Subject: [PATCH 15/18] Use hint::black_box instead of test::black_box --- src/lib.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7179402..78f809f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,9 +11,6 @@ clippy::cast_precision_loss )] -#[cfg(all(feature = "unstable", not(stage0)))] -extern crate test; - #[cfg(any(unix, target_os = "cloudabi"))] extern crate libc; @@ -1689,7 +1686,7 @@ fn ns_from_dur(dur: Duration) -> u64 { fn black_box(x: T) -> T { #[cfg(all(feature = "unstable", not(stage0)))] { - test::black_box(x) + std::hint::black_box(x) } #[cfg(any(not(feature = "unstable"), stage0))] { From 1e98ee4f3b0b6b3f099efd761e1a3d916418797d Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Fri, 29 Mar 2019 19:05:29 +0100 Subject: [PATCH 16/18] Remove unnecessary feature(test) --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 78f809f..d9e6345 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ //! Rust's built-in unit-test and micro-benchmarking framework. #![cfg_attr( feature = "unstable", - feature(set_stdio, panic_unwind, termination_trait_lib, test,) + feature(set_stdio, panic_unwind, termination_trait_lib) )] #![deny(rust_2018_idioms)] #![allow( From 1f13f7dd286fd16c76bd61ddcbe162fca9f9d9d2 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Sat, 30 Mar 2019 13:32:47 +0100 Subject: [PATCH 17/18] Re-add test feature: required for black_box --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index d9e6345..b6db2a1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ //! Rust's built-in unit-test and micro-benchmarking framework. #![cfg_attr( feature = "unstable", - feature(set_stdio, panic_unwind, termination_trait_lib) + feature(set_stdio, panic_unwind, termination_trait_lib, test) )] #![deny(rust_2018_idioms)] #![allow( From 6a9e5342203dce7a069f57084c56c97870d7ad60 Mon Sep 17 00:00:00 2001 From: CrLF0710 Date: Sun, 7 Apr 2019 23:30:49 +0800 Subject: [PATCH 18/18] Fix bug in black_box unsafe block. Run rustfmt. --- src/lib.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b6db2a1..4da6733 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -599,7 +599,7 @@ pub fn parse_opts(args: &[String]) -> Option { Ok(0) => { return Some(Err( "argument for --test-threads must not be 0".to_string() - )) + )); } Ok(n) => Some(n), Err(e) => { @@ -1690,7 +1690,11 @@ fn black_box(x: T) -> T { } #[cfg(any(not(feature = "unstable"), stage0))] { - unsafe { std::ptr::read_volatile(&x as *const T) } + unsafe { + let v = std::ptr::read_volatile(&x as *const T); + std::mem::forget(x); + v + } } }