Skip to content

Commit d5863e9

Browse files
Add Options type in libtest and remove argument
1 parent f30ed77 commit d5863e9

File tree

5 files changed

+39
-24
lines changed

5 files changed

+39
-24
lines changed

src/librustdoc/markdown.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,7 @@ pub fn test(input: &str, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
166166
old_find_testable_code(&input_str, &mut collector, DUMMY_SP);
167167
find_testable_code(&input_str, &mut collector, DUMMY_SP);
168168
test_args.insert(0, "rustdoctest".to_string());
169-
if display_warnings {
170-
test_args.insert(1, "--display-stdout".to_string());
171-
}
172-
testing::test_main(&test_args, collector.tests);
169+
testing::test_main(&test_args, collector.tests,
170+
testing::Options::new().display_output(display_warnings));
173171
0
174172
}

src/librustdoc/test.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,10 @@ pub fn run(input: &str,
126126
}
127127

128128
test_args.insert(0, "rustdoctest".to_string());
129-
if display_warnings {
130-
test_args.insert(1, "--display-stdout".to_string());
131-
}
132129

133130
testing::test_main(&test_args,
134-
collector.tests.into_iter().collect());
131+
collector.tests.into_iter().collect(),
132+
testing::Options::new().display_output(display_warnings));
135133
0
136134
}
137135

src/libsyntax/test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ We're going to be building a module that looks more or less like:
442442
mod __test {
443443
extern crate test (name = "test", vers = "...");
444444
fn main() {
445-
test::test_main_static(&::os::args()[], tests)
445+
test::test_main_static(&::os::args()[], tests, test::Options::new())
446446
}
447447
448448
static tests : &'static [test::TestDescAndFn] = &[
@@ -478,7 +478,7 @@ fn mk_main(cx: &mut TestCtxt) -> P<ast::Item> {
478478
// pub fn main() {
479479
// #![main]
480480
// use std::slice::AsSlice;
481-
// test::test_main_static(::std::os::args().as_slice(), TESTS);
481+
// test::test_main_static(::std::os::args().as_slice(), TESTS, test::Options::new());
482482
// }
483483

484484
let sp = ignored_span(cx, DUMMY_SP);

src/libtest/lib.rs

+32-13
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub mod test {
7676
pub use {Bencher, TestName, TestResult, TestDesc, TestDescAndFn, TestOpts, TrFailed,
7777
TrFailedMsg, TrIgnored, TrOk, Metric, MetricMap, StaticTestFn, StaticTestName,
7878
DynTestName, DynTestFn, run_test, test_main, test_main_static, filter_tests,
79-
parse_opts, StaticBenchFn, ShouldPanic};
79+
parse_opts, StaticBenchFn, ShouldPanic, Options};
8080
}
8181

8282
pub mod stats;
@@ -252,14 +252,34 @@ impl Clone for MetricMap {
252252
}
253253
}
254254

255+
/// In case we want to add other options as well, just add them in this struct.
256+
#[derive(Copy, Clone, Debug)]
257+
pub struct Options {
258+
display_output: bool,
259+
}
260+
261+
impl Options {
262+
pub fn new() -> Options {
263+
Options {
264+
display_output: false,
265+
}
266+
}
267+
268+
pub fn display_output(mut self, display_output: bool) -> Options {
269+
self.display_output = display_output;
270+
self
271+
}
272+
}
273+
255274
// The default console test runner. It accepts the command line
256275
// arguments and a vector of test_descs.
257-
pub fn test_main(args: &[String], tests: Vec<TestDescAndFn>) {
258-
let opts = match parse_opts(args) {
276+
pub fn test_main(args: &[String], tests: Vec<TestDescAndFn>, options: Options) {
277+
let mut opts = match parse_opts(args) {
259278
Some(Ok(o)) => o,
260279
Some(Err(msg)) => panic!("{:?}", msg),
261280
None => return,
262281
};
282+
opts.options = options;
263283
if opts.list {
264284
if let Err(e) = list_tests_console(&opts, tests) {
265285
panic!("io error when listing tests: {:?}", e);
@@ -301,7 +321,7 @@ pub fn test_main_static(tests: &[TestDescAndFn]) {
301321
}
302322
})
303323
.collect();
304-
test_main(&args, owned_tests)
324+
test_main(&args, owned_tests, Options::new())
305325
}
306326

307327
#[derive(Copy, Clone, Debug)]
@@ -325,7 +345,7 @@ pub struct TestOpts {
325345
pub quiet: bool,
326346
pub test_threads: Option<usize>,
327347
pub skip: Vec<String>,
328-
pub display_stdout: bool,
348+
pub options: Options,
329349
}
330350

331351
impl TestOpts {
@@ -344,7 +364,7 @@ impl TestOpts {
344364
quiet: false,
345365
test_threads: None,
346366
skip: vec![],
347-
display_stdout: false,
367+
options: Options::new(),
348368
}
349369
}
350370
}
@@ -372,8 +392,7 @@ fn optgroups() -> Vec<getopts::OptGroup> {
372392
getopts::optopt("", "color", "Configure coloring of output:
373393
auto = colorize if stdout is a tty and tests are run on serially (default);
374394
always = always colorize output;
375-
never = never colorize output;", "auto|always|never"),
376-
getopts::optflag("", "display-stdout", "to print stdout even if the test succeeds")]
395+
never = never colorize output;", "auto|always|never")]
377396
}
378397

379398
fn usage(binary: &str) {
@@ -485,7 +504,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
485504
quiet: quiet,
486505
test_threads: test_threads,
487506
skip: matches.opt_strs("skip"),
488-
display_stdout: matches.opt_present("display-stdout"),
507+
options: Options::new(),
489508
};
490509

491510
Some(Ok(test_opts))
@@ -528,7 +547,7 @@ struct ConsoleTestState<T> {
528547
failures: Vec<(TestDesc, Vec<u8>)>,
529548
not_failures: Vec<(TestDesc, Vec<u8>)>,
530549
max_name_len: usize, // number of columns to fill when aligning names
531-
display_stdout: bool,
550+
options: Options,
532551
}
533552

534553
impl<T: Write> ConsoleTestState<T> {
@@ -556,7 +575,7 @@ impl<T: Write> ConsoleTestState<T> {
556575
failures: Vec::new(),
557576
not_failures: Vec::new(),
558577
max_name_len: 0,
559-
display_stdout: opts.display_stdout,
578+
options: opts.options,
560579
})
561580
}
562581

@@ -741,7 +760,7 @@ impl<T: Write> ConsoleTestState<T> {
741760
pub fn write_run_finish(&mut self) -> io::Result<bool> {
742761
assert!(self.passed + self.failed + self.ignored + self.measured == self.total);
743762

744-
if self.display_stdout {
763+
if self.options.display_output {
745764
self.write_outputs()?;
746765
}
747766
let success = self.failed == 0;
@@ -942,7 +961,7 @@ fn should_sort_failures_before_printing_them() {
942961
max_name_len: 10,
943962
metrics: MetricMap::new(),
944963
failures: vec![(test_b, Vec::new()), (test_a, Vec::new())],
945-
display_stdout: false,
964+
options: Options::new(),
946965
not_failures: Vec::new(),
947966
};
948967

src/tools/compiletest/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ pub fn test_opts(config: &Config) -> test::TestOpts {
336336
test_threads: None,
337337
skip: vec![],
338338
list: false,
339-
display_stdout: false,
339+
options: test::Options::new(),
340340
}
341341
}
342342

0 commit comments

Comments
 (0)