Skip to content

Commit 1add949

Browse files
author
Paul Emmerich
committed
libtest: add --show-output option
this new flag enables printing the captured stdout of successful tests utilizing the already existing display_output test runner option
1 parent 78ca1bd commit 1add949

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

src/librustdoc/markdown.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,6 @@ pub fn test(mut options: Options, diag: &errors::Handler) -> i32 {
154154

155155
options.test_args.insert(0, "rustdoctest".to_string());
156156
testing::test_main(&options.test_args, collector.tests,
157-
testing::Options::new().display_output(options.display_warnings));
157+
Some(testing::Options::new().display_output(options.display_warnings)));
158158
0
159159
}

src/librustdoc/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ pub fn run(options: Options) -> i32 {
120120
testing::test_main(
121121
&test_args,
122122
tests,
123-
testing::Options::new().display_output(display_warnings)
123+
Some(testing::Options::new().display_output(display_warnings))
124124
);
125125

126126
0

src/libtest/lib.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ impl Options {
272272

273273
// The default console test runner. It accepts the command line
274274
// arguments and a vector of test_descs.
275-
pub fn test_main(args: &[String], tests: Vec<TestDescAndFn>, options: Options) {
275+
pub fn test_main(args: &[String], tests: Vec<TestDescAndFn>, options: Option<Options>) {
276276
let mut opts = match parse_opts(args) {
277277
Some(Ok(o)) => o,
278278
Some(Err(msg)) => {
@@ -281,8 +281,9 @@ pub fn test_main(args: &[String], tests: Vec<TestDescAndFn>, options: Options) {
281281
}
282282
None => return,
283283
};
284-
285-
opts.options = options;
284+
if let Some(options) = options {
285+
opts.options = options;
286+
}
286287
if opts.list {
287288
if let Err(e) = list_tests_console(&opts, tests) {
288289
eprintln!("error: io error when listing tests: {:?}", e);
@@ -323,7 +324,7 @@ pub fn test_main_static(tests: &[&TestDescAndFn]) {
323324
_ => panic!("non-static tests passed to test::test_main_static"),
324325
})
325326
.collect();
326-
test_main(&args, owned_tests, Options::new())
327+
test_main(&args, owned_tests, None)
327328
}
328329

329330
/// Invoked when unit tests terminate. Should panic if the unit
@@ -468,6 +469,11 @@ fn optgroups() -> getopts::Options {
468469
json = Output a json document",
469470
"pretty|terse|json",
470471
)
472+
.optflag(
473+
"",
474+
"show-output",
475+
"Show captured stdout of successful tests"
476+
)
471477
.optopt(
472478
"Z",
473479
"",
@@ -667,7 +673,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
667673
format,
668674
test_threads,
669675
skip: matches.opt_strs("skip"),
670-
options: Options::new(),
676+
options: Options::new().display_output(matches.opt_present("show-output")),
671677
};
672678

673679
Some(Ok(test_opts))

src/libtest/tests.rs

+11
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,17 @@ fn parse_ignored_flag() {
160160
assert_eq!(opts.run_ignored, RunIgnored::Only);
161161
}
162162

163+
#[test]
164+
fn parse_show_output_flag() {
165+
let args = vec![
166+
"progname".to_string(),
167+
"filter".to_string(),
168+
"--show-output".to_string(),
169+
];
170+
let opts = parse_opts(&args).unwrap().unwrap();
171+
assert!(opts.options.display_output);
172+
}
173+
163174
#[test]
164175
fn parse_include_ignored_flag() {
165176
let args = vec![

0 commit comments

Comments
 (0)