Transition libtest to 2018 edition

This commit is contained in:
Hirokazu Hata 2019-02-04 00:56:16 +09:00
parent 4f4f4a40b6
commit 4ae8abab93
4 changed files with 22 additions and 20 deletions

View File

@ -2,6 +2,7 @@
authors = ["The Rust Project Developers"] authors = ["The Rust Project Developers"]
name = "test" name = "test"
version = "0.0.0" version = "0.0.0"
edition = "2018"
[lib] [lib]
name = "test" name = "test"

View File

@ -145,7 +145,7 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
struct EscapedString<S: AsRef<str>>(S); struct EscapedString<S: AsRef<str>>(S);
impl<S: AsRef<str>> ::std::fmt::Display for EscapedString<S> { impl<S: AsRef<str>> ::std::fmt::Display for EscapedString<S> {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
let mut start = 0; let mut start = 0;
for (i, byte) in self.0.as_ref().bytes().enumerate() { for (i, byte) in self.0.as_ref().bytes().enumerate() {

View File

@ -17,6 +17,7 @@
// this crate, which relies on this attribute (rather than the value of `--crate-name` passed by // this crate, which relies on this attribute (rather than the value of `--crate-name` passed by
// cargo) to detect this crate. // cargo) to detect this crate.
#![deny(rust_2018_idioms)]
#![crate_name = "test"] #![crate_name = "test"]
#![unstable(feature = "test", issue = "27812")] #![unstable(feature = "test", issue = "27812")]
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
@ -32,10 +33,10 @@
#![feature(termination_trait_lib)] #![feature(termination_trait_lib)]
#![feature(test)] #![feature(test)]
extern crate getopts; use getopts;
#[cfg(any(unix, target_os = "cloudabi"))] #[cfg(any(unix, target_os = "cloudabi"))]
extern crate libc; extern crate libc;
extern crate term; use term;
// FIXME(#54291): rustc and/or LLVM don't yet support building with panic-unwind // FIXME(#54291): rustc and/or LLVM don't yet support building with panic-unwind
// on aarch64-pc-windows-msvc, so we don't link libtest against // on aarch64-pc-windows-msvc, so we don't link libtest against
@ -78,7 +79,7 @@ const QUIET_MODE_MAX_COLUMN: usize = 100; // insert a '\n' after 100 tests in qu
// to be used by rustc to compile tests in libtest // to be used by rustc to compile tests in libtest
pub mod test { pub mod test {
pub use {assert_test_result, filter_tests, parse_opts, run_test, test_main, test_main_static, pub use crate::{assert_test_result, filter_tests, parse_opts, run_test, test_main, test_main_static,
Bencher, DynTestFn, DynTestName, Metric, MetricMap, Options, RunIgnored, ShouldPanic, Bencher, DynTestFn, DynTestName, Metric, MetricMap, Options, RunIgnored, ShouldPanic,
StaticBenchFn, StaticTestFn, StaticTestName, TestDesc, TestDescAndFn, TestName, StaticBenchFn, StaticTestFn, StaticTestName, TestDesc, TestDescAndFn, TestName,
TestOpts, TestResult, TrFailed, TrFailedMsg, TrIgnored, TrOk}; TestOpts, TestResult, TrFailed, TrFailedMsg, TrIgnored, TrOk};
@ -87,7 +88,7 @@ pub mod test {
pub mod stats; pub mod stats;
mod formatters; mod formatters;
use formatters::{JsonFormatter, OutputFormatter, PrettyFormatter, TerseFormatter}; use crate::formatters::{JsonFormatter, OutputFormatter, PrettyFormatter, TerseFormatter};
/// Whether to execute tests concurrently or not /// Whether to execute tests concurrently or not
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
@ -131,7 +132,7 @@ impl TestName {
} }
} }
impl fmt::Display for TestName { impl fmt::Display for TestName {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(self.as_slice(), f) fmt::Display::fmt(self.as_slice(), f)
} }
} }
@ -185,7 +186,7 @@ impl TestFn {
} }
impl fmt::Debug for TestFn { impl fmt::Debug for TestFn {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match *self { f.write_str(match *self {
StaticTestFn(..) => "StaticTestFn(..)", StaticTestFn(..) => "StaticTestFn(..)",
StaticBenchFn(..) => "StaticBenchFn(..)", StaticBenchFn(..) => "StaticBenchFn(..)",
@ -823,7 +824,7 @@ pub fn list_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> io::Res
let mut nbench = 0; let mut nbench = 0;
for test in filter_tests(&opts, tests) { for test in filter_tests(&opts, tests) {
use TestFn::*; use crate::TestFn::*;
let TestDescAndFn { let TestDescAndFn {
desc: TestDesc { name, .. }, desc: TestDesc { name, .. },
@ -1454,12 +1455,12 @@ pub fn run_test(
match testfn { match testfn {
DynBenchFn(bencher) => { DynBenchFn(bencher) => {
::bench::benchmark(desc, monitor_ch, opts.nocapture, |harness| { crate::bench::benchmark(desc, monitor_ch, opts.nocapture, |harness| {
bencher.run(harness) bencher.run(harness)
}); });
} }
StaticBenchFn(benchfn) => { StaticBenchFn(benchfn) => {
::bench::benchmark(desc, monitor_ch, opts.nocapture, |harness| { crate::bench::benchmark(desc, monitor_ch, opts.nocapture, |harness| {
(benchfn.clone())(harness) (benchfn.clone())(harness)
}); });
} }
@ -1673,7 +1674,7 @@ pub mod bench {
use std::cmp; use std::cmp;
use std::io; use std::io;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use stats; use crate::stats;
use super::{BenchMode, BenchSamples, Bencher, MonitorMsg, Sender, Sink, TestDesc, TestResult}; use super::{BenchMode, BenchSamples, Bencher, MonitorMsg, Sender, Sink, TestDesc, TestResult};
pub fn benchmark<F>(desc: TestDesc, monitor_ch: Sender<MonitorMsg>, nocapture: bool, f: F) pub fn benchmark<F>(desc: TestDesc, monitor_ch: Sender<MonitorMsg>, nocapture: bool, f: F)
@ -1749,13 +1750,13 @@ pub mod bench {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use test::{filter_tests, parse_opts, run_test, DynTestFn, DynTestName, MetricMap, RunIgnored, use crate::test::{filter_tests, parse_opts, run_test, DynTestFn, DynTestName, MetricMap, RunIgnored,
ShouldPanic, StaticTestName, TestDesc, TestDescAndFn, TestOpts, TrFailed, ShouldPanic, StaticTestName, TestDesc, TestDescAndFn, TestOpts, TrFailed,
TrFailedMsg, TrIgnored, TrOk}; TrFailedMsg, TrIgnored, TrOk};
use std::sync::mpsc::channel; use std::sync::mpsc::channel;
use bench; use crate::bench;
use Bencher; use crate::Bencher;
use Concurrent; use crate::Concurrent;
fn one_ignored_one_unignored_test() -> Vec<TestDescAndFn> { fn one_ignored_one_unignored_test() -> Vec<TestDescAndFn> {
@ -2156,7 +2157,7 @@ mod tests {
allow_fail: false, allow_fail: false,
}; };
::bench::benchmark(desc, tx, true, f); crate::bench::benchmark(desc, tx, true, f);
rx.recv().unwrap(); rx.recv().unwrap();
} }
@ -2175,7 +2176,7 @@ mod tests {
allow_fail: false, allow_fail: false,
}; };
::bench::benchmark(desc, tx, true, f); crate::bench::benchmark(desc, tx, true, f);
rx.recv().unwrap(); rx.recv().unwrap();
} }
} }

View File

@ -319,8 +319,8 @@ pub fn winsorize(samples: &mut [f64], pct: f64) {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use stats::Stats; use crate::stats::Stats;
use stats::Summary; use crate::stats::Summary;
use std::f64; use std::f64;
use std::io::prelude::*; use std::io::prelude::*;
use std::io; use std::io;
@ -899,7 +899,7 @@ mod tests {
mod bench { mod bench {
extern crate test; extern crate test;
use self::test::Bencher; use self::test::Bencher;
use stats::Stats; use crate::stats::Stats;
#[bench] #[bench]
pub fn sum_three_items(b: &mut Bencher) { pub fn sum_three_items(b: &mut Bencher) {