Add tests for doc(attribute = "...") attribute
This commit is contained in:
parent
ab0ee84eac
commit
75cbd05d19
11 changed files with 135 additions and 5 deletions
|
|
@ -9,7 +9,7 @@ show-text: true
|
|||
define-function: (
|
||||
"check-colors",
|
||||
[theme, mod, macro, struct, enum, trait, fn, type, union, keyword,
|
||||
sidebar, sidebar_current, sidebar_current_background],
|
||||
attribute, sidebar, sidebar_current, sidebar_current_background],
|
||||
block {
|
||||
call-function: ("switch-theme", {"theme": |theme|})
|
||||
// Checking results colors.
|
||||
|
|
@ -22,6 +22,7 @@ define-function: (
|
|||
assert-css: (".item-table .type", {"color": |type|}, ALL)
|
||||
assert-css: (".item-table .union", {"color": |union|}, ALL)
|
||||
assert-css: (".item-table .keyword", {"color": |keyword|}, ALL)
|
||||
assert-css: (".item-table .attribute", {"color": |attribute|}, ALL)
|
||||
// Checking sidebar elements.
|
||||
assert-css: (
|
||||
".sidebar-elems li:not(.current) a",
|
||||
|
|
@ -58,6 +59,7 @@ call-function: (
|
|||
"type": "#ffa0a5",
|
||||
"union": "#ffa0a5",
|
||||
"keyword": "#39afd7",
|
||||
"attribute": "#39afd7",
|
||||
"sidebar": "#53b1db",
|
||||
"sidebar_current": "#ffb44c",
|
||||
"sidebar_current_background": "transparent",
|
||||
|
|
@ -76,6 +78,7 @@ call-function: (
|
|||
"type": "#2dbfb8",
|
||||
"union": "#2dbfb8",
|
||||
"keyword": "#d2991d",
|
||||
"attribute": "#d2991d",
|
||||
"sidebar": "#fdbf35",
|
||||
"sidebar_current": "#fdbf35",
|
||||
"sidebar_current_background": "#444",
|
||||
|
|
@ -94,6 +97,7 @@ call-function: (
|
|||
"type": "#ad378a",
|
||||
"union": "#ad378a",
|
||||
"keyword": "#3873ad",
|
||||
"attribute": "#3873ad",
|
||||
"sidebar": "#356da4",
|
||||
"sidebar_current": "#356da4",
|
||||
"sidebar_current_background": "#fff",
|
||||
|
|
|
|||
|
|
@ -65,3 +65,12 @@ assert-css: (
|
|||
"#keywords + .item-table dd",
|
||||
{"font-family": '"Source Serif 4", NanumBarunGothic, serif'},
|
||||
)
|
||||
// attributes
|
||||
assert-css: (
|
||||
"#attributes + .item-table dt a",
|
||||
{"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'},
|
||||
)
|
||||
assert-css: (
|
||||
"#attributes + .item-table dd",
|
||||
{"font-family": '"Source Serif 4", NanumBarunGothic, serif'},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ define-function: (
|
|||
[
|
||||
theme, count_color, desc_color, path_color, bottom_border_color, keyword_color,
|
||||
struct_color, associatedtype_color, tymethod_color, method_color, structfield_color,
|
||||
structfield_hover_color, macro_color, fn_color, hover_path_color, hover_background, grey
|
||||
structfield_hover_color, macro_color, fn_color, hover_path_color, hover_background,
|
||||
attribute_color, grey
|
||||
],
|
||||
block {
|
||||
call-function: ("switch-theme", {"theme": |theme|})
|
||||
|
|
@ -46,6 +47,11 @@ define-function: (
|
|||
"color": |keyword_color|,
|
||||
"hover_color": |keyword_color|,
|
||||
})
|
||||
call-function: ("check-result-color", {
|
||||
"result_kind": "attribute",
|
||||
"color": |attribute_color|,
|
||||
"hover_color": |attribute_color|,
|
||||
})
|
||||
call-function: ("check-result-color", {
|
||||
"result_kind": "struct",
|
||||
"color": |struct_color|,
|
||||
|
|
@ -155,6 +161,7 @@ call-function: ("check-search-color", {
|
|||
"path_color": "#0096cf",
|
||||
"bottom_border_color": "#aaa3",
|
||||
"keyword_color": "#39afd7",
|
||||
"attribute_color": "#39afd7",
|
||||
"struct_color": "#ffa0a5",
|
||||
"associatedtype_color": "#39afd7",
|
||||
"tymethod_color": "#fdd687",
|
||||
|
|
@ -176,6 +183,7 @@ call-function: ("check-search-color", {
|
|||
"path_color": "#ddd",
|
||||
"bottom_border_color": "#aaa3",
|
||||
"keyword_color": "#d2991d",
|
||||
"attribute_color": "#d2991d",
|
||||
"struct_color": "#2dbfb8",
|
||||
"associatedtype_color": "#d2991d",
|
||||
"tymethod_color": "#2bab63",
|
||||
|
|
@ -197,6 +205,7 @@ call-function: ("check-search-color", {
|
|||
"path_color": "#000",
|
||||
"bottom_border_color": "#aaa3",
|
||||
"keyword_color": "#3873ad",
|
||||
"attribute_color": "#3873ad",
|
||||
"struct_color": "#ad378a",
|
||||
"associatedtype_color": "#3873ad",
|
||||
"tymethod_color": "#ad7c37",
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ define-function: (
|
|||
enum_hover_background, union, union_hover, union_hover_background, trait, trait_hover,
|
||||
trait_hover_background, fn, fn_hover, fn_hover_background, type, type_hover,
|
||||
type_hover_background, keyword, keyword_hover, keyword_hover_background,
|
||||
attribute, attribute_hover, attribute_hover_background,
|
||||
],
|
||||
block {
|
||||
call-function: ("switch-theme", {"theme": |theme|})
|
||||
|
|
@ -85,6 +86,16 @@ define-function: (
|
|||
".sidebar .block.keyword a:hover",
|
||||
{"color": |keyword_hover|, "background-color": |keyword_hover_background|},
|
||||
)
|
||||
// Attribute
|
||||
assert-css: (
|
||||
".sidebar .block.attribute a",
|
||||
{"color": |attribute|, "background-color": "rgba(0, 0, 0, 0)"},
|
||||
)
|
||||
move-cursor-to: ".sidebar .block.attribute a"
|
||||
assert-css: (
|
||||
".sidebar .block.attribute a:hover",
|
||||
{"color": |attribute_hover|, "background-color": |attribute_hover_background|},
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -113,6 +124,9 @@ call-function: (
|
|||
"keyword": "#53b1db",
|
||||
"keyword_hover": "#ffb44c",
|
||||
"keyword_hover_background": "transparent",
|
||||
"attribute": "#53b1db",
|
||||
"attribute_hover": "#ffb44c",
|
||||
"attribute_hover_background": "transparent",
|
||||
}
|
||||
)
|
||||
call-function: (
|
||||
|
|
@ -140,6 +154,9 @@ call-function: (
|
|||
"keyword": "#fdbf35",
|
||||
"keyword_hover": "#fdbf35",
|
||||
"keyword_hover_background": "#444",
|
||||
"attribute": "#fdbf35",
|
||||
"attribute_hover": "#fdbf35",
|
||||
"attribute_hover_background": "#444",
|
||||
}
|
||||
)
|
||||
call-function: (
|
||||
|
|
@ -167,5 +184,8 @@ call-function: (
|
|||
"keyword": "#356da4",
|
||||
"keyword_hover": "#356da4",
|
||||
"keyword_hover_background": "#fff",
|
||||
"attribute": "#356da4",
|
||||
"attribute_hover": "#356da4",
|
||||
"attribute_hover_background": "#fff",
|
||||
}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -161,6 +161,10 @@ pub enum AnEnum {
|
|||
/// Some keyword.
|
||||
pub mod keyword {}
|
||||
|
||||
#[doc(attribute = "forbid")]
|
||||
/// Some attribute.
|
||||
pub mod repr {}
|
||||
|
||||
/// Just some type alias.
|
||||
pub type SomeType = u32;
|
||||
|
||||
|
|
|
|||
18
tests/rustdoc-json/doc_attribute.rs
Normal file
18
tests/rustdoc-json/doc_attribute.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
// Doc attributes (`#[doc(attribute = "...")]` should not be generated in rustdoc JSON output
|
||||
// and this test ensures it.
|
||||
|
||||
#![feature(rustdoc_internals)]
|
||||
#![no_std]
|
||||
|
||||
//@ !has "$.index[?(@.name=='repr')]"
|
||||
//@ has "$.index[?(@.name=='foo')]"
|
||||
|
||||
#[doc(attribute = "repr")]
|
||||
/// this is a test!
|
||||
pub mod foo {}
|
||||
|
||||
//@ !has "$.index[?(@.name=='forbid')]"
|
||||
//@ !has "$.index[?(@.name=='bar')]"
|
||||
#[doc(attribute = "forbid")]
|
||||
/// hello
|
||||
mod bar {}
|
||||
10
tests/rustdoc-ui/invalid-attribute.rs
Normal file
10
tests/rustdoc-ui/invalid-attribute.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// Testing the output when an invalid builtin attribute is passed as value
|
||||
// to `doc(attribute = "...")`.
|
||||
|
||||
#![feature(rustdoc_internals)]
|
||||
|
||||
#[doc(attribute = "foo df")] //~ ERROR
|
||||
mod foo {}
|
||||
|
||||
#[doc(attribute = "fooyi")] //~ ERROR
|
||||
mod foo2 {}
|
||||
18
tests/rustdoc-ui/invalid-attribute.stderr
Normal file
18
tests/rustdoc-ui/invalid-attribute.stderr
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
error: nonexistent builtin attribute `foo df` used in `#[doc(attribute = "...")]`
|
||||
--> $DIR/invalid-attribute.rs:6:19
|
||||
|
|
||||
LL | #[doc(attribute = "foo df")]
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= help: only existing builtin attributes are allowed in core/std
|
||||
|
||||
error: nonexistent builtin attribute `fooyi` used in `#[doc(attribute = "...")]`
|
||||
--> $DIR/invalid-attribute.rs:9:19
|
||||
|
|
||||
LL | #[doc(attribute = "fooyi")]
|
||||
| ^^^^^^^
|
||||
|
|
||||
= help: only existing builtin attributes are allowed in core/std
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
24
tests/rustdoc/doc-attribute.rs
Normal file
24
tests/rustdoc/doc-attribute.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// Test checking the `#[doc(attribute = "...")]` attribute.
|
||||
|
||||
#![crate_name = "foo"]
|
||||
|
||||
#![feature(rustdoc_internals)]
|
||||
|
||||
//@ has foo/index.html '//h2[@id="attributes"]' 'Attributes'
|
||||
//@ has foo/index.html '//a[@href="attribute.no_mangle.html"]' 'no_mangle'
|
||||
//@ has foo/index.html '//div[@class="sidebar-elems"]//li/a' 'Attributes'
|
||||
//@ has foo/index.html '//div[@class="sidebar-elems"]//li/a/@href' '#attributes'
|
||||
//@ has foo/attribute.no_mangle.html '//h1' 'Attribute no_mangle'
|
||||
//@ has foo/attribute.no_mangle.html '//section[@id="main-content"]//div[@class="docblock"]//p' 'this is a test!'
|
||||
//@ has foo/index.html '//a/@href' '../foo/index.html'
|
||||
//@ !has foo/foo/index.html
|
||||
//@ !has-dir foo/foo
|
||||
//@ !has foo/index.html '//span' '🔒'
|
||||
#[doc(attribute = "no_mangle")]
|
||||
/// this is a test!
|
||||
mod foo{}
|
||||
|
||||
//@ has foo/attribute.repr.html '//section[@id="main-content"]//div[@class="docblock"]//p' 'hello'
|
||||
#[doc(attribute = "repr")]
|
||||
/// hello
|
||||
mod bar {}
|
||||
|
|
@ -2,6 +2,10 @@
|
|||
/// wonderful
|
||||
mod foo {}
|
||||
|
||||
#[doc(attribute = "repr")] //~ ERROR: `#[doc(attribute)]` is meant for internal use only
|
||||
/// wonderful
|
||||
mod foo2 {}
|
||||
|
||||
trait Mine {}
|
||||
|
||||
#[doc(fake_variadic)] //~ ERROR: `#[doc(fake_variadic)]` is meant for internal use only
|
||||
|
|
|
|||
|
|
@ -8,8 +8,18 @@ LL | #[doc(keyword = "match")]
|
|||
= help: add `#![feature(rustdoc_internals)]` to the crate attributes to enable
|
||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||
|
||||
error[E0658]: `#[doc(attribute)]` is meant for internal use only
|
||||
--> $DIR/feature-gate-rustdoc_internals.rs:5:1
|
||||
|
|
||||
LL | #[doc(attribute = "repr")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #90418 <https://github.com/rust-lang/rust/issues/90418> for more information
|
||||
= help: add `#![feature(rustdoc_internals)]` to the crate attributes to enable
|
||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||
|
||||
error[E0658]: `#[doc(fake_variadic)]` is meant for internal use only
|
||||
--> $DIR/feature-gate-rustdoc_internals.rs:7:1
|
||||
--> $DIR/feature-gate-rustdoc_internals.rs:11:1
|
||||
|
|
||||
LL | #[doc(fake_variadic)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -19,7 +29,7 @@ LL | #[doc(fake_variadic)]
|
|||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||
|
||||
error[E0658]: `#[doc(search_unbox)]` is meant for internal use only
|
||||
--> $DIR/feature-gate-rustdoc_internals.rs:10:1
|
||||
--> $DIR/feature-gate-rustdoc_internals.rs:14:1
|
||||
|
|
||||
LL | #[doc(search_unbox)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -28,6 +38,6 @@ LL | #[doc(search_unbox)]
|
|||
= help: add `#![feature(rustdoc_internals)]` to the crate attributes to enable
|
||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue