- Then, it applies the suggestion and compares against `.fixed` (they must
match).
- Finally, the fixed source is compiled, and this compilation is required to
succeed.
Usually when creating a rustfix test you will generate the `.fixed` file
automatically with the `x test --bless` option.
The `run-rustfix` directive will cause *all* suggestions to be applied, even if
they are not [`MachineApplicable`](../diagnostics.md#suggestions). If this is a
problem, then you can add the `rustfix-only-machine-applicable` directive in
addition to `run-rustfix`. This should be used if there is a mixture of
different suggestion levels, and some of the non-machine-applicable ones do not
apply cleanly.
## Compare modes
[Compare modes](compiletest.md#compare-modes) can be used to run all tests with
different flags from what they are normally compiled with. In some cases, this
might result in different output from the compiler. To support this, different
output files can be saved which contain the output based on the compare mode.
For example, when using the Polonius mode, a test `foo.rs` will first look for
expected output in `foo.polonius.stderr`, falling back to the usual `foo.stderr`
if not found. This is useful as different modes can sometimes result in
different diagnostics and behavior. This can help track which tests have
differences between the modes, and to visually inspect those diagnostic
differences.
If in the rare case you encounter a test that has different behavior, you can
run something like the following to generate the alternate stderr file:
```sh
./x test tests/ui --compare-mode=polonius --bless
```
Currently none of the compare modes are checked in CI for UI tests.
## `rustc_*` TEST attributes
The compiler defines several perma-unstable `#[rustc_*]` attributes gated behind
the internal feature `rustc_attrs` that dump extra compiler-internal
information. See the corresponding subsection in [compiler debugging] for more
details.
They can be used in tests to more precisely, legibly and easily test internal
compiler state in cases where it would otherwise be very hard to do the same
with "user-facing" Rust alone. Indeed, one could say that this slightly abuses
the term "UI" (*user* interface) and turns such UI tests from black-box tests
into white-box ones. Use them carefully and sparingly.
## UI test mode preset lint levels
By default, test suites under UI test mode (`tests/ui`, `tests/ui-fulldeps`,
but not `tests/rustdoc-ui`) will specify
- `-A unused`
- `-A internal_features`
If:
- The ui test's pass mode is below `run` (i.e. check or build).
- No compare modes are specified.
Since they can be very noisy in ui tests.
You can override them with `compile-flags` lint level flags or
in-source lint level attributes as required.
Note that the `rustfix` version will *not* have `-A unused` passed,
meaning that you may have to `#[allow(unused)]` to suppress `unused`
lints on the rustfix'd file (because we might be testing rustfix
on `unused` lints themselves).