Skip to content

Commit

Permalink
added rustdoc book documentation, improved behavior when unstable fla…
Browse files Browse the repository at this point in the history
…g not present
  • Loading branch information
Goirad committed Jun 19, 2019
1 parent 994144f commit 5b597b2
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 10 deletions.
50 changes: 50 additions & 0 deletions src/doc/rustdoc/src/unstable-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,3 +455,53 @@ Some methodology notes about what rustdoc counts in this metric:

Public items that are not documented can be seen with the built-in `missing_docs` lint. Private
items that are not documented can be seen with Clippy's `missing_docs_in_private_items` lint.

### `--enable-per-target-ignores`: allow `ignore-foo` style filters for doctests

Using this flag looks like this:

```bash
$ rustdoc src/lib.rs -Z unstable-options --enable-per-target-ignores
```

This flag allows you to tag doctests with compiltest style `ignore-foo` filters that prevent
rustdoc from running that test if the target triple string contains foo. For example:

```rust
///```ignore-foo,ignore-bar
///assert!(2 == 2);
///```
struct Foo;
```

This will not be run when the build target is `super-awesome-foo` or `less-bar-awesome`.
If the flag is not enabled, then rustdoc will consume the filter, but do nothing with it, and
the above example will be run for all targets.
If you want to preserve backwards compatibility for older versions of rustdoc, you can use

```rust
///```ignore,ignore-foo
///assert!(2 == 2);
///```
struct Foo;
```

In older versions, this will be ignored on all targets, but on newer versions `ignore-gnu` will
override `ignore`.

### `--runtool`, `--runtool-arg`: program to run tests with; args to pass to it

Using thses options looks like this:

```bash
$ rustdoc src/lib.rs -Z unstable-options --runtool runner --runtool-arg --do-thing --runtool-arg --do-other-thing
```

These options can be used to run the doctest under a program, and also pass arguments to
that program. For example, if you want to run your doctests under valgrind you might run

```bash
$ rustdoc src/lib.rs -Z unstable-options --runtool valgrind
```

Another use case would be to run a test inside an emulator, or through a Virtual Machine.
14 changes: 4 additions & 10 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ impl LangString {
}
"no_run" => { data.no_run = true; seen_rust_tags = !seen_other_tags; }
"ignore" => { data.ignore = Ignore::All; seen_rust_tags = !seen_other_tags; }
x if enable_per_target_ignores && x.starts_with("ignore-") => {
x if x.starts_with("ignore-") => if enable_per_target_ignores {
ignores.push(x.trim_start_matches("ignore-").to_owned());
seen_rust_tags = !seen_other_tags;
}
Expand Down Expand Up @@ -681,15 +681,9 @@ impl LangString {
_ => { seen_other_tags = true }
}
}

match data.ignore {
Ignore::All => {},
Ignore::None => {
if !ignores.is_empty() {
data.ignore = Ignore::Some(ignores);
}
},
_ => unreachable!(),
// ignore-foo overrides ignore
if !ignores.is_empty() {
data.ignore = Ignore::Some(ignores);
}

data.rust &= !seen_other_tags || seen_rust_tags;
Expand Down
2 changes: 2 additions & 0 deletions src/librustdoc/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ pub fn run(options: Options) -> i32 {
..config::basic_debugging_options()
},
edition: options.edition,
target_triple: options.target.clone(),
..config::Options::default()
};

let config = interface::Config {
opts: sessopts,
crate_cfg: config::parse_cfgspecs(options.cfgs.clone()),
Expand Down

0 comments on commit 5b597b2

Please sign in to comment.