Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show test type during prints #84863

Merged
merged 6 commits into from
Jun 6, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/rustc_builtin_macros/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ pub fn expand_test_or_bench(
"allow_fail",
cx.expr_bool(sp, should_fail(&cx.sess, &item)),
),
// compile_fail: true | false
field("compile_fail", cx.expr_bool(sp, false)),
// no_run: true | false
field("no_run", cx.expr_bool(sp, false)),
// should_panic: ...
field(
"should_panic",
Expand Down
7 changes: 6 additions & 1 deletion library/test/src/formatters/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@ impl<T: Write> PrettyFormatter<T> {

fn write_test_name(&mut self, desc: &TestDesc) -> io::Result<()> {
let name = desc.padded_name(self.max_name_len, desc.name.padding());
self.write_plain(&format!("test {} ... ", name))?;
let test_mode = desc.test_mode();
if test_mode == "" {
m-ou-se marked this conversation as resolved.
Show resolved Hide resolved
self.write_plain(&format!("test {} ... ", name))?;
} else {
self.write_plain(&format!("test {} - {} ... ", name, test_mode))?;
}

Ok(())
}
Expand Down
7 changes: 6 additions & 1 deletion library/test/src/formatters/terse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,12 @@ impl<T: Write> TerseFormatter<T> {

fn write_test_name(&mut self, desc: &TestDesc) -> io::Result<()> {
let name = desc.padded_name(self.max_name_len, desc.name.padding());
self.write_plain(&format!("test {} ... ", name))?;
let test_mode = desc.test_mode();
if test_mode == "" {
self.write_plain(&format!("test {} ... ", name))?;
} else {
self.write_plain(&format!("test {} - {} ... ", name, test_mode))?;
}

Ok(())
}
Expand Down
76 changes: 76 additions & 0 deletions library/test/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ fn one_ignored_one_unignored_test() -> Vec<TestDescAndFn> {
ignore: true,
should_panic: ShouldPanic::No,
allow_fail: false,
#[cfg(not(bootstrap))]
compile_fail: false,
#[cfg(not(bootstrap))]
no_run: false,
test_type: TestType::Unknown,
},
testfn: DynTestFn(Box::new(move || {})),
Expand All @@ -71,6 +75,10 @@ fn one_ignored_one_unignored_test() -> Vec<TestDescAndFn> {
ignore: false,
should_panic: ShouldPanic::No,
allow_fail: false,
#[cfg(not(bootstrap))]
compile_fail: false,
#[cfg(not(bootstrap))]
no_run: false,
test_type: TestType::Unknown,
},
testfn: DynTestFn(Box::new(move || {})),
Expand All @@ -89,6 +97,10 @@ pub fn do_not_run_ignored_tests() {
ignore: true,
should_panic: ShouldPanic::No,
allow_fail: false,
#[cfg(not(bootstrap))]
compile_fail: false,
#[cfg(not(bootstrap))]
no_run: false,
test_type: TestType::Unknown,
},
testfn: DynTestFn(Box::new(f)),
Expand All @@ -108,6 +120,10 @@ pub fn ignored_tests_result_in_ignored() {
ignore: true,
should_panic: ShouldPanic::No,
allow_fail: false,
#[cfg(not(bootstrap))]
compile_fail: false,
#[cfg(not(bootstrap))]
no_run: false,
test_type: TestType::Unknown,
},
testfn: DynTestFn(Box::new(f)),
Expand All @@ -131,6 +147,10 @@ fn test_should_panic() {
ignore: false,
should_panic: ShouldPanic::Yes,
allow_fail: false,
#[cfg(not(bootstrap))]
compile_fail: false,
#[cfg(not(bootstrap))]
no_run: false,
test_type: TestType::Unknown,
},
testfn: DynTestFn(Box::new(f)),
Expand All @@ -154,6 +174,10 @@ fn test_should_panic_good_message() {
ignore: false,
should_panic: ShouldPanic::YesWithMessage("error message"),
allow_fail: false,
#[cfg(not(bootstrap))]
compile_fail: false,
#[cfg(not(bootstrap))]
no_run: false,
test_type: TestType::Unknown,
},
testfn: DynTestFn(Box::new(f)),
Expand Down Expand Up @@ -182,6 +206,10 @@ fn test_should_panic_bad_message() {
ignore: false,
should_panic: ShouldPanic::YesWithMessage(expected),
allow_fail: false,
#[cfg(not(bootstrap))]
compile_fail: false,
#[cfg(not(bootstrap))]
no_run: false,
test_type: TestType::Unknown,
},
testfn: DynTestFn(Box::new(f)),
Expand Down Expand Up @@ -214,6 +242,10 @@ fn test_should_panic_non_string_message_type() {
ignore: false,
should_panic: ShouldPanic::YesWithMessage(expected),
allow_fail: false,
#[cfg(not(bootstrap))]
compile_fail: false,
#[cfg(not(bootstrap))]
no_run: false,
test_type: TestType::Unknown,
},
testfn: DynTestFn(Box::new(f)),
Expand All @@ -238,6 +270,10 @@ fn test_should_panic_but_succeeds() {
ignore: false,
should_panic,
allow_fail: false,
#[cfg(not(bootstrap))]
compile_fail: false,
#[cfg(not(bootstrap))]
no_run: false,
test_type: TestType::Unknown,
},
testfn: DynTestFn(Box::new(f)),
Expand Down Expand Up @@ -270,6 +306,10 @@ fn report_time_test_template(report_time: bool) -> Option<TestExecTime> {
ignore: false,
should_panic: ShouldPanic::No,
allow_fail: false,
#[cfg(not(bootstrap))]
compile_fail: false,
#[cfg(not(bootstrap))]
no_run: false,
test_type: TestType::Unknown,
},
testfn: DynTestFn(Box::new(f)),
Expand Down Expand Up @@ -303,6 +343,10 @@ fn time_test_failure_template(test_type: TestType) -> TestResult {
ignore: false,
should_panic: ShouldPanic::No,
allow_fail: false,
#[cfg(not(bootstrap))]
compile_fail: false,
#[cfg(not(bootstrap))]
no_run: false,
test_type,
},
testfn: DynTestFn(Box::new(f)),
Expand Down Expand Up @@ -340,6 +384,10 @@ fn typed_test_desc(test_type: TestType) -> TestDesc {
ignore: false,
should_panic: ShouldPanic::No,
allow_fail: false,
#[cfg(not(bootstrap))]
compile_fail: false,
#[cfg(not(bootstrap))]
no_run: false,
test_type,
}
}
Expand Down Expand Up @@ -451,6 +499,10 @@ pub fn exclude_should_panic_option() {
ignore: false,
should_panic: ShouldPanic::Yes,
allow_fail: false,
#[cfg(not(bootstrap))]
compile_fail: false,
#[cfg(not(bootstrap))]
no_run: false,
test_type: TestType::Unknown,
},
testfn: DynTestFn(Box::new(move || {})),
Expand All @@ -473,6 +525,10 @@ pub fn exact_filter_match() {
ignore: false,
should_panic: ShouldPanic::No,
allow_fail: false,
#[cfg(not(bootstrap))]
compile_fail: false,
#[cfg(not(bootstrap))]
no_run: false,
test_type: TestType::Unknown,
},
testfn: DynTestFn(Box::new(move || {})),
Expand Down Expand Up @@ -565,6 +621,10 @@ pub fn sort_tests() {
ignore: false,
should_panic: ShouldPanic::No,
allow_fail: false,
#[cfg(not(bootstrap))]
compile_fail: false,
#[cfg(not(bootstrap))]
no_run: false,
test_type: TestType::Unknown,
},
testfn: DynTestFn(Box::new(testfn)),
Expand Down Expand Up @@ -642,6 +702,10 @@ pub fn test_bench_no_iter() {
ignore: false,
should_panic: ShouldPanic::No,
allow_fail: false,
#[cfg(not(bootstrap))]
compile_fail: false,
#[cfg(not(bootstrap))]
no_run: false,
test_type: TestType::Unknown,
};

Expand All @@ -662,6 +726,10 @@ pub fn test_bench_iter() {
ignore: false,
should_panic: ShouldPanic::No,
allow_fail: false,
#[cfg(not(bootstrap))]
compile_fail: false,
#[cfg(not(bootstrap))]
no_run: false,
test_type: TestType::Unknown,
};

Expand All @@ -676,6 +744,10 @@ fn should_sort_failures_before_printing_them() {
ignore: false,
should_panic: ShouldPanic::No,
allow_fail: false,
#[cfg(not(bootstrap))]
compile_fail: false,
#[cfg(not(bootstrap))]
no_run: false,
test_type: TestType::Unknown,
};

Expand All @@ -684,6 +756,10 @@ fn should_sort_failures_before_printing_them() {
ignore: false,
should_panic: ShouldPanic::No,
allow_fail: false,
#[cfg(not(bootstrap))]
compile_fail: false,
#[cfg(not(bootstrap))]
no_run: false,
test_type: TestType::Unknown,
};

Expand Down
32 changes: 32 additions & 0 deletions library/test/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ pub struct TestDesc {
pub ignore: bool,
pub should_panic: options::ShouldPanic,
pub allow_fail: bool,
#[cfg(not(bootstrap))]
pub compile_fail: bool,
#[cfg(not(bootstrap))]
pub no_run: bool,
pub test_type: TestType,
}

Expand All @@ -140,6 +144,34 @@ impl TestDesc {
}
}
}

