5 You can run the tests using `x.py`. The most basic command – which
6 you will almost never want to use! – is as follows:
12 This will build the stage 1 compiler and then run the whole test
13 suite. You probably don't want to do this very often, because it takes
14 a very long time, and anyway bors / GitHub Actions will do it for you.
15 (Often, I will run this command in the background after opening a PR that
16 I think is done, but rarely otherwise. -nmatsakis)
18 The test results are cached and previously successful tests are
19 `ignored` during testing. The stdout/stderr contents as well as a
20 timestamp file for every test can be found under `build/ARCH/test/`.
21 To force-rerun a test (e.g. in case the test runner fails to notice
22 a change) you can simply remove the timestamp file.
24 Note that some tests require a Python-enabled gdb. You can test if
25 your gdb install supports Python by using the `python` command from
26 within gdb. Once invoked you can type some Python code (e.g.
27 `print("hi")`) followed by return and then `CTRL+D` to execute it.
28 If you are building gdb from source, you will need to configure with
29 `--with-python=<path-to-python-binary>`.
31 ## Running a subset of the test suites
33 When working on a specific PR, you will usually want to run a smaller
34 set of tests. For example, a good "smoke test" that can be used after
35 modifying rustc to see if things are generally working correctly would be the
39 ./x.py test src/test/ui
42 This will run the `ui` test suite. Of course, the choice
43 of test suites is somewhat arbitrary, and may not suit the task you are
44 doing. For example, if you are hacking on debuginfo, you may be better off
45 with the debuginfo test suite:
48 ./x.py test src/test/debuginfo
51 If you only need to test a specific subdirectory of tests for any
52 given test suite, you can pass that directory to `x.py test`:
55 ./x.py test src/test/ui/const-generics
58 Likewise, you can test a single file by passing its path:
61 ./x.py test src/test/ui/const-generics/const-test.rs
64 ### Run only the tidy script
70 ### Run tests on the standard library
73 ./x.py test --stage 0 library/std
76 ### Run the tidy script and tests on the standard library
79 ./x.py test --stage 0 tidy library/std
82 ### Run tests on the standard library using a stage 1 compiler
85 ./x.py test library/std
88 By listing which test suites you want to run you avoid having to run
89 tests for components you did not change at all.
91 **Warning:** Note that bors only runs the tests with the full stage 2
92 build; therefore, while the tests **usually** work fine with stage 1,
93 there are some limitations.
95 ## Run unit tests on the compiler/library
97 You may want to run unit tests on a specific file with following:
100 ./x.py test compiler/rustc_data_structures/src/thin_vec/tests.rs
103 But unfortunately, it's impossible. You should invoke following instead:
106 ./x.py test compiler/rustc_data_structures/ --test-args thin_vec
109 ## Running an individual test
111 Another common thing that people want to do is to run an **individual
112 test**, often the test they are trying to fix. As mentioned earlier,
113 you may pass the full file path to achieve this, or alternatively one
114 may invoke `x.py` with the `--test-args` option:
117 ./x.py test src/test/ui --test-args issue-1234
120 Under the hood, the test runner invokes the standard rust test runner
121 (the same one you get with `#[test]`), so this command would wind up
122 filtering for tests that include "issue-1234" in the name. (Thus
123 `--test-args` is a good way to run a collection of related tests.)
125 ## Editing and updating the reference files
127 If you have changed the compiler's output intentionally, or you are
128 making a new test, you can pass `--bless` to the test subcommand. E.g.
129 if some tests in `src/test/ui` are failing, you can run
132 ./x.py test src/test/ui --bless
135 to automatically adjust the `.stderr`, `.stdout` or `.fixed` files of
136 all tests. Of course you can also target just specific tests with the
137 `--test-args your_test_name` flag, just like when running the tests.
139 ## Passing `--pass $mode`
141 Pass UI tests now have three modes, `check-pass`, `build-pass` and
142 `run-pass`. When `--pass $mode` is passed, these tests will be forced
143 to run under the given `$mode` unless the directive `// ignore-pass`
144 exists in the test file. For example, you can run all the tests in
145 `src/test/ui` as `check-pass`:
148 ./x.py test src/test/ui --pass check
151 By passing `--pass $mode`, you can reduce the testing time. For each
152 mode, please see [here][mode].
154 [mode]: ./adding.md#tests-that-do-not-result-in-compile-errors
156 ## Using incremental compilation
158 You can further enable the `--incremental` flag to save additional
159 time in subsequent rebuilds:
162 ./x.py test src/test/ui --incremental --test-args issue-1234
165 If you don't want to include the flag with every command, you can
166 enable it in the `config.toml`:
173 Note that incremental compilation will use more disk space than usual.
174 If disk space is a concern for you, you might want to check the size
175 of the `build` directory from time to time.
177 ## Running tests with different "compare modes"
179 UI tests may have different output depending on certain "modes" that
180 the compiler is in. For example, when in "non-lexical lifetimes" (NLL)
181 mode a test `foo.rs` will first look for expected output in
182 `foo.nll.stderr`, falling back to the usual `foo.stderr` if not found.
183 To run the UI test suite in NLL mode, one would use the following:
186 ./x.py test src/test/ui --compare-mode=nll
189 Other examples of compare-modes are "noopt", "migrate", and
190 [revisions](./adding.html#revisions).
192 ## Running tests manually
194 Sometimes it's easier and faster to just run the test by hand. Most tests are
195 just `rs` files, so you can do something like
198 rustc +stage1 src/test/ui/issue-1234.rs
201 This is much faster, but doesn't always work. For example, some tests
202 include directives that specify specific compiler flags, or which rely
203 on other crates, and they may not run the same without those options.