Skip to content

Commit 751af27

Browse files
committed
libtest: Unconfigure tests during normal build
1 parent 77eacae commit 751af27

File tree

5 files changed

+89
-96
lines changed

5 files changed

+89
-96
lines changed

src/libtest/lib.rs

Lines changed: 15 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ use std::sync::{Arc, Mutex};
7070
use std::thread;
7171
use std::time::{Duration, Instant};
7272

73+
#[cfg(test)]
74+
mod tests;
75+
7376
const TEST_WARN_TIMEOUT_S: u64 = 60;
7477
const QUIET_MODE_MAX_COLUMN: usize = 100; // insert a '\n' after 100 tests in quiet mode
7578

@@ -495,18 +498,18 @@ environment variable to a value other than "0". Logging is not captured by defau
495498
496499
Test Attributes:
497500
498-
#[test] - Indicates a function is a test to be run. This function
499-
takes no arguments.
500-
#[bench] - Indicates a function is a benchmark to be run. This
501-
function takes one argument (test::Bencher).
502-
#[should_panic] - This function (also labeled with #[test]) will only pass if
503-
the code causes a panic (an assertion failure or panic!)
504-
A message may be provided, which the failure string must
505-
contain: #[should_panic(expected = "foo")].
506-
#[ignore] - When applied to a function which is already attributed as a
507-
test, then the test runner will ignore these tests during
508-
normal test runs. Running with --ignored or --include-ignored will run
509-
these tests."#,
501+
`#[test]` - Indicates a function is a test to be run. This function
502+
takes no arguments.
503+
`#[bench]` - Indicates a function is a benchmark to be run. This
504+
function takes one argument (test::Bencher).
505+
`#[should_panic]` - This function (also labeled with `#[test]`) will only pass if
506+
the code causes a panic (an assertion failure or panic!)
507+
A message may be provided, which the failure string must
508+
contain: #[should_panic(expected = "foo")].
509+
`#[ignore]` - When applied to a function which is already attributed as a
510+
test, then the test runner will ignore these tests during
511+
normal test runs. Running with --ignored or --include-ignored will run
512+
these tests."#,
510513
usage = options.usage(&message)
511514
);
512515
}
@@ -974,50 +977,6 @@ pub fn run_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> io::Resu
974977
return out.write_run_finish(&st);
975978
}
976979