#[cfg(not(bootstrap))]
pub fn test_mode(&self) -> &'static str {
if self.ignore {
return &"";
m-ou-se marked this conversation as resolved.
Show resolved Hide resolved
}
match self.should_panic {
options::ShouldPanic::Yes | options::ShouldPanic::YesWithMessage(_) => {
return &"should panic";
}
options::ShouldPanic::No => {}
}
if self.allow_fail {
return &"allow fail";
}
if self.compile_fail {
return &"compile fail";
}
if self.no_run {
return &"compile";
}
&""
}

#[cfg(bootstrap)]
pub fn test_mode(&self) -> &'static str {
&""
}
}

#[derive(Debug)]
Expand Down
6 changes: 5 additions & 1 deletion src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,7 @@ impl Tester for Collector {
let target = self.options.target.clone();
let target_str = target.to_string();
let unused_externs = self.unused_extern_reports.clone();
let no_run = config.no_run || options.no_run;
if !config.compile_fail {
self.compiling_test_count.fetch_add(1, Ordering::SeqCst);
}
Expand Down Expand Up @@ -934,13 +935,16 @@ impl Tester for Collector {
// compiler failures are test failures
should_panic: testing::ShouldPanic::No,
allow_fail: config.allow_fail,
#[cfg(not(bootstrap))]
compile_fail: config.compile_fail,
#[cfg(not(bootstrap))]
no_run,
test_type: testing::TestType::DocTest,
},
testfn: testing::DynTestFn(box move || {
let report_unused_externs = |uext| {
unused_externs.lock().unwrap().push(uext);
};
let no_run = config.no_run || options.no_run;
let res = run_test(
&test,
&cratename,
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-ui/failed-doctest-compile-fail.stdout
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

running 1 test
test $DIR/failed-doctest-compile-fail.rs - Foo (line 9) ... FAILED
test $DIR/failed-doctest-compile-fail.rs - Foo (line 9) - compile fail ... FAILED

failures:

Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-ui/failed-doctest-missing-codes.stdout
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

running 1 test
test $DIR/failed-doctest-missing-codes.rs - Foo (line 9) ... FAILED
test $DIR/failed-doctest-missing-codes.rs - Foo (line 9) - compile fail ... FAILED

failures:

Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-ui/issue-80992.stdout
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

running 1 test
test $DIR/issue-80992.rs - test (line 7) ... ok
test $DIR/issue-80992.rs - test (line 7) - compile fail ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

12 changes: 6 additions & 6 deletions src/test/rustdoc-ui/no-run-flag.stdout
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

running 7 tests
test $DIR/no-run-flag.rs - f (line 11) ... ok
test $DIR/no-run-flag.rs - f (line 11) - compile ... ok
test $DIR/no-run-flag.rs - f (line 14) ... ignored
test $DIR/no-run-flag.rs - f (line 17) ... ok
test $DIR/no-run-flag.rs - f (line 23) ... ok
test $DIR/no-run-flag.rs - f (line 28) ... ok
test $DIR/no-run-flag.rs - f (line 32) ... ok
test $DIR/no-run-flag.rs - f (line 8) ... ok
test $DIR/no-run-flag.rs - f (line 17) - compile ... ok
test $DIR/no-run-flag.rs - f (line 23) - compile fail ... ok
test $DIR/no-run-flag.rs - f (line 28) - compile ... ok
test $DIR/no-run-flag.rs - f (line 32) - compile ... ok
test $DIR/no-run-flag.rs - f (line 8) - compile ... ok

test result: ok. 6 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in $TIME

26 changes: 26 additions & 0 deletions src/test/rustdoc-ui/test-type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// compile-flags: --test --test-args=--test-threads=1
// check-pass
// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR"
// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"

/// ```
/// let a = true;
/// ```
/// ```should_panic
/// panic!()
/// ```
/// ```ignore (incomplete-code)
/// fn foo() {
/// ```
/// ```no_run
/// loop {
/// println!("Hello, world");
/// }
/// ```
/// fails to compile
/// ```compile_fail
/// let x = 5;
/// x += 2; // shouldn't compile!
/// ```

pub fn f() {}
Loading