From 9f965bcf76f2fb5128b41e2e898e2d7ed537c72c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 14 Jan 2026 00:45:39 +0100 Subject: [PATCH] Add rustdoc GUI test to ensure that the "hide deprecated items" setting is working as expected --- .../rustdoc-gui/setting-hide-deprecated.goml | 83 +++++++++++++++++++ tests/rustdoc-gui/src/lib2/lib.rs | 43 ++++++++++ tests/rustdoc-gui/utils.goml | 12 ++- 3 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 tests/rustdoc-gui/setting-hide-deprecated.goml diff --git a/tests/rustdoc-gui/setting-hide-deprecated.goml b/tests/rustdoc-gui/setting-hide-deprecated.goml new file mode 100644 index 000000000000..77f84493c67b --- /dev/null +++ b/tests/rustdoc-gui/setting-hide-deprecated.goml @@ -0,0 +1,83 @@ +// Test that the "hide deprecated" setting is correctly handled. + +include: "utils.goml" + +go-to: "file://" + |DOC_PATH| + "/lib2/deprecated/index.html" + +// There should be two deprecated items listed on the module page: +// `DeprecatedStruct` and `DeprecatedTrait`. +assert-count: ("dt.deprecated", 2) +// `DeprecatedStruct` and `DeprecatedTrait` should be displayed for now. +assert-css: ("dt.deprecated", {"display": "block"}, ALL) + +// We enable the "hide deprecated items" setting. +call-function: ("open-settings-menu", {}) +click: "#hide-deprecated-items" +// None of them should be displayed anymore. +wait-for-css: ("dt.deprecated", {"display": "none"}, ALL) + +// We disable the setting. +click: "#hide-deprecated-items" +// All of them should be displayed back. +wait-for-css: ("dt.deprecated", {"display": "block"}, ALL) + +// Now we go to a trait with a deprecated method and a deprecated associated const. +go-to: "file://" + |DOC_PATH| + "/lib2/deprecated/trait.NormalTrait.html" + +// There should be two deprecated items. +assert-count: ("details.deprecated", 2) +// They should be displayed for now. +assert-css: ("details.deprecated", {"display": "block"}, ALL) + +// We enable the "hide deprecated items" setting. +call-function: ("open-settings-menu", {}) +click: "#hide-deprecated-items" + +// They shouldn't be displayed anymore. +wait-for-css: ("details.deprecated", {"display": "none"}, ALL) + +// We disable the setting. +click: "#hide-deprecated-items" +// All of them should be displayed back. +wait-for-css: ("details.deprecated", {"display": "block"}, ALL) + +// We now go to a struct with a deprecated method which implements a deprecated trait and a trait +// with deprecated associated items. +go-to: "file://" + |DOC_PATH| + "/lib2/deprecated/struct.NonDeprecatedStruct.html" + +// There should be five deprecated items (six minus one "future" deprecated)... +assert-count: ("details.deprecated", 5) +// One of which being a deprecated impl because the trait itself is deprecated. +assert-count: ("details.implementors-toggle.deprecated", 1) +// And another has `since = "TBD"` and should NOT have the `deprecated` class. +assert: "details:not(.deprecated) #method\.future_deprecated_fn" +// They should all be displayed for now. +assert-css: ("details.deprecated", {"display": "block"}, ALL) + +// We enable the "hide deprecated items" setting. +call-function: ("open-settings-menu", {}) +click: "#hide-deprecated-items" + +// They shouldn't be displayed anymore. +wait-for-css: ("details.deprecated", {"display": "none"}, ALL) + +// We disable the setting. +click: "#hide-deprecated-items" +// All of them should be displayed back. +wait-for-css: ("details.deprecated", {"display": "block"}, ALL) + +// And now we check with the search results. +call-function: ("perform-search", {"query": "deprecated::depr"}) +// There should at least 7 results. +store-count: ("#results ul.search-results.active > a", nb_search_results) +assert: |nb_search_results| >= 7 +// There should be at least 5 deprecated items. +store-count: ("#results ul.search-results.active > a.deprecated", nb_deprecated_results) +assert: |nb_search_results| >= 5 +// Deprecated items should all be displayed. +assert-css: ("#results ul.search-results.active > a.deprecated", {"display": "grid"}, ALL) +// We enable the "hide deprecated items" setting. +call-function: ("open-settings-menu", {}) +click: "#hide-deprecated-items" +// None of them should be displayed anymore. +wait-for-css: ("#results ul.search-results.active > a.deprecated", {"display": "none"}, ALL) diff --git a/tests/rustdoc-gui/src/lib2/lib.rs b/tests/rustdoc-gui/src/lib2/lib.rs index b87fdeea89da..1367b17b37b2 100644 --- a/tests/rustdoc-gui/src/lib2/lib.rs +++ b/tests/rustdoc-gui/src/lib2/lib.rs @@ -368,3 +368,46 @@ impl std::ops::Deref for Derefer { &self.0 } } + +pub mod deprecated { + #[deprecated(since = "1.26.0", note = "deprecated")] + pub struct DeprecatedStruct; + + pub struct NonDeprecatedStruct; + + pub trait NormalTrait { + #[deprecated(since = "1.26.0", note = "deprecated")] + /// doc + const X: usize = 12; + + #[deprecated(since = "1.26.0", note = "deprecated")] + /// doc + fn normal_deprecated_fn(); + } + + #[deprecated(since = "1.26.0", note = "deprecated")] + pub trait DeprecatedTrait { + fn depr_deprecated_fn(); + } + + impl NonDeprecatedStruct { + #[deprecated(since = "1.26.0", note = "deprecated")] + /// doc + pub fn deprecated_fn() {} + + /// doc + pub fn non_deprecated_fn() {} + + #[deprecated(since = "TBD", note = "deprecated")] + /// doc + pub fn future_deprecated_fn() {} + } + + impl NormalTrait for NonDeprecatedStruct { + fn normal_deprecated_fn() {} + } + + impl DeprecatedTrait for NonDeprecatedStruct { + fn depr_deprecated_fn() {} + } +} diff --git a/tests/rustdoc-gui/utils.goml b/tests/rustdoc-gui/utils.goml index c0625ead2f1a..29f1af293d6d 100644 --- a/tests/rustdoc-gui/utils.goml +++ b/tests/rustdoc-gui/utils.goml @@ -60,8 +60,8 @@ define-function: ( ) define-function: ( - "perform-search", - [query], + "open-search", + [], block { // Block requests with doubled `//`. // Amazon S3 doesn't support them, but other web hosts do, @@ -72,6 +72,14 @@ define-function: ( // Perform search click: "#search-button" wait-for: ".search-input" + } +) + +define-function: ( + "perform-search", + [query], + block { + call-function: ("open-search", {}) write-into: (".search-input", |query|) press-key: 'Enter' // wait for the search to start