Skip to content

Commit

Permalink
rustdoc: Fix incorrect usage of @!has and @!matches
Browse files Browse the repository at this point in the history
`@!has` (and `@!matches`) with two arguments used to treat the second
argument as a literal string of HTML code. Now, that feature has been
renamed into `@!hasraw` (and `@!matchesraw`), and the arity-2 `@!has`
version is an error.

These uses thought the second argument was being treated as an XPath, as
with the arity-3 version, but in fact was being treated as literal HTML.
Because these were checking for the *absence* of the string, the tests
silently did nothing -- an XPath string won't ever be showing up in the
test's generated HTML!
  • Loading branch information
camelid committed Aug 13, 2022
1 parent b34e240 commit 0d588e9
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 22 deletions.
14 changes: 8 additions & 6 deletions src/test/rustdoc/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

// Check that the unstable marker is not added for "rustc_private".

// @!matchesraw internal/index.html \
// '//*[@class="item-right docblock-short"]/span[@class="stab unstable"]'
// @!matchesraw internal/index.html \
// '//*[@class="item-right docblock-short"]/span[@class="stab internal"]'
// @!matches internal/index.html \
// '//*[@class="item-right docblock-short"]/span[@class="stab unstable"]' \
// ''
// @!matches internal/index.html \
// '//*[@class="item-right docblock-short"]/span[@class="stab internal"]' \
// ''
// @matches - '//*[@class="item-right docblock-short"]' 'Docs'

// @!hasraw internal/struct.S.html '//*[@class="stab unstable"]'
// @!hasraw internal/struct.S.html '//*[@class="stab internal"]'
// @!has internal/struct.S.html '//*[@class="stab unstable"]' ''
// @!has internal/struct.S.html '//*[@class="stab internal"]' ''
/// Docs
pub struct S;

Expand Down
4 changes: 2 additions & 2 deletions src/test/rustdoc/issue-61592.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ extern crate foo;
// @has issue_61592/index.html
// @has - '//a[@href="#reexports"]' 'Re-exports'
// @has - '//code' 'pub use foo::FooTrait as _;'
// @!hasraw - '//a[@href="trait._.html"]'
// @!has - '//a[@href="trait._.html"]' ''
pub use foo::FooTrait as _;

// @has issue_61592/index.html
// @has - '//a[@href="#reexports"]' 'Re-exports'
// @has - '//code' 'pub use foo::FooStruct as _;'
// @!hasraw - '//a[@href="struct._.html"]'
// @!has - '//a[@href="struct._.html"]' ''
pub use foo::FooStruct as _;
2 changes: 1 addition & 1 deletion src/test/rustdoc/no-crate-filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

// compile-flags: -Z unstable-options --disable-per-crate-search

