A smaller version of compiletest-rs
- Tests are run in order of their filenames (files first, then recursing into folders). 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).
If your test tests for failure, you need to add a //~ annotation where the error is happening
to make sure that the test will always keep failing with a specific message at the annotated line.
//~ ERROR: XXX make sure the stderr output contains XXX for an error in the line where this comment is written
- Also supports
HELP,WARNorNOTEfor different kind of message- 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.
- If the all caps note is left out, a message of any level is matched. Leaving it out is not allowed for
ERRORlevels. - This checks the output before normalization, so you can check things that get normalized away, but need to be careful not to accidentally have a pattern that differs between platforms.
- if
XXXis of the form/XXX/it is treated as a regex instead of a substring and will succeed if the regex matches.
In order to change how a single test is tested, you can add various //@ comments to the test.
Any other comments will be ignored, and all //@ comments must be formatted precisely as
their command specifies, or the test will fail without even being run.
//@ignore-Cavoids running the test when conditionCis met.Ccan betarget-XXX, which checks whether the target triple containsXXX.Ccan also be one of64bit,32bitor16bit.Ccan also beon-host, which will only run the test during cross compilation testing.
//@only-Conly runs the test when conditionCis met. The conditions are the same as withignore.//@needs-asm-supportonly runs the test when the target supportsasm!.//@stderr-per-bitwidthproduces one stderr file per bitwidth, as they may differ significantly sometimes//@error-in-other-file: XXXcan be used to check for errors that can't have//~patterns due to being reported in other files.//@revisions: XXX YYYruns the test once for each space separated name in the list- emits one stderr file per revision
//~comments can be restricted to specific revisions by adding the revision name after the~in square brackets://~[XXX]//@comments can be restricted to specific revisions by adding the revision name after the@in square brackets://@[XXX]- Note that you cannot add revisions to the
revisionscommand.
- Note that you cannot add revisions to the
//@compile-flags: XXXappendsXXXto the command line arguments passed to the rustc driver- you can specify this multiple times, and all the flags will accumulate
//@rustc-env: XXX=YYYsets the env varXXXtoYYYfor the rustc driver execution.- for Miri these env vars are used during compilation via rustc and during the emulation of the program
- you can specify this multiple times, accumulating all the env vars
//@normalize-stderr-test: "REGEX" -> "REPLACEMENT"replaces all matches ofREGEXin the stderr withREPLACEMENT. The replacement may specify$1and similar backreferences to paste captures.- you can specify multiple such commands, there is no need to create a single regex that handles multiple replacements that you want to perform.
//@require-annotations-for-level: LEVELcan be used to change the level of diagnostics that require a corresponding annotation.- this is only useful if there are any annotations like
HELP,WARNorNOTE, as these would automatically require annotations for all other diagnostics of the same or higher level.
- this is only useful if there are any annotations like
//@check-passoverrides theConfig::modeand will make the test behave as if the test suite were inMode::Pass.//@edition: EDITIONoverwrites the default edition (2021) to the given edition.//@run-rustfixruns rustfix on the output and recompiles the result. The result must suceed to compile.//@aux-build: filenamelooks for a file in theauxiliarydirectory (within the directory of the test), compiles it as a library and links the current crate against it. This allows you import the crate withextern crateor just viausestatements.- 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.
- you can optionally specify a crate type via
//@runcompiles 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.- You can also specify a different exit code/status that is expected via e.g.
//@run: 1or//@run: 101(the latter is the standard Rust exit code for panics).
- You can also specify a different exit code/status that is expected via e.g.
ignore-target-*andonly-target-*operate solely on the triple, instead of supporting things likemacos- only supports
uitests - tests are run in named order, so you can prefix slow tests with
0in order to make them get run first aux-builds for proc macros require an additional:proc-macroafter the file name, but then the aux file itself needs no#![proc_macro]or other flags.aux-builds require specifying nested aux builds explicitly and will not allow you to reference siblingaux-builds' artifacts.