Skip to content

Commit 36dc821

Browse files
Add more regression tests for doc(auto_cfg())
1 parent cb55c0e commit 36dc821

6 files changed

Lines changed: 188 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// This test ensures that `auto_cfg(hide(key))` does not hide `key = value` and that
2+
// `auto_cfg(hide(key, values(none())))` does the same.
3+
4+
#![feature(doc_cfg)]
5+
#![crate_name = "foo"]
6+
7+
#![doc(auto_cfg(hide(meow)))]
8+
#![doc(auto_cfg(hide(another_meow, values(none()))))]
9+
10+
//@ has foo/fn.foo.html
11+
//@ has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-blob'
12+
//@ !has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-meow'
13+
//@ !has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-another_meow'
14+
#[cfg(not(meow))]
15+
#[cfg(not(another_meow))]
16+
#[cfg(not(blob))]
17+
pub fn foo() {}
18+
19+
//@ has foo/fn.bar.html
20+
//@ has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-blob=lol'
21+
//@ has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-meow=lol'
22+
//@ has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-another_meow=lol'
23+
#[cfg(not(meow = "lol"))]
24+
#[cfg(not(another_meow = "lol"))]
25+
#[cfg(not(blob = "lol"))]
26+
pub fn bar() {}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// This test ensures that using `auto_cfg(show(key))` works correctly.
2+
3+
#![feature(doc_cfg)]
4+
#![crate_name = "foo"]
5+
6+
#![doc(auto_cfg(hide(meow)))]
7+
#![doc(auto_cfg(hide(meow, values("lol"))))]
8+
9+
//@ has foo/fn.foo.html
10+
//@ has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-blob'
11+
//@ !has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-meow'
12+
#[cfg(not(meow))]
13+
#[cfg(not(blob))]
14+
pub fn foo() {}
15+
16+
//@ has foo/fn.bar.html
17+
//@ has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-blob=lol'
18+
//@ !has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-meow=lol'
19+
#[cfg(not(meow = "lol"))]
20+
#[cfg(not(blob = "lol"))]
21+
pub fn bar() {}
22+
23+
//@ has foo/fn.babar.html
24+
//@ has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-blob=lola'
25+
//@ has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-meow=lola'
26+
#[cfg(not(meow = "lola"))]
27+
#[cfg(not(blob = "lola"))]
28+
pub fn babar() {}
29+
30+
pub mod sub {
31+
// We show again `meow`, however `meow="lol"` should still be hidden.
32+
#![doc(auto_cfg(show(meow)))]
33+
34+
//@ has foo/sub/fn.foo.html
35+
//@ has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-blob'
36+
//@ has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-meow'
37+
#[cfg(not(meow))]
38+
#[cfg(not(blob))]
39+
pub fn foo() {}
40+
41+
//@ has foo/sub/fn.bar.html
42+
//@ has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-blob=lol'
43+
//@ !has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-meow=lol'
44+
#[cfg(not(meow = "lol"))]
45+
#[cfg(not(blob = "lol"))]
46+
pub fn bar() {}
47+
48+
//@ has foo/sub/fn.babar.html
49+
//@ has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-blob=lola'
50+
//@ has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-meow=lola'
51+
#[cfg(not(meow = "lola"))]
52+
#[cfg(not(blob = "lola"))]
53+
pub fn babar() {}
54+
}
55+
56+
pub mod sub2 {
57+
// We show again `meow = "lol`, however `meow` should still be hidden.
58+
#![doc(auto_cfg(show(meow, values("lol"))))]
59+
60+
//@ has foo/sub2/fn.foo.html
61+
//@ has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-blob'
62+
//@ !has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-meow'
63+
#[cfg(not(meow))]
64+
#[cfg(not(blob))]
65+
pub fn foo() {}
66+
67+
//@ has foo/sub2/fn.bar.html
68+
//@ has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-blob=lol'
69+
//@ has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-meow=lol'
70+
#[cfg(not(meow = "lol"))]
71+
#[cfg(not(blob = "lol"))]
72+
pub fn bar() {}
73+
74+
//@ has foo/sub2/fn.babar.html
75+
//@ has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-blob=lola'
76+
//@ has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-meow=lola'
77+
#[cfg(not(meow = "lola"))]
78+
#[cfg(not(blob = "lola"))]
79+
pub fn babar() {}
80+
}
81+
82+
pub mod sub3 {
83+
// We show again `meow = "lol`, but by using `any()` this time.
84+
#![doc(auto_cfg(show(meow, values(any()))))]
85+
86+
//@ has foo/sub3/fn.foo.html
87+
//@ has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-blob'
88+
//@ !has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-meow'
89+
#[cfg(not(meow))]
90+
#[cfg(not(blob))]
91+
pub fn foo() {}
92+
93+
//@ has foo/sub3/fn.bar.html
94+
//@ has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-blob=lol'
95+
//@ has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-meow=lol'
96+
#[cfg(not(meow = "lol"))]
97+
#[cfg(not(blob = "lol"))]
98+
pub fn bar() {}
99+
100+
//@ has foo/sub3/fn.babar.html
101+
//@ has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-blob=lola'
102+
//@ has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-meow=lola'
103+
#[cfg(not(meow = "lola"))]
104+
#[cfg(not(blob = "lola"))]
105+
pub fn babar() {}
106+
}

