Expand description
Routines for comparing and diffing output.
§Deprecated comparisons
Cargo’s tests are in transition from internal-only pattern and normalization routines used in
asserts like crate::Execs::with_stdout_contains
to assert_e2e
and assert_ui
.
§Patterns
Many of these functions support special markup to assist with comparing text that may vary or is otherwise uninteresting for the test at hand. The supported patterns are:
[..]
is a wildcard that matches 0 or more characters on the same line (similar to.*
in a regex). It is non-greedy.[EXE]
optionally adds.exe
on Windows (empty string on other platforms).[ROOT]
is the path to the test directory’s root.[CWD]
is the working directory of the process that was run.- There is a wide range of substitutions (such as
[COMPILING]
or[WARNING]
) to match cargo’s “status” output and allows you to ignore the alignment. See the source ofsubstitute_macros
for a complete list of substitutions. [DIRTY-MSVC]
(only when the line starts with it) would be replaced by[DIRTY]
whencfg(target_env = "msvc")
or the line will be ignored otherwise. Tests that work around issue 7358 can use this to avoid duplicating thewith_stderr
call like:if cfg!(target_env = "msvc") {e.with_stderr("...[DIRTY]...");} else {e.with_stderr("...");}
.
§Normalization
In addition to the patterns described above, the strings are normalized in such a way to avoid unwanted differences. The normalizations are:
- Raw tab characters are converted to the string
<tab>
. This is helpful so that raw tabs do not need to be written in the expected string, and to avoid confusion of tabs vs spaces. - Backslashes are converted to forward slashes to deal with Windows paths. This helps so that all tests can be written assuming forward slashes. Other heuristics are applied to try to ensure Windows-style paths aren’t a problem.
- Carriage returns are removed, which can help when running on Windows.
Macros§
- regex 🔒This makes it easier to write regex replacements that are guaranteed to only get compiled once
Structs§
- WildStr 🔒A single line string that supports
[..]
wildcard matching.
Statics§
Functions§
- Assertion policy for functional end-to-end tests
- Convenience wrapper around
match_exact
which will panic on error. - Assertion policy for UI tests
- Checks that the given string contains the given contiguous lines somewhere.
- Checks that the given string contains the given contiguous lines somewhere, and should be repeated
number
times. - Checks that the given string does not contain the given contiguous lines anywhere.
- Compares one string against another, checking that they both match.
- Checks that the given string contains the given lines, ignoring the order of the lines.
- Checks that the given string has a line that contains the given patterns, and that line also does not contain the
without
patterns. - meta_
cmp 🔒 - Normalizes the output so that it can be compared against the expected value.
- Normalizes the expected string so that it can be compared against the actual output.
- Normalizes text for both actual and expected strings on Windows.