Skip to content

Commit 4ae8aba

Browse files
committed
Transition libtest to 2018 edition
1 parent 4f4f4a4 commit 4ae8aba

File tree

4 files changed

+22
-20
lines changed

4 files changed

+22
-20
lines changed

src/libtest/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
authors = ["The Rust Project Developers"]
33
name = "test"
44
version = "0.0.0"
5+
edition = "2018"
56

67
[lib]
78
name = "test"

src/libtest/formatters/json.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
145145
struct EscapedString<S: AsRef<str>>(S);
146146

147147
impl<S: AsRef<str>> ::std::fmt::Display for EscapedString<S> {
148-
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
148+
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
149149
let mut start = 0;
150150

151151
for (i, byte) in self.0.as_ref().bytes().enumerate() {

src/libtest/lib.rs

+17-16
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
// this crate, which relies on this attribute (rather than the value of `--crate-name` passed by
1818
// cargo) to detect this crate.
1919

20+
#![deny(rust_2018_idioms)]
2021
#![crate_name = "test"]
2122
#![unstable(feature = "test", issue = "27812")]
2223
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
@@ -32,10 +33,10 @@
3233
#![feature(termination_trait_lib)]
3334
#![feature(test)]
3435

35-
extern crate getopts;
36+
use getopts;
3637
#[cfg(any(unix, target_os = "cloudabi"))]
3738
extern crate libc;
38-
extern crate term;
39+
use term;
3940

4041
// FIXME(#54291): rustc and/or LLVM don't yet support building with panic-unwind
4142
// 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
7879

7980
// to be used by rustc to compile tests in libtest
8081
pub mod test {
81-
pub use {assert_test_result, filter_tests, parse_opts, run_test, test_main, test_main_static,
82+
pub use crate::{assert_test_result, filter_tests, parse_opts, run_test, test_main, test_main_static,
8283
Bencher, DynTestFn, DynTestName, Metric, MetricMap, Options, RunIgnored, ShouldPanic,
8384
StaticBenchFn, StaticTestFn, StaticTestName, TestDesc, TestDescAndFn, TestName,
8485
TestOpts, TestResult, TrFailed, TrFailedMsg, TrIgnored, TrOk};
@@ -87,7 +88,7 @@ pub mod test {
8788
pub mod stats;
8889
mod formatters;
8990

90-
use formatters::{JsonFormatter, OutputFormatter, PrettyFormatter, TerseFormatter};
91+
use crate::formatters::{JsonFormatter, OutputFormatter, PrettyFormatter, TerseFormatter};
9192

9293
/// Whether to execute tests concurrently or not
9394
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
@@ -131,7 +132,7 @@ impl TestName {
131132
}
132133
}
133134
impl fmt::Display for TestName {
134-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
135+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
135136
fmt::Display::fmt(self.as_slice(), f)
136137
}
137138
}
@@ -185,7 +186,7 @@ impl TestFn {
185186
}
186187

187188
impl fmt::Debug for TestFn {
188-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
189+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
189190
f.write_str(match *self {
190191
StaticTestFn(..) => "StaticTestFn(..)",
191192
StaticBenchFn(..) => "StaticBenchFn(..)",
@@ -823,7 +824,7 @@ pub fn list_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> io::Res
823824
let mut nbench = 0;
824825

825826
for test in filter_tests(&opts, tests) {
826-
use TestFn::*;
827+
use crate::TestFn::*;
827828

828829
let TestDescAndFn {
829830
desc: TestDesc { name, .. },
@@ -1454,12 +1455,12 @@ pub fn run_test(
14541455

14551456
match testfn {
14561457
DynBenchFn(bencher) => {
1457-
::bench::benchmark(desc, monitor_ch, opts.nocapture, |harness| {
1458+
crate::bench::benchmark(desc, monitor_ch, opts.nocapture, |harness| {
14581459
bencher.run(harness)
14591460
});
14601461
}
14611462
StaticBenchFn(benchfn) => {
1462-
::bench::benchmark(desc, monitor_ch, opts.nocapture, |harness| {
1463+
crate::bench::benchmark(desc, monitor_ch, opts.nocapture, |harness| {
14631464
(benchfn.clone())(harness)
14641465
});
14651466
}
@@ -1673,7 +1674,7 @@ pub mod bench {
16731674
use std::cmp;
16741675
use std::io;
16751676
use std::sync::{Arc, Mutex};
1676-
use stats;
1677+
use crate::stats;
16771678
use super::{BenchMode, BenchSamples, Bencher, MonitorMsg, Sender, Sink, TestDesc, TestResult};
16781679

16791680
pub fn benchmark<F>(desc: TestDesc, monitor_ch: Sender<MonitorMsg>, nocapture: bool, f: F)
@@ -1749,13 +1750,13 @@ pub mod bench {
17491750

17501751
#[cfg(test)]
17511752
mod tests {
1752-
use test::{filter_tests, parse_opts, run_test, DynTestFn, DynTestName, MetricMap, RunIgnored,
1753+
use crate::test::{filter_tests, parse_opts, run_test, DynTestFn, DynTestName, MetricMap, RunIgnored,
17531754
ShouldPanic, StaticTestName, TestDesc, TestDescAndFn, TestOpts, TrFailed,
17541755
TrFailedMsg, TrIgnored, TrOk};
17551756
use std::sync::mpsc::channel;
1756-
use bench;
1757-
use Bencher;
1758-
use Concurrent;
1757+
use crate::bench;
1758+
use crate::Bencher;
1759+
use crate::Concurrent;
17591760

17601761

17611762
fn one_ignored_one_unignored_test() -> Vec<TestDescAndFn> {
@@ -2156,7 +2157,7 @@ mod tests {
21562157
allow_fail: false,
21572158
};
21582159

2159-
::bench::benchmark(desc, tx, true, f);
2160+
crate::bench::benchmark(desc, tx, true, f);
21602161
rx.recv().unwrap();
21612162
}
21622163

@@ -2175,7 +2176,7 @@ mod tests {
21752176
allow_fail: false,
21762177
};
21772178

2178-
::bench::benchmark(desc, tx, true, f);
2179+
crate::bench::benchmark(desc, tx, true, f);
21792180
rx.recv().unwrap();
21802181
}
21812182
}

src/libtest/stats.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,8 @@ pub fn winsorize(samples: &mut [f64], pct: f64) {
319319

320320
#[cfg(test)]
321321
mod tests {
322-
use stats::Stats;
323-
use stats::Summary;
322+
use crate::stats::Stats;
323+
use crate::stats::Summary;
324324
use std::f64;
325325
use std::io::prelude::*;
326326
use std::io;
@@ -899,7 +899,7 @@ mod tests {
899899
mod bench {
900900
extern crate test;
901901
use self::test::Bencher;
902-
use stats::Stats;
902+
use crate::stats::Stats;
903903

904904
#[bench]
905905
pub fn sum_three_items(b: &mut Bencher) {

0 commit comments

Comments
 (0)