f(); //~ ERROR call to unsafe function is unsafe
}
fn main() {
f(); //[mir]~ ERROR call to unsafe function is unsafe
}
```
In this example, the second error message is only emitted in the `mir` revision.
The `thir` revision only emits the first error.
If the `cfg` causes the compiler to emit different output, then a test can have
multiple `.stderr` files for the different outputs. In the example above, there
would be a `.mir.stderr` and `.thir.stderr` file with the different outputs of
the different revisions.
> Note: cfg revisions also work inside the source code with `#[cfg]` attributes.
>
> By convention, the `FALSE` cfg is used to have an always-false config.
## Controlling pass/fail expectations
By default, a UI test is expected to **generate a compile error** because most
of the tests are checking for invalid input and error diagnostics. However, you
can also make UI tests where compilation is expected to succeed, and you can
even run the resulting program. Just add one of the following
[directives](directives.md):
- Pass directives:
- `//@ check-pass` — compilation should succeed but skip codegen
(which is expensive and isn't supposed to fail in most cases).
- `//@ build-pass` — compilation and linking should succeed but do
not run the resulting binary.
- `//@ run-pass` — compilation should succeed and running the resulting
binary should also succeed.
- Fail directives:
- `//@ check-fail` — compilation should fail (the codegen phase is skipped).
This is the default for UI tests.
- `//@ build-fail` — compilation should fail during the codegen phase.
This will run `rustc` twice, once to verify that it compiles successfully
without the codegen phase, then a second time the full compile should
fail.
- `//@ run-fail` — compilation should succeed, but running the resulting
binary should fail.
For `run-pass` and `run-fail` tests, by default the output of the program itself
is not checked.
If you want to check the output of running the program, include the
`check-run-results` directive. This will check for a `.run.stderr` and
`.run.stdout` files to compare against the actual output of the program.
Tests with the `*-pass` directives can be overridden with the `--pass`
command-line option:
```sh
./x test tests/ui --pass check
```
The `--pass` option only affects UI tests. Using `--pass check` can run the UI
test suite much faster (roughly twice as fast on my system), though obviously
not exercising as much.
The `ignore-pass` directive can be used to ignore the `--pass` CLI flag if the
test won't work properly with that override.
## Known bugs
The `known-bug` directive may be used for tests that demonstrate a known bug
that has not yet been fixed. Adding tests for known bugs is helpful for several
reasons, including:
1. Maintaining a functional test that can be conveniently reused when the bug is
fixed.
2. Providing a sentinel that will fail if the bug is incidentally fixed. This
can alert the developer so they know that the associated issue has been fixed
and can possibly be closed.
This directive takes comma-separated issue numbers as arguments, or `"unknown"`:
- `//@ known-bug: #123, #456` (when the issues are on rust-lang/rust)
- `//@ known-bug: rust-lang/chalk#123456`
(allows arbitrary text before the `#`, which is useful when the issue is on another repo)
- `//@ known-bug: unknown`
(when there is no known issue yet; preferrably open one if it does not already exist)
Do not include [error annotations](#error-annotations) in a test with
`known-bug`. The test should still include other normal directives and
stdout/stderr files.
## Test organization
When deciding where to place a test file, please try to find a subdirectory that
best matches what you are trying to exercise. Do your best to keep things
organized. Admittedly it can be difficult as some tests can overlap different
categories, and the existing layout may not fit well.
Name the test by a concise description of what the test is checking. Avoid