Add Options type in libtest and remove argument
This commit is contained in:
parent
f30ed77f0d
commit
d5863e9985
5 changed files with 39 additions and 24 deletions
|
@ -166,9 +166,7 @@ pub fn test(input: &str, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
|
||||||
old_find_testable_code(&input_str, &mut collector, DUMMY_SP);
|
old_find_testable_code(&input_str, &mut collector, DUMMY_SP);
|
||||||
find_testable_code(&input_str, &mut collector, DUMMY_SP);
|
find_testable_code(&input_str, &mut collector, DUMMY_SP);
|
||||||
test_args.insert(0, "rustdoctest".to_string());
|
test_args.insert(0, "rustdoctest".to_string());
|
||||||
if display_warnings {
|
testing::test_main(&test_args, collector.tests,
|
||||||
test_args.insert(1, "--display-stdout".to_string());
|
testing::Options::new().display_output(display_warnings));
|
||||||
}
|
|
||||||
testing::test_main(&test_args, collector.tests);
|
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,12 +126,10 @@ pub fn run(input: &str,
|
||||||
}
|
}
|
||||||
|
|
||||||
test_args.insert(0, "rustdoctest".to_string());
|
test_args.insert(0, "rustdoctest".to_string());
|
||||||
if display_warnings {
|
|
||||||
test_args.insert(1, "--display-stdout".to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
testing::test_main(&test_args,
|
testing::test_main(&test_args,
|
||||||
collector.tests.into_iter().collect());
|
collector.tests.into_iter().collect(),
|
||||||
|
testing::Options::new().display_output(display_warnings));
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -442,7 +442,7 @@ We're going to be building a module that looks more or less like:
|
||||||
mod __test {
|
mod __test {
|
||||||
extern crate test (name = "test", vers = "...");
|
extern crate test (name = "test", vers = "...");
|
||||||
fn main() {
|
fn main() {
|
||||||
test::test_main_static(&::os::args()[], tests)
|
test::test_main_static(&::os::args()[], tests, test::Options::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
static tests : &'static [test::TestDescAndFn] = &[
|
static tests : &'static [test::TestDescAndFn] = &[
|
||||||
|
@ -478,7 +478,7 @@ fn mk_main(cx: &mut TestCtxt) -> P<ast::Item> {
|
||||||
// pub fn main() {
|
// pub fn main() {
|
||||||
// #![main]
|
// #![main]
|
||||||
// use std::slice::AsSlice;
|
// use std::slice::AsSlice;
|
||||||
// test::test_main_static(::std::os::args().as_slice(), TESTS);
|
// test::test_main_static(::std::os::args().as_slice(), TESTS, test::Options::new());
|
||||||
// }
|
// }
|
||||||
|
|
||||||
let sp = ignored_span(cx, DUMMY_SP);
|
let sp = ignored_span(cx, DUMMY_SP);
|
||||||
|
|
|
@ -76,7 +76,7 @@ pub mod test {
|
||||||
pub use {Bencher, TestName, TestResult, TestDesc, TestDescAndFn, TestOpts, TrFailed,
|
pub use {Bencher, TestName, TestResult, TestDesc, TestDescAndFn, TestOpts, TrFailed,
|
||||||
TrFailedMsg, TrIgnored, TrOk, Metric, MetricMap, StaticTestFn, StaticTestName,
|
TrFailedMsg, TrIgnored, TrOk, Metric, MetricMap, StaticTestFn, StaticTestName,
|
||||||
DynTestName, DynTestFn, run_test, test_main, test_main_static, filter_tests,
|
DynTestName, DynTestFn, run_test, test_main, test_main_static, filter_tests,
|
||||||
parse_opts, StaticBenchFn, ShouldPanic};
|
parse_opts, StaticBenchFn, ShouldPanic, Options};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod stats;
|
pub mod stats;
|
||||||
|
@ -252,14 +252,34 @@ impl Clone for MetricMap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// In case we want to add other options as well, just add them in this struct.
|
||||||
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
pub struct Options {
|
||||||
|
display_output: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Options {
|
||||||
|
pub fn new() -> Options {
|
||||||
|
Options {
|
||||||
|
display_output: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn display_output(mut self, display_output: bool) -> Options {
|
||||||
|
self.display_output = display_output;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// The default console test runner. It accepts the command line
|
// The default console test runner. It accepts the command line
|
||||||
// arguments and a vector of test_descs.
|
// arguments and a vector of test_descs.
|
||||||
pub fn test_main(args: &[String], tests: Vec<TestDescAndFn>) {
|
pub fn test_main(args: &[String], tests: Vec<TestDescAndFn>, options: Options) {
|
||||||
let opts = match parse_opts(args) {
|
let mut opts = match parse_opts(args) {
|
||||||
Some(Ok(o)) => o,
|
Some(Ok(o)) => o,
|
||||||
Some(Err(msg)) => panic!("{:?}", msg),
|
Some(Err(msg)) => panic!("{:?}", msg),
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
|
opts.options = options;
|
||||||
if opts.list {
|
if opts.list {
|
||||||
if let Err(e) = list_tests_console(&opts, tests) {
|
if let Err(e) = list_tests_console(&opts, tests) {
|
||||||
panic!("io error when listing tests: {:?}", e);
|
panic!("io error when listing tests: {:?}", e);
|
||||||
|
@ -301,7 +321,7 @@ pub fn test_main_static(tests: &[TestDescAndFn]) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
test_main(&args, owned_tests)
|
test_main(&args, owned_tests, Options::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
@ -325,7 +345,7 @@ pub struct TestOpts {
|
||||||
pub quiet: bool,
|
pub quiet: bool,
|
||||||
pub test_threads: Option<usize>,
|
pub test_threads: Option<usize>,
|
||||||
pub skip: Vec<String>,
|
pub skip: Vec<String>,
|
||||||
pub display_stdout: bool,
|
pub options: Options,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TestOpts {
|
impl TestOpts {
|
||||||
|
@ -344,7 +364,7 @@ impl TestOpts {
|
||||||
quiet: false,
|
quiet: false,
|
||||||
test_threads: None,
|
test_threads: None,
|
||||||
skip: vec![],
|
skip: vec![],
|
||||||
display_stdout: false,
|
options: Options::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -372,8 +392,7 @@ fn optgroups() -> Vec<getopts::OptGroup> {
|
||||||
getopts::optopt("", "color", "Configure coloring of output:
|
getopts::optopt("", "color", "Configure coloring of output:
|
||||||
auto = colorize if stdout is a tty and tests are run on serially (default);
|
auto = colorize if stdout is a tty and tests are run on serially (default);
|
||||||
always = always colorize output;
|
always = always colorize output;
|
||||||
never = never colorize output;", "auto|always|never"),
|
never = never colorize output;", "auto|always|never")]
|
||||||
getopts::optflag("", "display-stdout", "to print stdout even if the test succeeds")]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(binary: &str) {
|
fn usage(binary: &str) {
|
||||||
|
@ -485,7 +504,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
|
||||||
quiet: quiet,
|
quiet: quiet,
|
||||||
test_threads: test_threads,
|
test_threads: test_threads,
|
||||||
skip: matches.opt_strs("skip"),
|
skip: matches.opt_strs("skip"),
|
||||||
display_stdout: matches.opt_present("display-stdout"),
|
options: Options::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
Some(Ok(test_opts))
|
Some(Ok(test_opts))
|
||||||
|
@ -528,7 +547,7 @@ struct ConsoleTestState<T> {
|
||||||
failures: Vec<(TestDesc, Vec<u8>)>,
|
failures: Vec<(TestDesc, Vec<u8>)>,
|
||||||
not_failures: Vec<(TestDesc, Vec<u8>)>,
|
not_failures: Vec<(TestDesc, Vec<u8>)>,
|
||||||
max_name_len: usize, // number of columns to fill when aligning names
|
max_name_len: usize, // number of columns to fill when aligning names
|
||||||
display_stdout: bool,
|
options: Options,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Write> ConsoleTestState<T> {
|
impl<T: Write> ConsoleTestState<T> {
|
||||||
|
@ -556,7 +575,7 @@ impl<T: Write> ConsoleTestState<T> {
|
||||||
failures: Vec::new(),
|
failures: Vec::new(),
|
||||||
not_failures: Vec::new(),
|
not_failures: Vec::new(),
|
||||||
max_name_len: 0,
|
max_name_len: 0,
|
||||||
display_stdout: opts.display_stdout,
|
options: opts.options,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -741,7 +760,7 @@ impl<T: Write> ConsoleTestState<T> {
|
||||||
pub fn write_run_finish(&mut self) -> io::Result<bool> {
|
pub fn write_run_finish(&mut self) -> io::Result<bool> {
|
||||||
assert!(self.passed + self.failed + self.ignored + self.measured == self.total);
|
assert!(self.passed + self.failed + self.ignored + self.measured == self.total);
|
||||||
|
|
||||||
if self.display_stdout {
|
if self.options.display_output {
|
||||||
self.write_outputs()?;
|
self.write_outputs()?;
|
||||||
}
|
}
|
||||||
let success = self.failed == 0;
|
let success = self.failed == 0;
|
||||||
|
@ -942,7 +961,7 @@ fn should_sort_failures_before_printing_them() {
|
||||||
max_name_len: 10,
|
max_name_len: 10,
|
||||||
metrics: MetricMap::new(),
|
metrics: MetricMap::new(),
|
||||||
failures: vec![(test_b, Vec::new()), (test_a, Vec::new())],
|
failures: vec![(test_b, Vec::new()), (test_a, Vec::new())],
|
||||||
display_stdout: false,
|
options: Options::new(),
|
||||||
not_failures: Vec::new(),
|
not_failures: Vec::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -336,7 +336,7 @@ pub fn test_opts(config: &Config) -> test::TestOpts {
|
||||||
test_threads: None,
|
test_threads: None,
|
||||||
skip: vec![],
|
skip: vec![],
|
||||||
list: false,
|
list: false,
|
||||||
display_stdout: false,
|
options: test::Options::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue