Skip to content

Commit 347ed00

Browse files
committed
proof of concept add test type on prints
1 parent 89ebad5 commit 347ed00

32 files changed

+187
-45
lines changed

compiler/rustc_builtin_macros/src/test.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@ pub fn expand_test_or_bench(
254254
"allow_fail",
255255
cx.expr_bool(sp, should_fail(&cx.sess, &item)),
256256
),
257+
// compile_fail: true | false
258+
field("compile_fail", cx.expr_bool(sp, false)),
259+
// no_run: true | false
260+
field("no_run", cx.expr_bool(sp, false)),
257261
// should_panic: ...
258262
field(
259263
"should_panic",

library/test/src/formatters/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl<T: Write> PrettyFormatter<T> {
169169

170170
fn write_test_name(&mut self, desc: &TestDesc) -> io::Result<()> {
171171
let name = desc.padded_name(self.max_name_len, desc.name.padding());
172-
self.write_plain(&format!("test {} ... ", name))?;
172+
self.write_plain(&format!("test {} {} ... ", name, desc.test_mode_string()))?;
173173

174174
Ok(())
175175
}

library/test/src/formatters/terse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl<T: Write> TerseFormatter<T> {
158158

159159
fn write_test_name(&mut self, desc: &TestDesc) -> io::Result<()> {
160160
let name = desc.padded_name(self.max_name_len, desc.name.padding());
161-
self.write_plain(&format!("test {} ... ", name))?;
161+
self.write_plain(&format!("test {} {} ... ", name, desc.test_mode_string()))?;
162162

163163
Ok(())
164164
}

library/test/src/tests.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ fn one_ignored_one_unignored_test() -> Vec<TestDescAndFn> {
6161
ignore: true,
6262
should_panic: ShouldPanic::No,
6363
allow_fail: false,
64+
compile_fail: false,
65+
no_run: false,
6466
test_type: TestType::Unknown,
6567
},
6668
testfn: DynTestFn(Box::new(move || {})),
@@ -71,6 +73,8 @@ fn one_ignored_one_unignored_test() -> Vec<TestDescAndFn> {
7173
ignore: false,
7274
should_panic: ShouldPanic::No,
7375
allow_fail: false,
76+
compile_fail: false,
77+
no_run: false,
7478
test_type: TestType::Unknown,
7579
},
7680
testfn: DynTestFn(Box::new(move || {})),
@@ -89,6 +93,8 @@ pub fn do_not_run_ignored_tests() {
8993
ignore: true,
9094
should_panic: ShouldPanic::No,
9195
allow_fail: false,
96+
compile_fail: false,
97+
no_run: false,
9298
test_type: TestType::Unknown,
9399
},
94100
testfn: DynTestFn(Box::new(f)),
@@ -108,6 +114,8 @@ pub fn ignored_tests_result_in_ignored() {
108114
ignore: true,
109115
should_panic: ShouldPanic::No,
110116
allow_fail: false,
117+
compile_fail: false,
118+
no_run: false,
111119
test_type: TestType::Unknown,
112120
},
113121
testfn: DynTestFn(Box::new(f)),
@@ -131,6 +139,8 @@ fn test_should_panic() {
131139
ignore: false,
132140
should_panic: ShouldPanic::Yes,
133141
allow_fail: false,
142+
compile_fail: false,
143+
no_run: false,
134144
test_type: TestType::Unknown,
135145
},
136146
testfn: DynTestFn(Box::new(f)),
@@ -154,6 +164,8 @@ fn test_should_panic_good_message() {
154164
ignore: false,
155165
should_panic: ShouldPanic::YesWithMessage("error message"),
156166
allow_fail: false,
167+
compile_fail: false,
168+
no_run: false,
157169
test_type: TestType::Unknown,
158170
},
159171
testfn: DynTestFn(Box::new(f)),
@@ -182,6 +194,8 @@ fn test_should_panic_bad_message() {
182194
ignore: false,
183195
should_panic: ShouldPanic::YesWithMessage(expected),
184196
allow_fail: false,
197+
compile_fail: false,
198+
no_run: false,
185199
test_type: TestType::Unknown,
186200
},
187201
testfn: DynTestFn(Box::new(f)),
@@ -214,6 +228,8 @@ fn test_should_panic_non_string_message_type() {
214228
ignore: false,
215229
should_panic: ShouldPanic::YesWithMessage(expected),
216230
allow_fail: false,
231+
compile_fail: false,
232+
no_run: false,
217233
test_type: TestType::Unknown,
218234
},
219235
testfn: DynTestFn(Box::new(f)),
@@ -238,6 +254,8 @@ fn test_should_panic_but_succeeds() {
238254
ignore: false,
239255
should_panic,
240256
allow_fail: false,
257+
compile_fail: false,
258+
no_run: false,
241259
test_type: TestType::Unknown,
242260
},
243261
testfn: DynTestFn(Box::new(f)),
@@ -270,6 +288,8 @@ fn report_time_test_template(report_time: bool) -> Option<TestExecTime> {
270288
ignore: false,
271289
should_panic: ShouldPanic::No,
272290
allow_fail: false,
291+
compile_fail: false,
292+
no_run: false,
273293
test_type: TestType::Unknown,
274294
},
275295
testfn: DynTestFn(Box::new(f)),
@@ -303,6 +323,8 @@ fn time_test_failure_template(test_type: TestType) -> TestResult {
303323
ignore: false,
304324
should_panic: ShouldPanic::No,
305325
allow_fail: false,
326+
compile_fail: false,
327+
no_run: false,
306328
test_type,
307329
},
308330
testfn: DynTestFn(Box::new(f)),
@@ -340,6 +362,8 @@ fn typed_test_desc(test_type: TestType) -> TestDesc {
340362
ignore: false,
341363
should_panic: ShouldPanic::No,
342364
allow_fail: false,
365+
compile_fail: false,
366+
no_run: false,
343367
test_type,
344368
}
345369
}
@@ -451,6 +475,8 @@ pub fn exclude_should_panic_option() {
451475
ignore: false,
452476
should_panic: ShouldPanic::Yes,
453477
allow_fail: false,
478+
compile_fail: false,
479+
no_run: false,
454480
test_type: TestType::Unknown,
455481
},
456482
testfn: DynTestFn(Box::new(move || {})),
@@ -473,6 +499,8 @@ pub fn exact_filter_match() {
473499
ignore: false,
474500
should_panic: ShouldPanic::No,
475501
allow_fail: false,
502+
compile_fail: false,
503+
no_run: false,
476504
test_type: TestType::Unknown,
477505
},
478506
testfn: DynTestFn(Box::new(move || {})),
@@ -565,6 +593,8 @@ pub fn sort_tests() {
565593
ignore: false,
566594
should_panic: ShouldPanic::No,
567595
allow_fail: false,
596+
compile_fail: false,
597+
no_run: false,
568598
test_type: TestType::Unknown,
569599
},
570600
testfn: DynTestFn(Box::new(testfn)),
@@ -642,6 +672,8 @@ pub fn test_bench_no_iter() {
642672
ignore: false,
643673
should_panic: ShouldPanic::No,
644674
allow_fail: false,
675+
compile_fail: false,
676+
no_run: false,
645677
test_type: TestType::Unknown,
646678
};
647679

@@ -662,6 +694,8 @@ pub fn test_bench_iter() {
662694
ignore: false,
663695
should_panic: ShouldPanic::No,
664696
allow_fail: false,
697+
compile_fail: false,
698+
no_run: false,
665699
test_type: TestType::Unknown,
666700
};
667701

@@ -676,6 +710,8 @@ fn should_sort_failures_before_printing_them() {
676710
ignore: false,
677711
should_panic: ShouldPanic::No,
678712
allow_fail: false,
713+
compile_fail: false,
714+
no_run: false,
679715
test_type: TestType::Unknown,
680716
};
681717

@@ -684,6 +720,8 @@ fn should_sort_failures_before_printing_them() {
684720
ignore: false,
685721
should_panic: ShouldPanic::No,
686722
allow_fail: false,
723+
compile_fail: false,
724+
no_run: false,
687725
test_type: TestType::Unknown,
688726
};
689727

library/test/src/types.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ pub struct TestDesc {
124124
pub ignore: bool,
125125
pub should_panic: options::ShouldPanic,
126126
pub allow_fail: bool,
127+
pub compile_fail: bool,
128+
pub no_run: bool,
127129
pub test_type: TestType,
128130
}
129131

@@ -140,6 +142,28 @@ impl TestDesc {
140142
}
141143
}
142144
}
145+
146+
pub fn test_mode_string(&self) -> String {
147+
if self.ignore {
148+
return "ignore".to_string();
149+
}
150+
match self.should_panic {
151+
options::ShouldPanic::Yes | options::ShouldPanic::YesWithMessage(_) => {
152+
return "should panic".to_string();
153+
}
154+
_ => {}
155+
}
156+
if self.allow_fail {
157+
return "allow fail".to_string();
158+
}
159+
if self.compile_fail {
160+
return "compile fail".to_string();
161+
}
162+
if self.no_run {
163+
return "compile".to_string();
164+
}
165+
"run".to_string()
166+
}
143167
}
144168

