Skip to content

Commit 1852141

Browse files
committed
coverage: Bless coverage attribute tests
1 parent b7c057c commit 1852141

10 files changed

+648
-265
lines changed

tests/ui/coverage-attr/bad-syntax.rs

+13-26
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,45 @@
11
#![feature(coverage_attribute)]
2+
//@ edition: 2021
23

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

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

12-
// FIXME(#126658): When there are multiple inconsistent coverage attributes,
13-
// it's unclear which one will prevail.
14-
#[coverage(off)]
11+
#[coverage(off)] //~ ERROR multiple `coverage` attributes
1512
#[coverage(on)]
1613
fn multiple_inconsistent() {}
1714

18-
#[coverage] //~ ERROR expected `coverage(off)` or `coverage(on)`
15+
#[coverage] //~ ERROR malformed `coverage` attribute input
1916
fn bare_word() {}
2017

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

30-
#[coverage()] //~ ERROR expected `coverage(off)` or `coverage(on)`
21+
#[coverage()] //~ ERROR malformed `coverage` attribute input
3122
fn list_empty() {}
3223

33-
#[coverage(off, off)] //~ ERROR expected `coverage(off)` or `coverage(on)`
24+
#[coverage(off, off)] //~ ERROR malformed `coverage` attribute input
3425
fn list_consistent() {}
3526

36-
#[coverage(off, on)] //~ ERROR expected `coverage(off)` or `coverage(on)`
27+
#[coverage(off, on)] //~ ERROR malformed `coverage` attribute input
3728
fn list_inconsistent() {}
3829

39-
#[coverage(bogus)] //~ ERROR expected `coverage(off)` or `coverage(on)`
30+
#[coverage(bogus)] //~ ERROR malformed `coverage` attribute input
4031
fn bogus_word() {}
4132

42-
#[coverage(bogus, off)] //~ ERROR expected `coverage(off)` or `coverage(on)`
33+
#[coverage(bogus, off)] //~ ERROR malformed `coverage` attribute input
4334
fn bogus_word_before() {}
4435

45-
#[coverage(off, bogus)] //~ ERROR expected `coverage(off)` or `coverage(on)`
36+
#[coverage(off, bogus)] //~ ERROR malformed `coverage` attribute input
4637
fn bogus_word_after() {}
4738

48-
#[coverage(off,)]
39+
#[coverage(off,)] // (OK!)
4940
fn comma_after() {}
5041

51-
// FIXME(#126658): This shows as multiple different errors.
52-
#[coverage(,off)]
53-
//~^ ERROR expected identifier, found `,`
54-
//~| HELP remove this comma
55-
//~| ERROR expected `coverage(off)` or `coverage(on)`
42+
#[coverage(,off)] //~ ERROR expected identifier, found `,`
5643
fn comma_before() {}
5744

5845
fn main() {}
+99-38
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,139 @@
11
error: malformed `coverage` attribute input
2-
--> $DIR/bad-syntax.rs:23:1
3-
|
4-
LL | #[coverage = true]
5-
| ^^^^^^^^^^^^^^^^^^
6-
|
7-
help: the following are the possible correct uses
8-
|
9-
LL | #[coverage(on|off)]
2+
--> $DIR/bad-syntax.rs:15:1
103
|
114
LL | #[coverage]
5+
| ^^^^^^^^^^^
126
|
13-
14-
error: expected identifier, found `,`
15-
--> $DIR/bad-syntax.rs:52:12
7+
help: the following are the possible correct uses
168
|
17-
LL | #[coverage(,off)]
18-
| ^
19-
| |
20-
| expected identifier
21-
| help: remove this comma
9+
LL | #[coverage(off)]
10+
| ~~~~~~~~~~~~~~~~
11+
LL | #[coverage(on)]
12+
| ~~~~~~~~~~~~~~~
2213

23-
error: expected `coverage(off)` or `coverage(on)`
14+
error: malformed `coverage` attribute input
2415
--> $DIR/bad-syntax.rs:18:1
2516
|
26-
LL | #[coverage]
27-
| ^^^^^^^^^^^
28-
29-
error: expected `coverage(off)` or `coverage(on)`
30-
--> $DIR/bad-syntax.rs:23:1
31-
|
3217
LL | #[coverage = true]
3318
| ^^^^^^^^^^^^^^^^^^
19+
|
20+
help: the following are the possible correct uses
21+
|
22+
LL | #[coverage(off)]
23+
| ~~~~~~~~~~~~~~~~
24+
LL | #[coverage(on)]
25+
| ~~~~~~~~~~~~~~~
3426

