Skip to content

Commit 8f88a8a

Browse files
committed
docs(test): Expand 'compare' documentation
1 parent cb52840 commit 8f88a8a

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

crates/cargo-test-support/src/compare.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
//! Routines for comparing and diffing output.
22
//!
3-
//! # Patterns
3+
//! # Deprecated comparisons
4+
//!
5+
//! Cargo's tests are in transition from internal-only pattern and normalization routines used in
6+
//! asserts like [`crate::Execs::with_stdout`] to [`assert_e2e`] and [`assert_ui`].
7+
//!
8+
//! ## Patterns
49
//!
510
//! Many of these functions support special markup to assist with comparing
611
//! text that may vary or is otherwise uninteresting for the test at hand. The
@@ -22,7 +27,7 @@
2227
//! can use this to avoid duplicating the `with_stderr` call like:
2328
//! `if cfg!(target_env = "msvc") {e.with_stderr("...[DIRTY]...");} else {e.with_stderr("...");}`.
2429
//!
25-
//! # Normalization
30+
//! ## Normalization
2631
//!
2732
//! In addition to the patterns described above, the strings are normalized
2833
//! in such a way to avoid unwanted differences. The normalizations are:
@@ -86,6 +91,19 @@ macro_rules! regex {
8691
/// Other heuristics are applied to try to ensure Windows-style paths aren't
8792
/// a problem.
8893
/// - Carriage returns are removed, which can help when running on Windows.
94+
///
95+
/// # Example
96+
///
97+
/// ```no_run
98+
/// # use cargo_test_support::compare::assert_e2e;
99+
/// # use cargo_test_support::file;
100+
/// # let p = cargo_test_support::project().build();
101+
/// # let stdout = "";
102+
/// assert_e2e().eq(stdout, file!["stderr.term.svg"]);
103+
/// ```
104+
/// ```console
105+
/// $ SNAPSHOTS=overwrite cargo test
106+
/// ```
89107
pub fn assert_ui() -> snapbox::Assert {
90108
let mut subs = snapbox::Redactions::new();
91109
subs.extend(MIN_LITERAL_REDACTIONS.into_iter().cloned())
@@ -129,6 +147,18 @@ pub fn assert_ui() -> snapbox::Assert {
129147
/// Other heuristics are applied to try to ensure Windows-style paths aren't
130148
/// a problem.
131149
/// - Carriage returns are removed, which can help when running on Windows.
150+
///
151+
/// # Example
152+
///
153+
/// ```no_run
154+
/// # use cargo_test_support::compare::assert_e2e;
155+
/// # use cargo_test_support::str;
156+
/// # let p = cargo_test_support::project().build();
157+
/// assert_e2e().eq(p.read_lockfile(), str![]);
158+
/// ```
159+
/// ```console
160+
/// $ SNAPSHOTS=overwrite cargo test
161+
/// ```
132162
pub fn assert_e2e() -> snapbox::Assert {
133163
let mut subs = snapbox::Redactions::new();
134164
subs.extend(MIN_LITERAL_REDACTIONS.into_iter().cloned())

0 commit comments

Comments
 (0)