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

Add #[no_coverage] to the test harness's fn main #111042

Merged
merged 1 commit into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions compiler/rustc_builtin_macros/src/test_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ fn generate_test_harness(
let expn_id = ext_cx.resolver.expansion_for_ast_pass(
DUMMY_SP,
AstPass::TestHarness,
&[sym::test, sym::rustc_attrs],
&[sym::test, sym::rustc_attrs, sym::no_coverage],
None,
);
let def_site = DUMMY_SP.with_def_site_ctxt(expn_id.to_expn_id());
Expand Down Expand Up @@ -313,6 +313,8 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {

// #[rustc_main]
let main_attr = ecx.attr_word(sym::rustc_main, sp);
// #[no_coverage]
let no_coverage_attr = ecx.attr_word(sym::no_coverage, sp);

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

let main = P(ast::Item {
ident: main_id,
attrs: thin_vec![main_attr],
attrs: thin_vec![main_attr, no_coverage_attr],
id: ast::DUMMY_NODE_ID,
kind: main,
vis: ast::Visibility { span: sp, kind: ast::VisibilityKind::Public, tokens: None },
Expand Down
1 change: 1 addition & 0 deletions tests/pretty/tests-are-sorted.pp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
};
fn a_test() {}
#[rustc_main]
#[no_coverage]
pub fn main() -> () {
extern crate test;
test::test_main_static(&[&a_test, &m_test, &z_test])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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| 0|fn unused() {}
8| |
9| 1|#[test]
10| 1|fn my_test() {}

10 changes: 10 additions & 0 deletions tests/run-make/coverage/test_harness.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Verify that the entry point injected by the test harness doesn't cause
// weird artifacts in the coverage report (e.g. issue #10749).

// compile-flags: --test

#[allow(dead_code)]
fn unused() {}

#[test]
fn my_test() {}