]> git.proxmox.com Git - rustc.git/blob - vendor/ui_test/README.md
New upstream version 1.73.0+dfsg1
[rustc.git] / vendor / ui_test / README.md
1 A smaller version of compiletest-rs
2
3 ## Magic behavior
4
5 * Tests are run in order of their filenames (files first, then recursing into folders).
6 So if you have any slow tests, prepend them with a small integral number to make them get run first, taking advantage of parallelism as much as possible (instead of waiting for the slow tests at the end).
7
8 ## Supported magic comment annotations
9
10 If your test tests for failure, you need to add a `//~` annotation where the error is happening
11 to make sure that the test will always keep failing with a specific message at the annotated line.
12
13 `//~ ERROR: XXX` make sure the stderr output contains `XXX` for an error in the line where this comment is written
14
15 * Also supports `HELP`, `WARN` or `NOTE` for different kind of message
16 * if one of those levels is specified explicitly, *all* diagnostics of this level or higher need an annotation. If you want to avoid this, just leave out the all caps level note entirely.
17 * If the all caps note is left out, a message of any level is matched. Leaving it out is not allowed for `ERROR` levels.
18 * This checks the output *before* normalization, so you can check things that get normalized away, but need to
19 be careful not to accidentally have a pattern that differs between platforms.
20 * if `XXX` is of the form `/XXX/` it is treated as a regex instead of a substring and will succeed if the regex matches.
21
22 In order to change how a single test is tested, you can add various `//@` comments to the test.
23 Any other comments will be ignored, and all `//@` comments must be formatted precisely as
24 their command specifies, or the test will fail without even being run.
25
26 * `//@ignore-C` avoids running the test when condition `C` is met.
27 * `C` can be `target-XXX`, which checks whether the target triple contains `XXX`.
28 * `C` can also be one of `64bit`, `32bit` or `16bit`.
29 * `C` can also be `on-host`, which will only run the test during cross compilation testing.
30 * `//@only-C` **only** runs the test when condition `C` is met. The conditions are the same as with `ignore`.
31 * `//@needs-asm-support` **only** runs the test when the target supports `asm!`.
32 * `//@stderr-per-bitwidth` produces one stderr file per bitwidth, as they may differ significantly sometimes
33 * `//@error-in-other-file: XXX` can be used to check for errors that can't have `//~` patterns due to being reported in other files.
34 * `//@revisions: XXX YYY` runs the test once for each space separated name in the list
35 * emits one stderr file per revision
36 * `//~` comments can be restricted to specific revisions by adding the revision name after the `~` in square brackets: `//~[XXX]`
37 * `//@` comments can be restricted to specific revisions by adding the revision name after the `@` in square brackets: `//@[XXX]`
38 * Note that you cannot add revisions to the `revisions` command.
39 * `//@compile-flags: XXX` appends `XXX` to the command line arguments passed to the rustc driver
40 * you can specify this multiple times, and all the flags will accumulate
41 * `//@rustc-env: XXX=YYY` sets the env var `XXX` to `YYY` for the rustc driver execution.
42 * for Miri these env vars are used during compilation via rustc and during the emulation of the program
43 * you can specify this multiple times, accumulating all the env vars
44 * `//@normalize-stderr-test: "REGEX" -> "REPLACEMENT"` replaces all matches of `REGEX` in the stderr with `REPLACEMENT`. The replacement may specify `$1` and similar backreferences to paste captures.
45 * you can specify multiple such commands, there is no need to create a single regex that handles multiple replacements that you want to perform.
46 * `//@require-annotations-for-level: LEVEL` can be used to change the level of diagnostics that require a corresponding annotation.
47 * this is only useful if there are any annotations like `HELP`, `WARN` or `NOTE`, as these would automatically require annotations for all other diagnostics of the same or higher level.
48 * `//@check-pass` overrides the `Config::mode` and will make the test behave as if the test suite were in `Mode::Pass`.
49 * `//@edition: EDITION` overwrites the default edition (2021) to the given edition.
50 * `//@run-rustfix` runs rustfix on the output and recompiles the result. The result must suceed to compile.
51 * `//@aux-build: filename` looks for a file in the `auxiliary` directory (within the directory of the test), compiles it as a library and links the current crate against it. This allows you import the crate with `extern crate` or just via `use` statements.
52 * you can optionally specify a crate type via `//@aux-build: filename.rs:proc-macro`. This is necessary for some crates (like proc macros), but can also be used to change the linkage against the aux build.
53 * `//@run` compiles the test and runs the resulting binary. The resulting binary must exit successfully. Stdout and stderr are taken from the resulting binary. Any warnings during compilation are ignored.
54 * You can also specify a different exit code/status that is expected via e.g. `//@run: 1` or `//@run: 101` (the latter is the standard Rust exit code for panics).
55
56 ## Significant differences to compiletest-rs
57
58 * `ignore-target-*` and `only-target-*` operate solely on the triple, instead of supporting things like `macos`
59 * only supports `ui` tests
60 * tests are run in named order, so you can prefix slow tests with `0` in order to make them get run first
61 * `aux-build`s for proc macros require an additional `:proc-macro` after the file name, but then the aux file itself needs no `#![proc_macro]` or other flags.
62 * `aux-build`s require specifying nested aux builds explicitly and will not allow you to reference sibling `aux-build`s' artifacts.