tests/rustdoc-ui/doc-cfg-3.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Checks that you cannot have `any()` and values at the same time.
2+
3+
#![deny(invalid_doc_attributes)]
4+
#![feature(doc_cfg)]
5+
6+
#![doc(auto_cfg(hide(target_os, values(any(), "linux"))))] //~ ERROR
7+
#![doc(auto_cfg(hide(target_os, values("linux", any()))))] //~ ERROR

tests/rustdoc-ui/doc-cfg-3.stderr

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error: `any()` was used when other values were provided
2+
--> $DIR/doc-cfg-3.rs:6:40
3+
|
4+
LL | #![doc(auto_cfg(hide(target_os, values(any(), "linux"))))]
5+
| ^^^^^ ------- value declared here
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/doc-cfg-3.rs:3:9
9+
|
10+
LL | #![deny(invalid_doc_attributes)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: `any()` was used when other values were provided
14+
--> $DIR/doc-cfg-3.rs:7:49
15+
|
16+
LL | #![doc(auto_cfg(hide(target_os, values("linux", any()))))]
17+
| ------- ^^^^^
18+
| |
19+
| value declared here
20+
21+
error: aborting due to 2 previous errors
22+

tests/rustdoc-ui/doc-cfg-4.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Checks that you cannot have any item inside `any()` and
2+
3+
#![deny(invalid_doc_attributes)]
4+
#![feature(doc_cfg)]
5+
6+
#![doc(auto_cfg(hide(target_os, values(any("linux")))))] //~ ERROR
7+
#![doc(auto_cfg(hide(target_os, values(none("linux")))))] //~ ERROR

tests/rustdoc-ui/doc-cfg-4.stderr

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: `#![doc(auto_cfg(any(...)))]` only accepts identifiers or `values()`
2+
--> $DIR/doc-cfg-4.rs:6:40
3+
|
4+
LL | #![doc(auto_cfg(hide(target_os, values(any("linux")))))]
5+
| ^^^^^^^^^^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/doc-cfg-4.rs:3:9
9+
|
10+
LL | #![deny(invalid_doc_attributes)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: `#![doc(auto_cfg(none(...)))]` only accepts identifiers or `values()`
14+
--> $DIR/doc-cfg-4.rs:7:40
15+
|
16+
LL | #![doc(auto_cfg(hide(target_os, values(none("linux")))))]
17+
| ^^^^^^^^^^^^^
18+
19+
error: aborting due to 2 previous errors
20+

0 commit comments

Comments
 (0)