cargo_test_support

Module compare

source
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 of substitute_macros for a complete list of substitutions.
  • [DIRTY-MSVC] (only when the line starts with it) would be replaced by [DIRTY] when cfg(target_env = "msvc") or the line will be ignored otherwise. Tests that work around issue 7358 can use this to avoid duplicating the with_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§