Add a more thorough test of incorrect/unusal #[coverage(..)] syntax

This test reflects the current implementation behaviour, which is not
necessarily the desired behaviour.
This commit is contained in:
Zalathar 2024-06-18 18:18:15 +10:00
parent 605b61534a
commit 9a084e6310
2 changed files with 136 additions and 0 deletions

View File

@ -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() {}

View File

@ -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