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 656d6c9 commit 1d085bf
Show file tree
Hide file tree
Showing 10 changed files with 648 additions and 265 deletions.
39 changes: 13 additions & 26 deletions tests/ui/coverage-attr/bad-syntax.rs
Original file line number Diff line number Diff line change
@@ -1,58 +1,45 @@
#![feature(coverage_attribute)]
//@ edition: 2021

// Tests the error messages produced (or not produced) by various unusual
// uses of the `#[coverage(..)]` attribute.

// FIXME(#126658): Multiple coverage attributes with the same value are useless,
// and should probably produce a diagnostic.
#[coverage(off)]
#[coverage(off)] //~ ERROR multiple `coverage` attributes
#[coverage(off)]
fn multiple_consistent() {}

// FIXME(#126658): When there are multiple inconsistent coverage attributes,
// it's unclear which one will prevail.
#[coverage(off)]
#[coverage(off)] //~ ERROR multiple `coverage` attributes
#[coverage(on)]
fn multiple_inconsistent() {}

#[coverage] //~ ERROR expected `coverage(off)` or `coverage(on)`
#[coverage] //~ ERROR malformed `coverage` attribute input
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 malformed `coverage` attribute input
fn key_value() {}

#[coverage()] //~ ERROR expected `coverage(off)` or `coverage(on)`
#[coverage()] //~ ERROR malformed `coverage` attribute input
fn list_empty() {}

#[coverage(off, off)] //~ ERROR expected `coverage(off)` or `coverage(on)`
#[coverage(off, off)] //~ ERROR malformed `coverage` attribute input
fn list_consistent() {}

#[coverage(off, on)] //~ ERROR expected `coverage(off)` or `coverage(on)`
#[coverage(off, on)] //~ ERROR malformed `coverage` attribute input
fn list_inconsistent() {}

#[coverage(bogus)] //~ ERROR expected `coverage(off)` or `coverage(on)`
#[coverage(bogus)] //~ ERROR malformed `coverage` attribute input
fn bogus_word() {}

#[coverage(bogus, off)] //~ ERROR expected `coverage(off)` or `coverage(on)`
#[coverage(bogus, off)] //~ ERROR malformed `coverage` attribute input
fn bogus_word_before() {}

#[coverage(off, bogus)] //~ ERROR expected `coverage(off)` or `coverage(on)`
#[coverage(off, bogus)] //~ ERROR malformed `coverage` attribute input
fn bogus_word_after() {}

#[coverage(off,)]
#[coverage(off,)] // (OK!)
fn comma_after() {}

// FIXME(#126658): This shows as multiple different errors.
#[coverage(,off)]
//~^ ERROR expected identifier, found `,`
//~| HELP remove this comma
//~| ERROR expected `coverage(off)` or `coverage(on)`
#[coverage(,off)] //~ ERROR expected identifier, found `,`
fn comma_before() {}

fn main() {}
137 changes: 99 additions & 38 deletions tests/ui/coverage-attr/bad-syntax.stderr
Original file line number Diff line number Diff line change
@@ -1,78 +1,139 @@
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)]
--> $DIR/bad-syntax.rs:15:1
|
LL | #[coverage]
| ^^^^^^^^^^^
|

error: expected identifier, found `,`
--> $DIR/bad-syntax.rs:52:12
help: the following are the possible correct uses
|
LL | #[coverage(,off)]
| ^
| |
| expected identifier
| help: remove this comma
LL | #[coverage(off)]
| ~~~~~~~~~~~~~~~~
LL | #[coverage(on)]
| ~~~~~~~~~~~~~~~

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

error: expected `coverage(off)` or `coverage(on)`
--> $DIR/bad-syntax.rs:23:1
|
LL | #[coverage = true]
| ^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(off)]
| ~~~~~~~~~~~~~~~~
LL | #[coverage(on)]
| ~~~~~~~~~~~~~~~

error: expected `coverage(off)` or `coverage(on)`
--> $DIR/bad-syntax.rs:30:1
error: malformed `coverage` attribute input
--> $DIR/bad-syntax.rs:21:1
|
LL | #[coverage()]
| ^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(off)]
| ~~~~~~~~~~~~~~~~
LL | #[coverage(on)]
| ~~~~~~~~~~~~~~~

