Skip to content

Commit

Permalink
Add a more thorough test of incorrect/unusal #[coverage(..)] syntax
Browse files Browse the repository at this point in the history
This test reflects the current implementation behaviour, which is not
necessarily the desired behaviour.
  • Loading branch information
Zalathar committed Jun 18, 2024
1 parent 605b615 commit 9a084e6
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tests/ui/coverage-attr/bad-syntax.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#![feature(coverage_attribute)]

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

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

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

#[coverage] //~ ERROR expected `coverage(off)` or `coverage(on)`
fn bare_word() {}

// FIXME(#84605): 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)]
fn key_value() {}

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

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

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

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

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

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

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

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

fn main() {}
78 changes: 78 additions & 0 deletions tests/ui/coverage-attr/bad-syntax.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
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
|
LL | #[coverage(,off)]
| ^
| |
| expected identifier
| help: remove this comma

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

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

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

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

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

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

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

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

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

error: aborting due to 11 previous errors

0 comments on commit 9a084e6

Please sign in to comment.