Skip to content

Commit 53580da

Browse files
authored
Rollup merge of #113857 - GuillaumeGomez:document-hidden-items-test, r=notriddle
Add tests for `--document-hidden-items` option Since `--document-hidden-items` was greatly fixed/improved in #113574, thought it might be worth adding some more tests for it to prevent new regressions. As for the first commit, it allows to go from: ``` Traceback (most recent call last): File "/home/imperio/rust/rust/src/etc/htmldocck.py", line 706, in <module> check(sys.argv[1], get_commands(rust_test_path)) File "/home/imperio/rust/rust/src/etc/htmldocck.py", line 689, in check for c in commands: File "/home/imperio/rust/rust/src/etc/htmldocck.py", line 274, in get_commands args = shlex.split(args) File "/usr/lib/python3.10/shlex.py", line 315, in split return list(lex) File "/usr/lib/python3.10/shlex.py", line 300, in __next__ token = self.get_token() File "/usr/lib/python3.10/shlex.py", line 109, in get_token raw = self.read_token() File "/usr/lib/python3.10/shlex.py", line 191, in read_token raise ValueError("No closing quotation") ValueError: No closing quotation ``` to: ``` Traceback (most recent call last): File "/home/imperio/rust/rust/src/etc/htmldocck.py", line 708, in <module> check(sys.argv[1], get_commands(rust_test_path)) File "/home/imperio/rust/rust/src/etc/htmldocck.py", line 691, in check for c in commands: File "/home/imperio/rust/rust/src/etc/htmldocck.py", line 278, in get_commands raise Exception("line {}: {}".format(lineno + 1, exc)) from None Exception: line 57: No closing quotation ``` Having the line where the error occurred is quite useful. r? `@notriddle`
2 parents b128750 + d9753d7 commit 53580da

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

src/etc/htmldocck.py

+2
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ def get_commands(template):
274274
args = shlex.split(args)
275275
except UnicodeEncodeError:
276276
args = [arg.decode('utf-8') for arg in shlex.split(args.encode('utf-8'))]
277+
except Exception as exc:
278+
raise Exception("line {}: {}".format(lineno + 1, exc)) from None
277279
yield Command(negated=negated, cmd=cmd, args=args, lineno=lineno+1, context=line)
278280

279281

tests/rustdoc/display-hidden-items.rs

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Test to ensure that the `--document-hidden-items` option is working as expected.
2+
// compile-flags: -Z unstable-options --document-hidden-items
3+
// ignore-tidy-linelength
4+
5+
#![crate_name = "foo"]
6+
7+
// @has 'foo/index.html'
8+
// @has - '//*[@id="reexport.hidden_reexport"]/code' 'pub use hidden::inside_hidden as hidden_reexport;'
9+
#[doc(hidden)]
10+
pub use hidden::inside_hidden as hidden_reexport;
11+
12+
// @has - '//*[@class="item-name"]/a[@class="trait"]' 'TraitHidden'
13+
// @has 'foo/trait.TraitHidden.html'
14+
#[doc(hidden)]
15+
pub trait TraitHidden {}
16+
17+
// @has 'foo/index.html' '//*[@class="item-name"]/a[@class="trait"]' 'Trait'
18+
pub trait Trait {
19+
// @has 'foo/trait.Trait.html'
20+
// @has - '//*[@id="associatedconstant.BAR"]/*[@class="code-header"]' 'const BAR: u32 = 0u32'
21+
#[doc(hidden)]
22+
const BAR: u32 = 0;
23+
24+
// @has - '//*[@id="method.foo"]/*[@class="code-header"]' 'fn foo()'
25+
#[doc(hidden)]
26+
fn foo() {}
27+
}
28+
29+
// @has 'foo/index.html' '//*[@class="item-name"]/a[@class="struct"]' 'Struct'
30+
// @has 'foo/struct.Struct.html'
31+
pub struct Struct {
32+
// @has - '//*[@id="structfield.a"]/code' 'a: u32'
33+
#[doc(hidden)]
34+
pub a: u32,
35+
}
36+
37+
impl Struct {
38+
// @has - '//*[@id="method.new"]/*[@class="code-header"]' 'pub fn new() -> Self'
39+
#[doc(hidden)]
40+
pub fn new() -> Self { Self { a: 0 } }
41+
}
42+
43+
impl Trait for Struct {
44+
// @has - '//*[@id="associatedconstant.BAR"]/*[@class="code-header"]' 'const BAR: u32 = 0u32'
45+
// @has - '//*[@id="method.foo"]/*[@class="code-header"]' 'fn foo()'
46+
}
47+
// @has - '//*[@id="impl-TraitHidden-for-Struct"]/*[@class="code-header"]' 'impl TraitHidden for Struct'
48+
impl TraitHidden for Struct {}
49+
50+
// @has 'foo/index.html' '//*[@class="item-name"]/a[@class="enum"]' 'HiddenEnum'
51+
// @has 'foo/enum.HiddenEnum.html'
52+
#[doc(hidden)]
53+
pub enum HiddenEnum {
54+
A,
55+
}
56+
57+
// @has 'foo/index.html' '//*[@class="item-name"]/a[@class="enum"]' 'Enum'
58+
pub enum Enum {
59+
// @has 'foo/enum.Enum.html' '//*[@id="variant.A"]/*[@class="code-header"]' 'A'
60+
#[doc(hidden)]
61+
A,
62+
}
63+
64+
// @has 'foo/index.html' '//*[@class="item-name"]/a[@class="mod"]' 'hidden'
65+
#[doc(hidden)]
66+
pub mod hidden {
67+
// @has 'foo/hidden/index.html'
68+
// @has - '//*[@class="item-name"]/a[@class="fn"]' 'inside_hidden'
69+
// @has 'foo/hidden/fn.inside_hidden.html'
70+
pub fn inside_hidden() {}
71+
}

0 commit comments

Comments
 (0)