Home Explore Blog CI



rustc

8th chunk of `src/tests/ui.md`
5e6d3e6e9cd7f3768405030010fb5bb264d3672a2a51bc3f0000000100000838
`tests/ui` (UI test root directory) and `tests/ui/issues` directories have more
than 1000 entries, we set a different limit for those directories. So, please
avoid putting a new test there and try to find a more relevant place.

For example, if your test is related to closures, you should put it in
`tests/ui/closures`. When you reach the limit, you could increase it by tweaking
[here][ui test tidy].


## Rustfix tests

UI tests can validate that diagnostic suggestions apply correctly and that the
resulting changes compile correctly. This can be done with the `run-rustfix`
directive:

```rust,ignore
//@ run-rustfix
//@ check-pass
#![crate_type = "lib"]

pub struct not_camel_case {}
//~^ WARN `not_camel_case` should have an upper camel case name
//~| HELP convert the identifier to upper camel case
//~| SUGGESTION NotCamelCase
```

Rustfix tests should have a file with the `.fixed` extension which contains the
source file after the suggestion has been applied.

- When the test is run, compiletest first checks that the correct lint/warning
  is generated.
- 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.

Title: Rustfix Tests and Compare Modes
Summary
This section provides further details on Rustfix tests, explaining the process of generating `.fixed` files, applying suggestions, and ensuring successful compilation. It also introduces the `rustfix-only-machine-applicable` directive for cases with mixed suggestion levels. Additionally, it briefly mentions compare modes, which allow running tests with different compiler flags and using different output files based on the compare mode.