145169
#[derive(Debug)]

src/librustdoc/doctest.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,7 @@ impl Tester for Collector {
879879
let target = self.options.target.clone();
880880
let target_str = target.to_string();
881881
let unused_externs = self.unused_extern_reports.clone();
882+
let no_run = config.no_run || options.no_run;
882883
if !config.compile_fail {
883884
self.compiling_test_count.fetch_add(1, Ordering::SeqCst);
884885
}
@@ -934,13 +935,14 @@ impl Tester for Collector {
934935
// compiler failures are test failures
935936
should_panic: testing::ShouldPanic::No,
936937
allow_fail: config.allow_fail,
938+
compile_fail: config.compile_fail,
939+
no_run,
937940
test_type: testing::TestType::DocTest,
938941
},
939942
testfn: testing::DynTestFn(box move || {
940943
let report_unused_externs = |uext| {
941944
unused_externs.lock().unwrap().push(uext);
942945
};
943-
let no_run = config.no_run || options.no_run;
944946
let res = run_test(
945947
&test,
946948
&cratename,

src/test/rustdoc-ui/cfg-test.stdout

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
running 2 tests
3-
test $DIR/cfg-test.rs - Bar (line 27) ... ok
4-
test $DIR/cfg-test.rs - Foo (line 19) ... ok
3+
test $DIR/cfg-test.rs - Bar (line 27) run ... ok
4+
test $DIR/cfg-test.rs - Foo (line 19) run ... ok
55

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
running 1 test
3-
test $DIR/doc-test-doctest-feature.rs - Foo (line 9) ... ok
3+
test $DIR/doc-test-doctest-feature.rs - Foo (line 9) run ... ok
44

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
running 1 test
3-
test $DIR/doc-test-rustdoc-feature.rs - Foo (line 10) ... ok
3+
test $DIR/doc-test-rustdoc-feature.rs - Foo (line 10) run ... ok
44

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

22
running 3 tests
3-
test $DIR/doctest-output.rs - (line 8) ... ok
4-
test $DIR/doctest-output.rs - ExpandedStruct (line 24) ... ok
5-
test $DIR/doctest-output.rs - foo::bar (line 18) ... ok
3+
test $DIR/doctest-output.rs - (line 8) run ... ok
4+
test $DIR/doctest-output.rs - ExpandedStruct (line 24) run ... ok
5+
test $DIR/doctest-output.rs - foo::bar (line 18) run ... ok
66

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

src/test/rustdoc-ui/failed-doctest-compile-fail.stdout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

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

55
failures:
66

src/test/rustdoc-ui/failed-doctest-missing-codes.stdout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

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

55
failures:
66

src/test/rustdoc-ui/failed-doctest-output.stdout

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
running 2 tests
3-
test $DIR/failed-doctest-output.rs - OtherStruct (line 22) ... FAILED
4-
test $DIR/failed-doctest-output.rs - SomeStruct (line 12) ... FAILED
3+
test $DIR/failed-doctest-output.rs - OtherStruct (line 22) run ... FAILED
4+
test $DIR/failed-doctest-output.rs - SomeStruct (line 12) run ... FAILED
55

66
failures:
77

src/test/rustdoc-ui/failed-doctest-should-panic.stdout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
running 1 test
3-
test $DIR/failed-doctest-should-panic.rs - Foo (line 9) ... FAILED
3+
test $DIR/failed-doctest-should-panic.rs - Foo (line 9) run ... FAILED
44

55
failures:
66

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

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

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

src/test/rustdoc-ui/issue-81662-shortness.stdout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
running 1 test
3-
test $DIR/issue-81662-shortness.rs - foo (line 6) ... FAILED
3+
test $DIR/issue-81662-shortness.rs - foo (line 6) run ... FAILED
44

55
failures:
66

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

22
running 7 tests
3-
test $DIR/no-run-flag.rs - f (line 11) ... ok
4-
test $DIR/no-run-flag.rs - f (line 14) ... ignored
5-
test $DIR/no-run-flag.rs - f (line 17) ... ok
6-
test $DIR/no-run-flag.rs - f (line 23) ... ok
7-
test $DIR/no-run-flag.rs - f (line 28) ... ok
8-
test $DIR/no-run-flag.rs - f (line 32) ... ok
9-
test $DIR/no-run-flag.rs - f (line 8) ... ok
3+
test $DIR/no-run-flag.rs - f (line 11) compile ... ok
4+
test $DIR/no-run-flag.rs - f (line 14) ignore ... ignored
5+
test $DIR/no-run-flag.rs - f (line 17) compile ... ok
6+
test $DIR/no-run-flag.rs - f (line 23) compile fail ... ok
7+
test $DIR/no-run-flag.rs - f (line 28) compile ... ok
8+
test $DIR/no-run-flag.rs - f (line 32) compile ... ok
9+
test $DIR/no-run-flag.rs - f (line 8) compile ... ok
1010

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
running 1 test
3-
test $DIR/run-directory.rs - foo (line 10) ... ok
3+
test $DIR/run-directory.rs - foo (line 10) run ... ok
44

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
running 1 test
3-
test $DIR/run-directory.rs - foo (line 19) ... ok
3+
test $DIR/run-directory.rs - foo (line 19) run ... ok
44

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
running 1 test
3-
test $DIR/test-no_std.rs - f (line 10) ... ok
3+
test $DIR/test-no_std.rs - f (line 10) run ... ok
44

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

0 commit comments

Comments
 (0)