Skip to content

Commit 07871bd

Browse files
Add tests for attribute bang macros in rustdoc
1 parent 3552177 commit 07871bd

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

tests/rustdoc-gui/attr-macros.goml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// This test ensures that a bang macro which is also an attribute macro is listed correctly in
2+
// the sidebar and in the module.
3+
4+
go-to: "file://" + |DOC_PATH| + "/test_docs/macro.b.html"
5+
// It should be present twice in the sidebar.
6+
assert-count: ("#rustdoc-modnav a[href='macro.attr_macro.html']", 2)
7+
assert-count: ("//*[@id='rustdoc-modnav']//a[text()='attr_macro']", 2)
8+
// We check that the current item in the sidebar is the correct one.
9+
assert-text: ("#rustdoc-modnav .block.macro .current", "b")
10+
11+
// We now go to the attribute macro page.
12+
click: "#rustdoc-modnav a[href='macro.attr_macro.html']"
13+
// It should be present twice in the sidebar.
14+
assert-count: ("#rustdoc-modnav a[href='macro.attr_macro.html']", 2)
15+
assert-count: ("//*[@id='rustdoc-modnav']//a[text()='attr_macro']", 2)
16+
// We check that the current item is the "attr_macro".
17+
assert-text: ("#rustdoc-modnav .block.macro .current", "attr_macro")
18+
// Since the item is present twice in the sidebar, we should have two "current" items.
19+
assert-count: ("#rustdoc-modnav .current", 2)
20+
// We check it has the expected information.
21+
assert-text: ("h3.macro-info", "ⓘ This is an attribute/function macro")
22+
23+
// Now we check it's correctly listed in the crate page.
24+
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html"
25+
// It should be only present twice.
26+
assert-count: ("#main-content a[href='macro.attr_macro.html']", 2)
27+
// First in the "Macros" section.
28+
assert-text: ("#macros + .item-table a[href='macro.attr_macro.html']", "attr_macro")
29+
// Then in the "Attribute Macros" section.
30+
assert-text: ("#attributes + .item-table a[href='macro.attr_macro.html']", "attr_macro")
31+
32+
// And finally we check it's correctly listed in the "all items" page.
33+
go-to: "file://" + |DOC_PATH| + "/test_docs/all.html"
34+
// It should be only present twice.
35+
assert-count: ("#main-content a[href='macro.attr_macro.html']", 2)
36+
// First in the "Macros" section.
37+
assert-text: ("#macros + .all-items a[href='macro.attr_macro.html']", "attr_macro")
38+
// Then in the "Attribute Macros" section.
39+
assert-text: ("#attributes + .all-items a[href='macro.attr_macro.html']", "attr_macro")

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#![feature(rustdoc_internals)]
88
#![feature(doc_cfg)]
99
#![feature(associated_type_defaults)]
10+
#![feature(macro_attr)]
1011

1112
/*!
1213
Enable the feature <span class="stab portability"><code>some-feature</code></span> to enjoy

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,10 @@
22
macro_rules! a{ () => {}}
33
#[macro_export]
44
macro_rules! b{ () => {}}
5+
6+
// An attribute bang macro.
7+
#[macro_export]
8+
macro_rules! attr_macro {
9+
attr() () => {};
10+
() => {};
11+
}

0 commit comments

Comments
 (0)