error: expected `coverage(off)` or `coverage(on)`
--> $DIR/bad-syntax.rs:33:1
error: malformed `coverage` attribute input
--> $DIR/bad-syntax.rs:24:1
|
LL | #[coverage(off, off)]
| ^^^^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(off)]
| ~~~~~~~~~~~~~~~~
LL | #[coverage(on)]
| ~~~~~~~~~~~~~~~

error: expected `coverage(off)` or `coverage(on)`
--> $DIR/bad-syntax.rs:36:1
error: malformed `coverage` attribute input
--> $DIR/bad-syntax.rs:27:1
|
LL | #[coverage(off, on)]
| ^^^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(off)]
| ~~~~~~~~~~~~~~~~
LL | #[coverage(on)]
| ~~~~~~~~~~~~~~~

error: expected `coverage(off)` or `coverage(on)`
--> $DIR/bad-syntax.rs:39:1
error: malformed `coverage` attribute input
--> $DIR/bad-syntax.rs:30:1
|
LL | #[coverage(bogus)]
| ^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(off)]
| ~~~~~~~~~~~~~~~~
LL | #[coverage(on)]
| ~~~~~~~~~~~~~~~

error: expected `coverage(off)` or `coverage(on)`
--> $DIR/bad-syntax.rs:42:1
error: malformed `coverage` attribute input
--> $DIR/bad-syntax.rs:33:1
|
LL | #[coverage(bogus, off)]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(off)]
| ~~~~~~~~~~~~~~~~
LL | #[coverage(on)]
| ~~~~~~~~~~~~~~~

error: expected `coverage(off)` or `coverage(on)`
--> $DIR/bad-syntax.rs:45:1
error: malformed `coverage` attribute input
--> $DIR/bad-syntax.rs:36:1
|
LL | #[coverage(off, bogus)]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(off)]
| ~~~~~~~~~~~~~~~~
LL | #[coverage(on)]
| ~~~~~~~~~~~~~~~

error: expected `coverage(off)` or `coverage(on)`
--> $DIR/bad-syntax.rs:52:1
error: expected identifier, found `,`
--> $DIR/bad-syntax.rs:42:12
|
LL | #[coverage(,off)]
| ^^^^^^^^^^^^^^^^^
| ^
| |
| expected identifier
| help: remove this comma

error: multiple `coverage` attributes
--> $DIR/bad-syntax.rs:7:1
|
LL | #[coverage(off)]
| ^^^^^^^^^^^^^^^^ help: remove this attribute
|
note: attribute also specified here
--> $DIR/bad-syntax.rs:8:1
|
LL | #[coverage(off)]
| ^^^^^^^^^^^^^^^^

error: multiple `coverage` attributes
--> $DIR/bad-syntax.rs:11:1
|
LL | #[coverage(off)]
| ^^^^^^^^^^^^^^^^ help: remove this attribute
|
note: attribute also specified here
--> $DIR/bad-syntax.rs:12:1
|
LL | #[coverage(on)]
| ^^^^^^^^^^^^^^^

error: aborting due to 11 previous errors

51 changes: 28 additions & 23 deletions tests/ui/coverage-attr/name-value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,57 +8,62 @@
// and in places that cannot have a coverage attribute, to demonstrate the
// interaction between multiple errors.

// 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 malformed `coverage` attribute input
//~| 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 malformed `coverage` attribute input
//~| 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 malformed `coverage` attribute input
//~| ERROR attribute should be applied to a function definition or closure
struct MyStruct;

#[coverage = "off"] //~ ERROR malformed `coverage` attribute input
#[coverage = "off"]
//~^ ERROR malformed `coverage` attribute input
//~| 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 malformed `coverage` attribute input
//~| 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 malformed `coverage` attribute input
//~| 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 malformed `coverage` attribute input
//~| 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 malformed `coverage` attribute input
//~| ERROR attribute should be applied to a function definition or closure
type T;
}

#[coverage = "off"] //~ ERROR malformed `coverage` attribute input
#[coverage = "off"]
//~^ ERROR malformed `coverage` attribute input
//~| 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 malformed `coverage` attribute input
//~| 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 malformed `coverage` attribute input
//~| 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
//~^ ERROR malformed `coverage` attribute input
fn main() {}
Loading

0 comments on commit 1d085bf

Please sign in to comment.