977-
#[test]
978-
fn should_sort_failures_before_printing_them() {
979-
let test_a = TestDesc {
980-
name: StaticTestName("a"),
981-
ignore: false,
982-
should_panic: ShouldPanic::No,
983-
allow_fail: false,
984-
};
985-
986-
let test_b = TestDesc {
987-
name: StaticTestName("b"),
988-
ignore: false,
989-
should_panic: ShouldPanic::No,
990-
allow_fail: false,
991-
};
992-
993-
let mut out = PrettyFormatter::new(Raw(Vec::new()), false, 10, false);
994-
995-
let st = ConsoleTestState {
996-
log_out: None,
997-
total: 0,
998-
passed: 0,
999-
failed: 0,
1000-
ignored: 0,
1001-
allowed_fail: 0,
1002-
filtered_out: 0,
1003-
measured: 0,
1004-
metrics: MetricMap::new(),
1005-
failures: vec![(test_b, Vec::new()), (test_a, Vec::new())],
1006-
options: Options::new(),
1007-
not_failures: Vec::new(),
1008-
};
1009-
1010-
out.write_failures(&st).unwrap();
1011-
let s = match out.output_location() {
1012-
&Raw(ref m) => String::from_utf8_lossy(&m[..]),
1013-
&Pretty(_) => unreachable!(),
1014-
};
1015-
1016-
let apos = s.find("a").unwrap();
1017-
let bpos = s.find("b").unwrap();
1018-
assert!(apos < bpos);
1019-
}
1020-
1021980
fn use_color(opts: &TestOpts) -> bool {
1022981
match opts.color {
1023982
AutoColor => !opts.nocapture && stdout_isatty(),
@@ -1775,6 +1734,3 @@ pub mod bench {
17751734
bs.bench(f);
17761735
}
17771736
}
1778-
1779-
#[cfg(test)]
1780-
mod tests;

src/libtest/stats.rs

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
use std::cmp::Ordering::{self, Equal, Greater, Less};
55
use std::mem;
66

7+
#[cfg(test)]
8+
mod tests;
9+
710
fn local_cmp(x: f64, y: f64) -> Ordering {
811
// arbitrarily decide that NaNs are larger than everything.
912
if y.is_nan() {
@@ -314,34 +317,3 @@ pub fn winsorize(samples: &mut [f64], pct: f64) {
314317
}
315318
}
316319
}
317-
318-
// Test vectors generated from R, using the script src/etc/stat-test-vectors.r.
319-
320-
#[cfg(test)]
321-
mod tests;
322-
323-
#[cfg(test)]
324-
mod bench {
325-
extern crate test;
326-
use self::test::Bencher;
327-
use crate::stats::Stats;
328-
329-
#[bench]
330-
pub fn sum_three_items(b: &mut Bencher) {
331-
b.iter(|| {
332-
[1e20f64, 1.5f64, -1e20f64].sum();
333-
})
334-
}
335-
#[bench]
336-
pub fn sum_many_f64(b: &mut Bencher) {
337-
let nums = [-1e30f64, 1e60, 1e30, 1.0, -1e60];
338-
let v = (0..500).map(|i| nums[i % 5]).collect::<Vec<_>>();
339-
340-
b.iter(|| {
341-
v.sum();
342-
})
343-
}
344-
345-
#[bench]
346-
pub fn no_iter(_: &mut Bencher) {}
347-
}

src/libtest/stats/tests.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
use crate::stats::Stats;
2-
use crate::stats::Summary;
1+
use super::*;
2+
3+
extern crate test;
34
use std::f64;
45
use std::io::prelude::*;
56
use std::io;
7+
use self::test::Bencher;
8+
9+
// Test vectors generated from R, using the script src/etc/stat-test-vectors.r.
610

711
macro_rules! assert_approx_eq {
812
($a: expr, $b: expr) => {{
@@ -572,3 +576,22 @@ fn test_sum_f64s() {
572576
fn test_sum_f64_between_ints_that_sum_to_0() {
573577
assert_eq!([1e30f64, 1.2f64, -1e30f64].sum(), 1.2);
574578
}
579+
580+
#[bench]
581+
pub fn sum_three_items(b: &mut Bencher) {
582+
b.iter(|| {
583+
[1e20f64, 1.5f64, -1e20f64].sum();
584+
})
585+
}
586+
#[bench]
587+
pub fn sum_many_f64(b: &mut Bencher) {
588+
let nums = [-1e30f64, 1e60, 1e30, 1.0, -1e60];
589+
let v = (0..500).map(|i| nums[i % 5]).collect::<Vec<_>>();
590+
591+
b.iter(|| {
592+
v.sum();
593+
})
594+
}
595+
596+
#[bench]
597+
pub fn no_iter(_: &mut Bencher) {}

src/libtest/tests.rs

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
use crate::bench;
1+
use super::*;
2+
23
use crate::test::{
34
filter_tests, parse_opts, run_test, DynTestFn, DynTestName, MetricMap, RunIgnored,
45
ShouldPanic, StaticTestName, TestDesc, TestDescAndFn, TestOpts, TrFailed, TrFailedMsg,
56
TrIgnored, TrOk,
67
};
7-
use crate::Bencher;
8-
use crate::Concurrent;
98
use std::sync::mpsc::channel;
109

1110
fn one_ignored_one_unignored_test() -> Vec<TestDescAndFn> {
@@ -451,3 +450,47 @@ pub fn test_bench_iter() {
451450
crate::bench::benchmark(desc, tx, true, f);
452451
rx.recv().unwrap();
453452
}
453+
454+
#[test]
455+
fn should_sort_failures_before_printing_them() {
456+
let test_a = TestDesc {
457+
name: StaticTestName("a"),
458+
ignore: false,
459+
should_panic: ShouldPanic::No,
460+
allow_fail: false,
461+
};
462+
463+
let test_b = TestDesc {
464+
name: StaticTestName("b"),
465+
ignore: false,
466+
should_panic: ShouldPanic::No,
467+
allow_fail: false,
468+
};
469+
470+
let mut out = PrettyFormatter::new(Raw(Vec::new()), false, 10, false);
471+
472+
let st = ConsoleTestState {
473+
log_out: None,
474+
total: 0,
475+
passed: 0,
476+
failed: 0,
477+
ignored: 0,
478+
allowed_fail: 0,
479+
filtered_out: 0,
480+
measured: 0,
481+
metrics: MetricMap::new(),
482+
failures: vec![(test_b, Vec::new()), (test_a, Vec::new())],
483+
options: Options::new(),
484+
not_failures: Vec::new(),
485+
};
486+
487+
out.write_failures(&st).unwrap();
488+
let s = match out.output_location() {
489+
&Raw(ref m) => String::from_utf8_lossy(&m[..]),
490+
&Pretty(_) => unreachable!(),
491+
};
492+
493+
let apos = s.find("a").unwrap();
494+
let bpos = s.find("b").unwrap();
495+
assert!(apos < bpos);
496+
}

src/tools/tidy/src/unit_tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ pub fn check(root_path: &Path, bad: &mut bool) {
3939
"libsyntax",
4040
"libsyntax_pos",
4141
"libterm/terminfo",
42-
"libtest",
4342
];
4443

4544
let mut skip = |path: &Path| {

0 commit comments

Comments
 (0)