35-
error: expected `coverage(off)` or `coverage(on)`
36-
--> $DIR/bad-syntax.rs:30:1
27+
error: malformed `coverage` attribute input
28+
--> $DIR/bad-syntax.rs:21:1
3729
|
3830
LL | #[coverage()]
3931
| ^^^^^^^^^^^^^
32+
|
33+
help: the following are the possible correct uses
34+
|
35+
LL | #[coverage(off)]
36+
| ~~~~~~~~~~~~~~~~
37+
LL | #[coverage(on)]
38+
| ~~~~~~~~~~~~~~~
4039

41-
error: expected `coverage(off)` or `coverage(on)`
42-
--> $DIR/bad-syntax.rs:33:1
40+
error: malformed `coverage` attribute input
41+
--> $DIR/bad-syntax.rs:24:1
4342
|
4443
LL | #[coverage(off, off)]
4544
| ^^^^^^^^^^^^^^^^^^^^^
45+
|
46+
help: the following are the possible correct uses
47+
|
48+
LL | #[coverage(off)]
49+
| ~~~~~~~~~~~~~~~~
50+
LL | #[coverage(on)]
51+
| ~~~~~~~~~~~~~~~
4652

47-
error: expected `coverage(off)` or `coverage(on)`
48-
--> $DIR/bad-syntax.rs:36:1
53+
error: malformed `coverage` attribute input
54+
--> $DIR/bad-syntax.rs:27:1
4955
|
5056
LL | #[coverage(off, on)]
5157
| ^^^^^^^^^^^^^^^^^^^^
58+
|
59+
help: the following are the possible correct uses
60+
|
61+
LL | #[coverage(off)]
62+
| ~~~~~~~~~~~~~~~~
63+
LL | #[coverage(on)]
64+
| ~~~~~~~~~~~~~~~
5265

53-
error: expected `coverage(off)` or `coverage(on)`
54-
--> $DIR/bad-syntax.rs:39:1
66+
error: malformed `coverage` attribute input
67+
--> $DIR/bad-syntax.rs:30:1
5568
|
5669
LL | #[coverage(bogus)]
5770
| ^^^^^^^^^^^^^^^^^^
71+
|
72+
help: the following are the possible correct uses
73+
|
74+
LL | #[coverage(off)]
75+
| ~~~~~~~~~~~~~~~~
76+
LL | #[coverage(on)]
77+
| ~~~~~~~~~~~~~~~
5878

59-
error: expected `coverage(off)` or `coverage(on)`
60-
--> $DIR/bad-syntax.rs:42:1
79+
error: malformed `coverage` attribute input
80+
--> $DIR/bad-syntax.rs:33:1
6181
|
6282
LL | #[coverage(bogus, off)]
6383
| ^^^^^^^^^^^^^^^^^^^^^^^
84+
|
85+
help: the following are the possible correct uses
86+
|
87+
LL | #[coverage(off)]
88+
| ~~~~~~~~~~~~~~~~
89+
LL | #[coverage(on)]
90+
| ~~~~~~~~~~~~~~~
6491

65-
error: expected `coverage(off)` or `coverage(on)`
66-
--> $DIR/bad-syntax.rs:45:1
92+
error: malformed `coverage` attribute input
93+
--> $DIR/bad-syntax.rs:36:1
6794
|
6895
LL | #[coverage(off, bogus)]
6996
| ^^^^^^^^^^^^^^^^^^^^^^^
97+
|
98+
help: the following are the possible correct uses
99+
|
100+
LL | #[coverage(off)]
101+
| ~~~~~~~~~~~~~~~~
102+
LL | #[coverage(on)]
103+
| ~~~~~~~~~~~~~~~
70104

71-
error: expected `coverage(off)` or `coverage(on)`
72-
--> $DIR/bad-syntax.rs:52:1
105+
error: expected identifier, found `,`
106+
--> $DIR/bad-syntax.rs:42:12
73107
|
74108
LL | #[coverage(,off)]
75-
| ^^^^^^^^^^^^^^^^^
109+
| ^
110+
| |
111+
| expected identifier
112+
| help: remove this comma
113+
114+
error: multiple `coverage` attributes
115+
--> $DIR/bad-syntax.rs:7:1
116+
|
117+
LL | #[coverage(off)]
118+
| ^^^^^^^^^^^^^^^^ help: remove this attribute
119+
|
120+
note: attribute also specified here
121+
--> $DIR/bad-syntax.rs:8:1
122+
|
123+
LL | #[coverage(off)]
124+
| ^^^^^^^^^^^^^^^^
125+
126+
error: multiple `coverage` attributes
127+
--> $DIR/bad-syntax.rs:11:1
128+
|
129+
LL | #[coverage(off)]
130+
| ^^^^^^^^^^^^^^^^ help: remove this attribute
131+
|
132+
note: attribute also specified here
133+
--> $DIR/bad-syntax.rs:12:1
134+
|
135+
LL | #[coverage(on)]
136+
| ^^^^^^^^^^^^^^^
76137

