Skip to content

Commit 1fe45dd

Browse files
Add rustdoc GUI test to ensure that the "hide deprecated items" setting is working as expected
1 parent 5e3fc6b commit 1fe45dd

3 files changed

Lines changed: 130 additions & 2 deletions

File tree

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Test that the "hide deprecated" setting is correctly handled.
2+
3+
include: "utils.goml"
4+
5+
go-to: "file://" + |DOC_PATH| + "/lib2/deprecated/index.html"
6+
7+
// There should be two deprecated items listed on the module page:
8+
// `DeprecatedStruct` and `DeprecatedTrait`.
9+
assert-count: ("dt.deprecated", 2)
10+
// `DeprecatedStruct` and `DeprecatedTrait` should be displayed for now.
11+
assert-css: ("dt.deprecated", {"display": "block"}, ALL)
12+
13+
// We enable the "hide deprecated items" setting.
14+
call-function: ("open-settings-menu", {})
15+
click: "#hide-deprecated-items"
16+
// None of them should be displayed anymore.
17+
wait-for-css: ("dt.deprecated", {"display": "none"}, ALL)
18+
19+
// We disable the setting.
20+
click: "#hide-deprecated-items"
21+
// All of them should be displayed back.
22+
wait-for-css: ("dt.deprecated", {"display": "block"}, ALL)
23+
24+
// Now we go to a trait with a deprecated method and a deprecated associated const.
25+
go-to: "file://" + |DOC_PATH| + "/lib2/deprecated/trait.NormalTrait.html"
26+
27+
// There should be two deprecated items.
28+
assert-count: ("details.deprecated", 2)
29+
// They should be displayed for now.
30+
assert-css: ("details.deprecated", {"display": "block"}, ALL)
31+
32+
// We enable the "hide deprecated items" setting.
33+
call-function: ("open-settings-menu", {})
34+
click: "#hide-deprecated-items"
35+
36+
// They shouldn't be displayed anymore.
37+
wait-for-css: ("details.deprecated", {"display": "none"}, ALL)
38+
39+
// We disable the setting.
40+
click: "#hide-deprecated-items"
41+
// All of them should be displayed back.
42+
wait-for-css: ("details.deprecated", {"display": "block"}, ALL)
43+
44+
// We now go to a struct with a deprecated method which implements a deprecated trait and a trait
45+
// with deprecated associated items.
46+
go-to: "file://" + |DOC_PATH| + "/lib2/deprecated/struct.NonDeprecatedStruct.html"
47+
48+
// There should be five deprecated items...
49+
assert-count: ("details.deprecated", 5)
50+
// One of which being a deprecated impl because the trait itself is deprecated.
51+
assert-count: ("details.implementors-toggle.deprecated", 1)
52+
// They should all be displayed for now.
53+
assert-css: ("details.deprecated", {"display": "block"}, ALL)
54+
55+
// We enable the "hide deprecated items" setting.
56+
call-function: ("open-settings-menu", {})
57+
click: "#hide-deprecated-items"
58+
59+
// They shouldn't be displayed anymore.
60+
wait-for-css: ("details.deprecated", {"display": "none"}, ALL)
61+
62+
// We disable the setting.
63+
click: "#hide-deprecated-items"
64+
// All of them should be displayed back.
65+
wait-for-css: ("details.deprecated", {"display": "block"}, ALL)
66+
67+
// And now we check with the search results.
68+
call-function: ("perform-search", {"query": "deprecated::depr"})
69+
// There should at least 7 results.
70+
store-count: ("#results ul.search-results.active > a", nb_search_results)
71+
assert: |nb_search_results| >= 7
72+
// There should be at least 5 deprecated items.
73+
store-count: ("#results ul.search-results.active > a.deprecated", nb_deprecated_results)
74+
assert: |nb_search_results| >= 5
75+
// Deprecated items should all be displayed.
76+
assert-css: ("#results ul.search-results.active > a.deprecated", {"display": "grid"}, ALL)
77+
// We enable the "hide deprecated items" setting.
78+
call-function: ("open-settings-menu", {})
79+
click: "#hide-deprecated-items"
80+
// None of them should be displayed anymore.
81+
wait-for-css: ("#results ul.search-results.active > a.deprecated", {"display": "none"}, ALL)

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,3 +368,42 @@ impl std::ops::Deref for Derefer {
368368
&self.0
369369
}
370370
}
371+
372+
pub mod deprecated {
373+
#[deprecated(since = "1.26.0", note = "deprecated")]
374+
pub struct DeprecatedStruct;
375+
376+
pub struct NonDeprecatedStruct;
377+
378+
pub trait NormalTrait {
379+
#[deprecated(since = "1.26.0", note = "deprecated")]
380+
/// doc
381+
const X: usize = 12;
382+
383+
#[deprecated(since = "1.26.0", note = "deprecated")]
384+
/// doc
385+
fn normal_deprecated_fn();
386+
}
387+
388+
#[deprecated(since = "1.26.0", note = "deprecated")]
389+
pub trait DeprecatedTrait {
390+
fn depr_deprecated_fn();
391+
}
392+
393+
impl NonDeprecatedStruct {
394+
#[deprecated(since = "1.26.0", note = "deprecated")]
395+
/// doc
396+
pub fn deprecated_fn() {}
397+
398+
/// doc
399+
pub fn non_deprecated_fn() {}
400+
}
401+
402+
impl NormalTrait for NonDeprecatedStruct {
403+
fn normal_deprecated_fn() {}
404+
}
405+
406+
impl DeprecatedTrait for NonDeprecatedStruct {
407+
fn depr_deprecated_fn() {}
408+
}
409+
}

tests/rustdoc-gui/utils.goml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ define-function: (
6060
)
6161

6262
define-function: (
63-
"perform-search",
64-
[query],
63+
"open-search",
64+
[],
6565
block {
6666
// Block requests with doubled `//`.
6767
// Amazon S3 doesn't support them, but other web hosts do,
@@ -72,6 +72,14 @@ define-function: (
7272
// Perform search
7373
click: "#search-button"
7474
wait-for: ".search-input"
75+
}
76+
)
77+
78+
define-function: (
79+
"perform-search",
80+
[query],
81+
block {
82+
call-function: ("open-search", {})
7583
write-into: (".search-input", |query|)
7684
press-key: 'Enter'
7785
// wait for the search to start

0 commit comments

Comments
 (0)