diff options
| author | Thomas Otto <th1000s@posteo.net> | 2024-07-06 16:35:06 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-06 10:35:06 -0400 |
| commit | 096941f77f28e21cbaad74eff3bbe7608ba4cbd8 (patch) | |
| tree | 40f4dd85867b0ba75b0f23cb448100c2e371d305 /src | |
| parent | f5b37173fe88a62e37208a9587a0ab4fec0ef107 (diff) | |
tests: add insta for snapshot testing (#1739)
Insta makes writing new tests or performing changes which update the
expected value(s) easier. The new reference data can be reviewed
and inserted/updated automatically by `cargo insta review` (after
`cargo install cargo-insta`, but that tool is optional).
The snapshots are stored inline using the `@""` syntax and not in
separate files because the delta test output is small and designed to
be human readable.
See https://insta.rs/#hello-snapshot-testing
and https://docs.rs/insta/1.39.0/insta/
Diffstat (limited to 'src')
| -rw-r--r-- | src/features/side_by_side.rs | 17 | ||||
| -rw-r--r-- | src/tests/integration_test_utils.rs | 6 |
2 files changed, 15 insertions, 8 deletions
diff --git a/src/features/side_by_side.rs b/src/features/side_by_side.rs index a818235..8db8d11 100644 --- a/src/features/side_by_side.rs +++ b/src/features/side_by_side.rs @@ -594,16 +594,19 @@ pub mod tests { use crate::features::line_numbers::tests::*; use crate::options::theme; use crate::tests::integration_test_utils::{make_config_from_args, run_delta, DeltaTest}; + use insta::assert_snapshot; #[test] - fn test_two_minus_lines() { - DeltaTest::with_args(&["--side-by-side", "--width", "40"]) + fn test_two_fitting_minus_lines() { + // rustfmt ignores the assert macro arguments, so do the setup outside + let result = DeltaTest::with_args(&["--side-by-side", "--width", "40"]) .with_input(TWO_MINUS_LINES_DIFF) - .expect_after_header( - r#" - │ 1 │a = 1 │ │ - │ 2 │b = 23456 │ │"#, - ); + .skip_header(); + assert_snapshot!(result, @r###" + │ 1 │a = 1 │ │ + │ 2 │b = 23456 │ │ + "### + ); } #[test] diff --git a/src/tests/integration_test_utils.rs b/src/tests/integration_test_utils.rs index 09e445e..1b2f1df 100644 --- a/src/tests/integration_test_utils.rs +++ b/src/tests/integration_test_utils.rs @@ -6,7 +6,7 @@ use std::io::{BufReader, Write}; use std::path::Path; use bytelines::ByteLines; -use itertools; +use itertools::Itertools; use crate::ansi; use crate::cli; @@ -264,6 +264,10 @@ impl DeltaTestOutput { self.expect_after_skip(crate::config::HEADER_LEN, expected) } + pub fn skip_header(self) -> String { + self.output.lines().skip(config::HEADER_LEN).join("\n") + } + pub fn expect_contains(self, expected: &str) -> Self { assert!( self.output.contains(expected), |