77138
error: aborting due to 11 previous errors
78139

tests/ui/coverage-attr/name-value.rs

+28-23
Original file line numberDiff line numberDiff line change
@@ -8,57 +8,62 @@
88
// and in places that cannot have a coverage attribute, to demonstrate the
99
// interaction between multiple errors.
1010

11-
// FIXME(#126658): The error messages for using this syntax are inconsistent
12-
// with the error message in other cases. They also sometimes appear together
13-
// with other errors, and they suggest using the incorrect `#[coverage]` syntax.
14-
15-
#[coverage = "off"] //~ ERROR malformed `coverage` attribute input
11+
#[coverage = "off"]
12+
//~^ ERROR malformed `coverage` attribute input
13+
//~| ERROR attribute should be applied to a function definition or closure
1614
mod my_mod {}
1715

1816
mod my_mod_inner {
19-
#![coverage = "off"] //~ ERROR malformed `coverage` attribute input
17+
#![coverage = "off"]
18+
//~^ ERROR malformed `coverage` attribute input
19+
//~| ERROR attribute should be applied to a function definition or closure
2020
}
2121

2222
#[coverage = "off"]
23-
//~^ ERROR `#[coverage]` must be applied to coverable code
24-
//~| ERROR malformed `coverage` attribute input
23+
//~^ ERROR malformed `coverage` attribute input
24+
//~| ERROR attribute should be applied to a function definition or closure
2525
struct MyStruct;
2626

27-
#[coverage = "off"] //~ ERROR malformed `coverage` attribute input
27+
#[coverage = "off"]
28+
//~^ ERROR malformed `coverage` attribute input
29+
//~| ERROR attribute should be applied to a function definition or closure
2830
impl MyStruct {
2931
#[coverage = "off"]
30-
//~^ ERROR `#[coverage]` must be applied to coverable code
31-
//~| ERROR malformed `coverage` attribute input
32+
//~^ ERROR malformed `coverage` attribute input
33+
//~| ERROR attribute should be applied to a function definition or closure
3234
const X: u32 = 7;
3335
}
3436

35-
#[coverage = "off"] //~ ERROR malformed `coverage` attribute input
37+
#[coverage = "off"]
38+
//~^ ERROR malformed `coverage` attribute input
39+
//~| ERROR attribute should be applied to a function definition or closure
3640
trait MyTrait {
3741
#[coverage = "off"]
38-
//~^ ERROR `#[coverage]` must be applied to coverable code
39-
//~| ERROR malformed `coverage` attribute input
42+
//~^ ERROR malformed `coverage` attribute input
43+
//~| ERROR attribute should be applied to a function definition or closure
4044
const X: u32;
4145

4246
#[coverage = "off"]
43-
//~^ ERROR `#[coverage]` must be applied to coverable code
44-
//~| ERROR malformed `coverage` attribute input
47+
//~^ ERROR malformed `coverage` attribute input
48+
//~| ERROR attribute should be applied to a function definition or closure
4549
type T;
4650
}
4751

48-
#[coverage = "off"] //~ ERROR malformed `coverage` attribute input
52+
#[coverage = "off"]
53+
//~^ ERROR malformed `coverage` attribute input
54+
//~| ERROR attribute should be applied to a function definition or closure
4955
impl MyTrait for MyStruct {
5056
#[coverage = "off"]
51-
//~^ ERROR `#[coverage]` must be applied to coverable code
52-
//~| ERROR malformed `coverage` attribute input
57+
//~^ ERROR malformed `coverage` attribute input
58+
//~| ERROR attribute should be applied to a function definition or closure
5359
const X: u32 = 8;
5460

5561
#[coverage = "off"]
56-
//~^ ERROR `#[coverage]` must be applied to coverable code
57-
//~| ERROR malformed `coverage` attribute input
62+
//~^ ERROR malformed `coverage` attribute input
63+
//~| ERROR attribute should be applied to a function definition or closure
5864
type T = ();
5965
}
6066

6167
#[coverage = "off"]
62-
//~^ ERROR expected `coverage(off)` or `coverage(on)`
63-
//~| ERROR malformed `coverage` attribute input
68+
//~^ ERROR malformed `coverage` attribute input
6469
fn main() {}

0 commit comments

Comments
 (0)