// @!hasraw 'foo/struct.Foo.html' '//*[id="crate-search"]'
// @!has 'foo/struct.Foo.html' '//*[id="crate-search"]' ''
pub struct Foo;
8 changes: 4 additions & 4 deletions src/test/rustdoc/recursive-deref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl G {

// @has recursive_deref/struct.D.html '//h3[@class="code-header in-band"]' 'impl Deref for D'
// We also check that `G::g` method isn't rendered because there is no `self` argument.
// @!hasraw '-' '//*[@id="deref-methods-G"]'
// @!has '-' '//*[@id="deref-methods-G"]' ''
impl Deref for D {
type Target = E;

Expand All @@ -62,7 +62,7 @@ impl Deref for D {

// @has recursive_deref/struct.E.html '//h3[@class="code-header in-band"]' 'impl Deref for E'
// We also check that `G::g` method isn't rendered because there is no `self` argument.
// @!hasraw '-' '//*[@id="deref-methods-G"]'
// @!has '-' '//*[@id="deref-methods-G"]' ''
impl Deref for E {
type Target = F;

Expand All @@ -73,7 +73,7 @@ impl Deref for E {

// @has recursive_deref/struct.F.html '//h3[@class="code-header in-band"]' 'impl Deref for F'
// We also check that `G::g` method isn't rendered because there is no `self` argument.
// @!hasraw '-' '//*[@id="deref-methods-G"]'
// @!has '-' '//*[@id="deref-methods-G"]' ''
impl Deref for F {
type Target = G;

Expand Down Expand Up @@ -101,7 +101,7 @@ impl I {
}

// @has recursive_deref/struct.H.html '//h3[@class="code-header in-band"]' 'impl Deref for H'
// @!hasraw '-' '//*[@id="deref-methods-I"]'
// @!has '-' '//*[@id="deref-methods-I"]' ''
impl Deref for H {
type Target = I;

Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc/remove-url-from-headings.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![crate_name = "foo"]

// @has foo/fn.foo.html
// @!hasraw - '//a[@href="http://a.a"]'
// @!has - '//a[@href="http://a.a"]' ''
// @has - '//a[@href="#implementing-stuff-somewhere"]' 'Implementing stuff somewhere'
// @has - '//a[@href="#another-one-urg"]' 'Another one urg'

Expand Down
4 changes: 2 additions & 2 deletions src/test/rustdoc/sized_trait.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#![crate_name = "foo"]

// @has foo/struct.Bar.html
// @!hasraw - '//*[@id="impl-Sized"]'
// @!has - '//*[@id="impl-Sized"]' ''
pub struct Bar {
a: u16,
}

// @has foo/struct.Foo.html
// @!hasraw - '//*[@id="impl-Sized"]'
// @!has - '//*[@id="impl-Sized"]' ''
pub struct Foo<T: ?Sized>(T);

// @has foo/struct.Unsized.html
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc/table-in-docblock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// @has foo/struct.Foo.html
// @count - '//*[@class="docblock"]/div/table' 2
// @!hasraw - '//*[@class="docblock"]/table'
// @!has - '//*[@class="docblock"]/table' ''
/// | hello | hello2 |
/// | ----- | ------ |
/// | data | data2 |
Expand Down
4 changes: 2 additions & 2 deletions src/test/rustdoc/toggle-item-contents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub struct PrivStruct {
}

// @has 'toggle_item_contents/enum.Enum.html'
// @!hasraw - '//details[@class="rustdoc-toggle type-contents-toggle"]'
// @!has - '//details[@class="rustdoc-toggle type-contents-toggle"]' ''
pub enum Enum {
A, B, C,
D {
Expand All @@ -72,7 +72,7 @@ pub enum Enum {
}

// @has 'toggle_item_contents/enum.EnumStructVariant.html'
// @!hasraw - '//details[@class="rustdoc-toggle type-contents-toggle"]'
// @!has - '//details[@class="rustdoc-toggle type-contents-toggle"]' ''
pub enum EnumStructVariant {
A, B, C,
D {
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc/trait-impl-items-links-and-anchors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub struct MyStruct;

// We check that associated items with default values aren't generated in the implementors list.
impl MyTrait for (u8, u8) {
// @!hasraw trait_impl_items_links_and_anchors/trait.MyTrait.html '//div[@id="associatedconstant.VALUE-4"]'
// @!has trait_impl_items_links_and_anchors/trait.MyTrait.html '//div[@id="associatedconstant.VALUE-4"]' ''
type Assoc = bool;
fn trait_function(&self) {}
}
2 changes: 1 addition & 1 deletion src/test/rustdoc/trait-impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl Trait for Struct {
fn c() {}

// @has - '//*[@id="method.d"]/../../div[@class="docblock"]/p' 'Escaped formatting a*b*c* works'
// @!hasraw - '//*[@id="method.d"]/../../div[@class="docblock"]/p/em'
// @!has - '//*[@id="method.d"]/../../div[@class="docblock"]/p/em' ''
fn d() {}

// @has - '//*[@id="impl-Trait-for-Struct"]/h3//a/@href' 'trait.Trait.html'
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc/tuple-struct-fields-doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// @has - '//h3[@class="sidebar-title"]/a[@href="#fields"]' 'Tuple Fields'
// @has - '//*[@id="structfield.0"]' '0: u32'
// @has - '//*[@id="main-content"]/div[@class="docblock"]' 'hello'
// @!hasraw - '//*[@id="structfield.1"]'
// @!has - '//*[@id="structfield.1"]' ''
// @has - '//*[@id="structfield.2"]' '2: char'
// @has - '//*[@id="structfield.3"]' '3: i8'
// @has - '//*[@id="main-content"]/div[@class="docblock"]' 'not hello'
Expand Down

0 comments on commit 0d588e9

Please sign in to comment.