about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorJoshua Nelson <jyn514@gmail.com>2020-12-06 17:56:01 -0500
committerJoshua Nelson <jyn514@gmail.com>2021-02-11 17:16:43 -0500
commit02ffe9ef0101cb7b0540ca6195d63442ad3df5ec (patch)
tree91e4de5c6f751868c0e1310f4213071fb4159d5e /src/test
parent178108bf81606a0e25b1066568c2b8c8e0648617 (diff)
Fix injected errors when running doctests on a crate named after a keyword
Unfortunately, this can't currently be tested. The problem is that we
need the file to be compiled first to then be used as dependency, which
cannot be done currently unfortunately in the rustdoc test suites.
Example:

```rust
// name this file "foo.rs"

/// ```
/// let x = foo::foo();
/// ```
pub fn foo() {}
```

If you run `rustdoc --test foo.rs`, you'll get:

```
running 1 test
test foo.rs - foo (line 1) ... FAILED

failures:

---- foo.rs - foo (line 1) stdout ----
error[E0463]: can't find crate for `foo`
 --> foo.rs:0:1
  |
2 | extern crate foo;
  | ^^^^^^^^^^^^^^^^^ can't find crate
```

If a test were possible, it would look something like

 ````rust
 #![crate_name = "mod"]
 #![crate_type = "lib"]
 //! ```
 //! // NOTE: requires that the literal string 'mod' appears in the doctest for
 //! // the bug to appear
 //! assert_eq!(1, 1);
 //! ```
 ````
Diffstat (limited to 'src/test')
-rw-r--r--src/test/rustdoc/playground-arg.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/test/rustdoc/playground-arg.rs b/src/test/rustdoc/playground-arg.rs
index 018716ad45a..dbe2297f818 100644
--- a/src/test/rustdoc/playground-arg.rs
+++ b/src/test/rustdoc/playground-arg.rs
@@ -11,4 +11,4 @@
 pub fn dummy() {}
 
 // ensure that `extern crate foo;` was inserted into code snips automatically:
-// @matches foo/index.html '//a[@class="test-arrow"][@href="https://example.com/?code=%23!%5Ballow(unused)%5D%0Aextern%20crate%20foo%3B%0Afn%20main()%20%7B%0Ause%20foo%3A%3Adummy%3B%0Adummy()%3B%0A%7D&edition=2015"]' "Run"
+// @matches foo/index.html '//a[@class="test-arrow"][@href="https://example.com/?code=%23!%5Ballow(unused)%5D%0Aextern%20crate%20r%23foo%3B%0Afn%20main()%20%7B%0Ause%20foo%3A%3Adummy%3B%0Adummy()%3B%0A%7D&edition=2015"]' "Run"