Skip to content

Commit 77af67a

Browse files
committed
Add #[no_coverage] to the test harness's fn main
1 parent 9ecda8d commit 77af67a

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

compiler/rustc_builtin_macros/src/test_harness.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ fn generate_test_harness(
232232
let expn_id = ext_cx.resolver.expansion_for_ast_pass(
233233
DUMMY_SP,
234234
AstPass::TestHarness,
235-
&[sym::test, sym::rustc_attrs],
235+
&[sym::test, sym::rustc_attrs, sym::no_coverage],
236236
None,
237237
);
238238
let def_site = DUMMY_SP.with_def_site_ctxt(expn_id.to_expn_id());
@@ -313,6 +313,8 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
313313

314314
// #[rustc_main]
315315
let main_attr = ecx.attr_word(sym::rustc_main, sp);
316+
// #[no_coverage]
317+
let no_coverage_attr = ecx.attr_word(sym::no_coverage, sp);
316318

317319
// pub fn main() { ... }
318320
let main_ret_ty = ecx.ty(sp, ast::TyKind::Tup(ThinVec::new()));
@@ -342,7 +344,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
342344

343345
let main = P(ast::Item {
344346
ident: main_id,
345-
attrs: thin_vec![main_attr],
347+
attrs: thin_vec![main_attr, no_coverage_attr],
346348
id: ast::DUMMY_NODE_ID,
347349
kind: main,
348350
vis: ast::Visibility { span: sp, kind: ast::VisibilityKind::Public, tokens: None },

tests/pretty/tests-are-sorted.pp

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
};
8080
fn a_test() {}
8181
#[rustc_main]
82+
#[no_coverage]
8283
pub fn main() -> () {
8384
extern crate test;
8485
test::test_main_static(&[&a_test, &m_test, &z_test])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
1| |// Verify that the entry point injected by the test harness doesn't cause
2+
2| |// weird artifacts in the coverage report (e.g. issue #10749).
3+
3| |
4+
4| |// compile-flags: --test
5+
5| |
6+
6| |#[allow(dead_code)]
7+
7| 0|fn unused() {}
8+
8| |
9+
9| 1|#[test]
10+
10| 1|fn my_test() {}
11+
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Verify that the entry point injected by the test harness doesn't cause
2+
// weird artifacts in the coverage report (e.g. issue #10749).
3+
4+
// compile-flags: --test
5+
6+
#[allow(dead_code)]
7+
fn unused() {}
8+
9+
#[test]
10+
fn my_test() {}

0 commit comments

Comments
 (0)