Skip to content

Commit

Permalink
coverage: Bless coverage attribute tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Zalathar committed Jun 20, 2024
1 parent 63013b3 commit 435eb30
Show file tree
Hide file tree
Showing 8 changed files with 419 additions and 299 deletions.
8 changes: 1 addition & 7 deletions tests/ui/coverage-attr/bad-syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@ fn multiple_inconsistent() {}
#[coverage] //~ ERROR expected `coverage(off)` or `coverage(on)`
fn bare_word() {}

// FIXME(#126658): This shows as multiple different errors, one of which suggests
// writing bare `#[coverage]`, which is not allowed.
#[coverage = true]
//~^ ERROR expected `coverage(off)` or `coverage(on)`
//~| ERROR malformed `coverage` attribute input
//~| HELP the following are the possible correct uses
//~| SUGGESTION #[coverage(on|off)]
#[coverage = true] //~ ERROR expected `coverage(off)` or `coverage(on)`
fn key_value() {}

#[coverage()] //~ ERROR expected `coverage(off)` or `coverage(on)`
Expand Down
33 changes: 10 additions & 23 deletions tests/ui/coverage-attr/bad-syntax.stderr
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
error: malformed `coverage` attribute input
--> $DIR/bad-syntax.rs:23:1
|
LL | #[coverage = true]
| ^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(on|off)]
|
LL | #[coverage]
|

error: expected identifier, found `,`
--> $DIR/bad-syntax.rs:52:12
--> $DIR/bad-syntax.rs:46:12
|
LL | #[coverage(,off)]
| ^
Expand Down Expand Up @@ -51,52 +38,52 @@ LL | #[coverage]
| ^^^^^^^^^^^

error: expected `coverage(off)` or `coverage(on)`
--> $DIR/bad-syntax.rs:23:1
--> $DIR/bad-syntax.rs:21:1
|
LL | #[coverage = true]
| ^^^^^^^^^^^^^^^^^^

error: expected `coverage(off)` or `coverage(on)`
--> $DIR/bad-syntax.rs:30:1
--> $DIR/bad-syntax.rs:24:1
|
LL | #[coverage()]
| ^^^^^^^^^^^^^

error: expected `coverage(off)` or `coverage(on)`
--> $DIR/bad-syntax.rs:33:1
--> $DIR/bad-syntax.rs:27:1
|
LL | #[coverage(off, off)]
| ^^^^^^^^^^^^^^^^^^^^^

error: expected `coverage(off)` or `coverage(on)`
--> $DIR/bad-syntax.rs:36:1
--> $DIR/bad-syntax.rs:30:1
|
LL | #[coverage(off, on)]
| ^^^^^^^^^^^^^^^^^^^^

error: expected `coverage(off)` or `coverage(on)`
--> $DIR/bad-syntax.rs:39:1
--> $DIR/bad-syntax.rs:33:1
|
LL | #[coverage(bogus)]
| ^^^^^^^^^^^^^^^^^^

error: expected `coverage(off)` or `coverage(on)`
--> $DIR/bad-syntax.rs:42:1
--> $DIR/bad-syntax.rs:36:1
|
LL | #[coverage(bogus, off)]
| ^^^^^^^^^^^^^^^^^^^^^^^

error: expected `coverage(off)` or `coverage(on)`
--> $DIR/bad-syntax.rs:45:1
--> $DIR/bad-syntax.rs:39:1
|
LL | #[coverage(off, bogus)]
| ^^^^^^^^^^^^^^^^^^^^^^^

error: expected `coverage(off)` or `coverage(on)`
--> $DIR/bad-syntax.rs:52:1
--> $DIR/bad-syntax.rs:46:1
|
LL | #[coverage(,off)]
| ^^^^^^^^^^^^^^^^^

error: aborting due to 13 previous errors
error: aborting due to 12 previous errors

49 changes: 27 additions & 22 deletions tests/ui/coverage-attr/name-value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,62 @@
// Demonstrates the diagnostics produced when using the syntax
// `#![coverage = "off"]`, which should not be allowed.

// FIXME(#126658): The error messages for using this syntax are inconsistent
// with the error message in other cases. They also sometimes appear together
// with other errors, and they suggest using the incorrect `#[coverage]` syntax.

#[coverage = "off"] //~ ERROR malformed `coverage` attribute input
#[coverage = "off"]
//~^ ERROR expected `coverage(off)` or `coverage(on)`
//~| ERROR attribute should be applied to a function definition or closure
mod my_mod {}

mod my_mod_inner {
#![coverage = "off"] //~ ERROR malformed `coverage` attribute input
#![coverage = "off"]
//~^ ERROR expected `coverage(off)` or `coverage(on)`
//~| ERROR attribute should be applied to a function definition or closure
}

#[coverage = "off"]
//~^ ERROR `#[coverage]` must be applied to coverable code
//~| ERROR malformed `coverage` attribute input
//~^ ERROR expected `coverage(off)` or `coverage(on)`
//~| ERROR attribute should be applied to a function definition or closure
struct MyStruct;

#[coverage = "off"] //~ ERROR malformed `coverage` attribute input
#[coverage = "off"]
//~^ ERROR expected `coverage(off)` or `coverage(on)`
//~| ERROR attribute should be applied to a function definition or closure
impl MyStruct {
#[coverage = "off"]
//~^ ERROR `#[coverage]` must be applied to coverable code
//~| ERROR malformed `coverage` attribute input
//~^ ERROR expected `coverage(off)` or `coverage(on)`
//~| ERROR attribute should be applied to a function definition or closure
const X: u32 = 7;
}

#[coverage = "off"] //~ ERROR malformed `coverage` attribute input
#[coverage = "off"]
//~^ ERROR expected `coverage(off)` or `coverage(on)`
//~| ERROR attribute should be applied to a function definition or closure
trait MyTrait {
#[coverage = "off"]
//~^ ERROR `#[coverage]` must be applied to coverable code
//~| ERROR malformed `coverage` attribute input
//~^ ERROR expected `coverage(off)` or `coverage(on)`
//~| ERROR attribute should be applied to a function definition or closure
const X: u32;

#[coverage = "off"]
//~^ ERROR `#[coverage]` must be applied to coverable code
//~| ERROR malformed `coverage` attribute input
//~^ ERROR expected `coverage(off)` or `coverage(on)`
//~| ERROR attribute should be applied to a function definition or closure
type T;
}

#[coverage = "off"] //~ ERROR malformed `coverage` attribute input
#[coverage = "off"]
//~^ ERROR expected `coverage(off)` or `coverage(on)`
//~| ERROR attribute should be applied to a function definition or closure
impl MyTrait for MyStruct {
#[coverage = "off"]
//~^ ERROR `#[coverage]` must be applied to coverable code
//~| ERROR malformed `coverage` attribute input
//~^ ERROR expected `coverage(off)` or `coverage(on)`
//~| ERROR attribute should be applied to a function definition or closure
const X: u32 = 8;

#[coverage = "off"]
//~^ ERROR `#[coverage]` must be applied to coverable code
//~| ERROR malformed `coverage` attribute input
//~^ ERROR expected `coverage(off)` or `coverage(on)`
//~| ERROR attribute should be applied to a function definition or closure
type T = ();
}

#[coverage = "off"]
//~^ ERROR expected `coverage(off)` or `coverage(on)`
//~| ERROR malformed `coverage` attribute input
fn main() {}
Loading

0 comments on commit 435eb30

Please sign in to comment.