Skip to content

Commit cb38ced

Browse files
Add tests for doc(attribute = "...") attribute
1 parent 5604780 commit cb38ced

File tree

11 files changed

+135
-5
lines changed

11 files changed

+135
-5
lines changed

tests/rustdoc-gui/links-color.goml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ show-text: true
99
define-function: (
1010
"check-colors",
1111
[theme, mod, macro, struct, enum, trait, fn, type, union, keyword,
12-
sidebar, sidebar_current, sidebar_current_background],
12+
attribute, sidebar, sidebar_current, sidebar_current_background],
1313
block {
1414
call-function: ("switch-theme", {"theme": |theme|})
1515
// Checking results colors.
@@ -22,6 +22,7 @@ define-function: (
2222
assert-css: (".item-table .type", {"color": |type|}, ALL)
2323
assert-css: (".item-table .union", {"color": |union|}, ALL)
2424
assert-css: (".item-table .keyword", {"color": |keyword|}, ALL)
25+
assert-css: (".item-table .attribute", {"color": |attribute|}, ALL)
2526
// Checking sidebar elements.
2627
assert-css: (
2728
".sidebar-elems li:not(.current) a",
@@ -58,6 +59,7 @@ call-function: (
5859
"type": "#ffa0a5",
5960
"union": "#ffa0a5",
6061
"keyword": "#39afd7",
62+
"attribute": "#39afd7",
6163
"sidebar": "#53b1db",
6264
"sidebar_current": "#ffb44c",
6365
"sidebar_current_background": "transparent",
@@ -76,6 +78,7 @@ call-function: (
7678
"type": "#2dbfb8",
7779
"union": "#2dbfb8",
7880
"keyword": "#d2991d",
81+
"attribute": "#d2991d",
7982
"sidebar": "#fdbf35",
8083
"sidebar_current": "#fdbf35",
8184
"sidebar_current_background": "#444",
@@ -94,6 +97,7 @@ call-function: (
9497
"type": "#ad378a",
9598
"union": "#ad378a",
9699
"keyword": "#3873ad",
100+
"attribute": "#3873ad",
97101
"sidebar": "#356da4",
98102
"sidebar_current": "#356da4",
99103
"sidebar_current_background": "#fff",

tests/rustdoc-gui/module-items-font.goml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,12 @@ assert-css: (
6565
"#keywords + .item-table dd",
6666
{"font-family": '"Source Serif 4", NanumBarunGothic, serif'},
6767
)
68+
// attributes
69+
assert-css: (
70+
"#attributes + .item-table dt a",
71+
{"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'},
72+
)
73+
assert-css: (
74+
"#attributes + .item-table dd",
75+
{"font-family": '"Source Serif 4", NanumBarunGothic, serif'},
76+
)

tests/rustdoc-gui/search-result-color.goml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ define-function: (
77
[
88
theme, count_color, desc_color, path_color, bottom_border_color, keyword_color,
99
struct_color, associatedtype_color, tymethod_color, method_color, structfield_color,
10-
structfield_hover_color, macro_color, fn_color, hover_path_color, hover_background, grey
10+
structfield_hover_color, macro_color, fn_color, hover_path_color, hover_background,
11+
keyword_color, grey
1112
],
1213
block {
1314
call-function: ("switch-theme", {"theme": |theme|})
@@ -45,6 +46,11 @@ define-function: (
4546
"color": |keyword_color|,
4647
"hover_color": |keyword_color|,
4748
})
49+
call-function: ("check-result-color", {
50+
"result_kind": "attribute",
51+
"color": |attribute_color|,
52+
"hover_color": |attribute_color|,
53+
})
4854
call-function: ("check-result-color", {
4955
"result_kind": "struct",
5056
"color": |struct_color|,
@@ -154,6 +160,7 @@ call-function: ("check-search-color", {
154160
"path_color": "#0096cf",
155161
"bottom_border_color": "#aaa3",
156162
"keyword_color": "#39afd7",
163+
"attribute_color": "#39afd7",
157164
"struct_color": "#ffa0a5",
158165
"associatedtype_color": "#39afd7",
159166
"tymethod_color": "#fdd687",
@@ -175,6 +182,7 @@ call-function: ("check-search-color", {
175182
"path_color": "#ddd",
176183
"bottom_border_color": "#aaa3",
177184
"keyword_color": "#d2991d",
185+
"attribute_color": "#d2991d",
178186
"struct_color": "#2dbfb8",
179187
"associatedtype_color": "#d2991d",
180188
"tymethod_color": "#2bab63",
@@ -196,6 +204,7 @@ call-function: ("check-search-color", {
196204
"path_color": "#000",
197205
"bottom_border_color": "#aaa3",
198206
"keyword_color": "#3873ad",
207+
"attribute_color": "#3873ad",
199208
"struct_color": "#ad378a",
200209
"associatedtype_color": "#3873ad",
201210
"tymethod_color": "#ad7c37",

tests/rustdoc-gui/sidebar-links-color.goml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ define-function: (
1212
enum_hover_background, union, union_hover, union_hover_background, trait, trait_hover,
1313
trait_hover_background, fn, fn_hover, fn_hover_background, type, type_hover,
1414
type_hover_background, keyword, keyword_hover, keyword_hover_background,
15+
attribute, attribute_hover, attribute_hover_background,
1516
],
1617
block {
1718
call-function: ("switch-theme", {"theme": |theme|})
@@ -85,6 +86,16 @@ define-function: (
8586
".sidebar .block.keyword a:hover",
8687
{"color": |keyword_hover|, "background-color": |keyword_hover_background|},
8788
)
89+
// Attribute
90+
assert-css: (
91+
".sidebar .block.attribute a",
92+
{"color": |attribute|, "background-color": "rgba(0, 0, 0, 0)"},
93+
)
94+
move-cursor-to: ".sidebar .block.attribute a"
95+
assert-css: (
96+
".sidebar .block.attribute a:hover",
97+
{"color": |attribute_hover|, "background-color": |attribute_hover_background|},
98+
)
8899
}
89100
)
90101

@@ -113,6 +124,9 @@ call-function: (
113124
"keyword": "#53b1db",
114125
"keyword_hover": "#ffb44c",
115126
"keyword_hover_background": "transparent",
127+
"attribute": "#53b1db",
128+
"attribute_hover": "#ffb44c",
129+
"attribute_hover_background": "transparent",
116130
}
117131
)
118132
call-function: (
@@ -140,6 +154,9 @@ call-function: (
140154
"keyword": "#fdbf35",
141155
"keyword_hover": "#fdbf35",
142156
"keyword_hover_background": "#444",
157+
"attribute": "#fdbf35",
158+
"attribute_hover": "#fdbf35",
159+
"attribute_hover_background": "#444",
143160
}
144161
)
145162
call-function: (
@@ -167,5 +184,8 @@ call-function: (
167184
"keyword": "#356da4",
168185
"keyword_hover": "#356da4",
169186
"keyword_hover_background": "#fff",
187+
"attribute": "#356da4",
188+
"attribute_hover": "#356da4",
189+
"attribute_hover_background": "#fff",
170190
}
171191
)

tests/rustdoc-gui/src/test_docs/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ pub enum AnEnum {
161161
/// Some keyword.
162162
pub mod keyword {}
163163

164+
#[doc(attribute = "forbid")]
165+
/// Some attribute.
166+
pub mod repr {}
167+
164168
/// Just some type alias.
165169
pub type SomeType = u32;
166170

tests/rustdoc-json/doc_attribute.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Doc attributes (`#[doc(attribute = "...")]` should not be generated in rustdoc JSON output
2+
// and this test ensures it.
3+
4+
#![feature(rustdoc_internals)]
5+
#![no_std]
6+
7+
//@ !has "$.index[?(@.name=='repr')]"
8+
//@ has "$.index[?(@.name=='foo')]"
9+
10+
#[doc(attribute = "repr")]
11+
/// this is a test!
12+
pub mod foo {}
13+
14+
//@ !has "$.index[?(@.name=='forbid')]"
15+
//@ !has "$.index[?(@.name=='bar')]"
16+
#[doc(attribute = "forbid")]
17+
/// hello
18+
mod bar {}

tests/rustdoc-ui/invalid-attribute.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Testing the output when an invalid builtin attribute is passed as value
2+
// to `doc(attribute = "...")`.
3+
4+
#![feature(rustdoc_internals)]
5+
6+
#[doc(attribute = "foo df")] //~ ERROR
7+
mod foo {}
8+
9+
#[doc(attribute = "fooyi")] //~ ERROR
10+
mod foo2 {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: nonexistent builtin attribute `foo df` used in `#[doc(attribute = "...")]`
2+
--> $DIR/invalid-attribute.rs:6:19
3+
|
4+
LL | #[doc(attribute = "foo df")]
5+
| ^^^^^^^^
6+
|
7+
= help: only existing builtin attributes are allowed in core/std
8+
9+
error: nonexistent builtin attribute `fooyi` used in `#[doc(attribute = "...")]`
10+
--> $DIR/invalid-attribute.rs:9:19
11+
|
12+
LL | #[doc(attribute = "fooyi")]
13+
| ^^^^^^^
14+
|
15+
= help: only existing builtin attributes are allowed in core/std
16+
17+
error: aborting due to 2 previous errors
18+

tests/rustdoc/doc-attribute.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Test checking the `#[doc(attribute = "...")]` attribute.
2+
3+
#![crate_name = "foo"]
4+
5+
#![feature(rustdoc_internals)]
6+
7+
//@ has foo/index.html '//h2[@id="attributes"]' 'Attributes'
8+
//@ has foo/index.html '//a[@href="attribute.no_mangle.html"]' 'no_mangle'
9+
//@ has foo/index.html '//div[@class="sidebar-elems"]//li/a' 'Attributes'
10+
//@ has foo/index.html '//div[@class="sidebar-elems"]//li/a/@href' '#attributes'
11+
//@ has foo/attribute.no_mangle.html '//h1' 'Attribute no_mangle'
12+
//@ has foo/attribute.no_mangle.html '//section[@id="main-content"]//div[@class="docblock"]//p' 'this is a test!'
13+
//@ has foo/index.html '//a/@href' '../foo/index.html'
14+
//@ !has foo/foo/index.html
15+
//@ !has-dir foo/foo
16+
//@ !has foo/index.html '//span' '🔒'
17+
#[doc(attribute = "no_mangle")]
18+
/// this is a test!
19+
mod foo{}
20+
21+
//@ has foo/attribute.repr.html '//section[@id="main-content"]//div[@class="docblock"]//p' 'hello'
22+
#[doc(attribute = "repr")]
23+
/// hello
24+
mod bar {}

tests/ui/feature-gates/feature-gate-rustdoc_internals.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
/// wonderful
33
mod foo {}
44

5+
#[doc(attribute = "repr")] //~ ERROR: `#[doc(attribute)]` is meant for internal use only
6+
/// wonderful
7+
mod foo2 {}
8+
59
trait Mine {}
610

711
#[doc(fake_variadic)] //~ ERROR: `#[doc(fake_variadic)]` is meant for internal use only

tests/ui/feature-gates/feature-gate-rustdoc_internals.stderr

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,18 @@ LL | #[doc(keyword = "match")]
88
= help: add `#![feature(rustdoc_internals)]` to the crate attributes to enable
99
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1010

11+
error[E0658]: `#[doc(attribute)]` is meant for internal use only
12+
--> $DIR/feature-gate-rustdoc_internals.rs:5:1
13+
|
14+
LL | #[doc(attribute = "repr")]
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
|
17+
= note: see issue #90418 <https://github.com/rust-lang/rust/issues/90418> for more information
18+
= help: add `#![feature(rustdoc_internals)]` to the crate attributes to enable
19+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
20+
1121
error[E0658]: `#[doc(fake_variadic)]` is meant for internal use only
12-
--> $DIR/feature-gate-rustdoc_internals.rs:7:1
22+
--> $DIR/feature-gate-rustdoc_internals.rs:11:1
1323
|
1424
LL | #[doc(fake_variadic)]
1525
| ^^^^^^^^^^^^^^^^^^^^^
@@ -19,7 +29,7 @@ LL | #[doc(fake_variadic)]
1929
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2030

2131
error[E0658]: `#[doc(search_unbox)]` is meant for internal use only
22-
--> $DIR/feature-gate-rustdoc_internals.rs:10:1
32+
--> $DIR/feature-gate-rustdoc_internals.rs:14:1
2333
|
2434
LL | #[doc(search_unbox)]
2535
| ^^^^^^^^^^^^^^^^^^^^
@@ -28,6 +38,6 @@ LL | #[doc(search_unbox)]
2838
= help: add `#![feature(rustdoc_internals)]` to the crate attributes to enable
2939
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
3040

31-
error: aborting due to 3 previous errors
41+
error: aborting due to 4 previous errors
3242

3343
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)