summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWayne Davison <wayne@opencoder.net>2022-01-04 00:39:03 -0800
committerGitHub <noreply@github.com>2022-01-04 03:39:03 -0500
commit1d6f18a6630825cefa4c6cd714e8103dd8a95cde (patch)
treef6ce03fa63ed9ec4f7a8d2e6fd837eb1a5a19bf5
parentcd47b21176b19eb700562dcb0999ef4b99c6a893 (diff)
DeltaTest improvements (#876)
* DeltaTest improvements - Added .expect_contains(), .expect_raw_contains(), and .expect_contains_once() member functions to DeltaTestOutput. These functions also output some helpful debug info when the assert fails. - Separated .with_config_and_input() into .with_config() and (the tweaked) .with_input(). - Made .with_config() create a DeltaTest object (like .with() does). - Renamed .with() as .with_args(). - Moved .explain_ansi() from DeltaTestOutput to DeltaTest, which must now be called prior to .with_input() since the latter stashes off both the raw_output & the processed output in the object. - Changed .expect() and .expect_skip() to return Self so that they can continue a chain of multiple expect calls (e.g. a series of partial matches with different skip values). - The processed output text can be accessed via `test_obj.output` (see also `test_obj.raw_output`). - Renamed .expect_skip() to .expect_after_skip(). - Changed .expect() to start at the first line. - Added .expect_after_header() that works like the old .expect(). - Renamed lines_match() to assert_lines_match() and made it match all lines (no skip number). - Added assert_lines_match_after_skip() to work like the old lines_match() function, but with the .expect_after_skip() arg order. - Converted some old-style tests into DeltaTest style tests. - Renamed set_cfg as set_config
-rw-r--r--src/features/line_numbers.rs32
-rw-r--r--src/features/side_by_side.rs30
-rw-r--r--src/handlers/hunk.rs30
-rw-r--r--src/tests/integration_test_utils.rs173
-rw-r--r--src/tests/test_example_diffs.rs157
-rw-r--r--src/wrapping.rs187
6 files changed, 313 insertions, 296 deletions
diff --git a/src/features/line_numbers.rs b/src/features/line_numbers.rs
index fd2232f4..65cf4022 100644
--- a/src/features/line_numbers.rs
+++ b/src/features/line_numbers.rs
@@ -630,7 +630,7 @@ pub mod tests {
#[test]
fn test_two_minus_lines() {
- DeltaTest::with(&[
+ DeltaTest::with_args(&[
"--line-numbers",
"--line-numbers-left-format",
"{nm:^4}⋮",
@@ -646,7 +646,7 @@ pub mod tests {
"0 4",
])
.with_input(TWO_MINUS_LINES_DIFF)
- .expect(
+ .expect_after_header(
r#"
#indent_mark
1 ⋮ │a = 1
@@ -656,7 +656,7 @@ pub mod tests {
#[test]
fn test_two_plus_lines() {
- DeltaTest::with(&[
+ DeltaTest::with_args(&[
"--line-numbers",
"--line-numbers-left-format",
"{nm:^4}⋮",
@@ -672,7 +672,7 @@ pub mod tests {
"0 4",
])
.with_input(TWO_PLUS_LINES_DIFF)
- .expect(
+ .expect_after_header(
r#"
#indent_mark
⋮ 1 │a = 1
@@ -779,9 +779,9 @@ pub mod tests {
#[test]
fn test_line_numbers_continue_correctly() {
- DeltaTest::with(&["--side-by-side", "--width", "44", "--line-fill-method=ansi"])
+ DeltaTest::with_args(&["--side-by-side", "--width", "44", "--line-fill-method=ansi"])
.with_input(DIFF_PLUS_MINUS_WITH_1_CONTEXT_DIFF)
- .expect(
+ .expect_after_header(
r#"
│ 1 │abc │ 1 │abc
│ 2 │a = left side │ 2 │a = right side
@@ -791,7 +791,7 @@ pub mod tests {
#[test]
fn test_line_numbers_continue_correctly_after_wrapping() {
- DeltaTest::with(&[
+ DeltaTest::with_args(&[
"--side-by-side",
"--width",
"32",
@@ -802,7 +802,7 @@ pub mod tests {
"@",
])
.with_input(DIFF_PLUS_MINUS_WITH_1_CONTEXT_DIFF)
- .expect(
+ .expect_after_header(
r#"
│ 1 │abc │ 1 │abc
│ 2 │a = left @│ 2 │a = right@
@@ -821,9 +821,9 @@ pub mod tests {
"@",
];
- DeltaTest::with(cfg)
+ DeltaTest::with_args(cfg)
.with_input(DIFF_WITH_LONGER_MINUS_1_CONTEXT)
- .expect(
+ .expect_after_header(
r#"
│ 1 │abc │ 1 │abc
│ 2 │a = one side │ 2 │a = one longer@
@@ -831,9 +831,9 @@ pub mod tests {
│ 3 │xyz │ 3 │xyz"#,
);
- DeltaTest::with(cfg)
+ DeltaTest::with_args(cfg)
.with_input(DIFF_WITH_LONGER_PLUS_1_CONTEXT)
- .expect(
+ .expect_after_header(
r#"
│ 1 │abc │ 1 │abc
│ 2 │a = one longer@│ 2 │a = one side
@@ -841,9 +841,9 @@ pub mod tests {
│ 3 │xyz │ 3 │xyz"#,
);
- DeltaTest::with(cfg)
+ DeltaTest::with_args(cfg)
.with_input(DIFF_MISMATCH_LONGER_MINUS_1_CONTEXT)
- .expect(
+ .expect_after_header(
r#"
│ 1 │abc │ 1 │abc
│ 2 │a = left side @│ │
@@ -852,9 +852,9 @@ pub mod tests {
│ 3 │xyz │ 3 │xyz"#,
);
- DeltaTest::with(cfg)
+ DeltaTest::with_args(cfg)
.with_input(DIFF_MISMATCH_LONGER_PLUS_1_CONTEXT)
- .expect(
+ .expect_after_header(
r#"
│ 1 │abc │ 1 │abc
│ 2 │a = other one │ │
diff --git a/src/features/side_by_side.rs b/src/features/side_by_side.rs
index 96431696..fb0a8198 100644
--- a/src/features/side_by_side.rs
+++ b/src/features/side_by_side.rs
@@ -597,9 +597,9 @@ pub mod tests {
#[test]
fn test_two_minus_lines() {
- DeltaTest::with(&["--side-by-side", "--width", "40"])
+ DeltaTest::with_args(&["--side-by-side", "--width", "40"])
.with_input(TWO_MINUS_LINES_DIFF)
- .expect(
+ .expect_after_header(
r#"
│ 1 │a = 1 │ │
│ 2 │b = 23456 │ │"#,
@@ -608,7 +608,7 @@ pub mod tests {
#[test]
fn test_two_minus_lines_truncated() {
- DeltaTest::with(&[
+ DeltaTest::with_args(&[
"--side-by-side",
"--wrap-max-lines",
"0",
@@ -616,9 +616,9 @@ pub mod tests {
"28",
"--line-fill-method=spaces",
])
- .set_cfg(|cfg| cfg.truncation_symbol = ">".into())
+ .set_config(|cfg| cfg.truncation_symbol = ">".into())
.with_input(TWO_MINUS_LINES_DIFF)
- .expect(
+ .expect_after_header(
r#"
│ 1 │a = 1 │ │
│ 2 │b = 234>│ │"#,
@@ -627,14 +627,14 @@ pub mod tests {
#[test]
fn test_two_plus_lines() {
- DeltaTest::with(&[
+ DeltaTest::with_args(&[
"--side-by-side",
"--width",
"41",
"--line-fill-method=spaces",
])
.with_input(TWO_PLUS_LINES_DIFF)
- .expect(
+ .expect_after_header(
r#"
│ │ │ 1 │a = 1
│ │ │ 2 │b = 234567 "#,
@@ -643,27 +643,27 @@ pub mod tests {
#[test]
fn test_two_plus_lines_spaces_and_ansi() {
- DeltaTest::with(&[
+ DeltaTest::with_args(&[
"--side-by-side",
"--width",
"41",
"--line-fill-method=spaces",
])
- .with_input(TWO_PLUS_LINES_DIFF)
.explain_ansi()
- .expect(r#"
+ .with_input(TWO_PLUS_LINES_DIFF)
+ .expect_after_header(r#"
(blue)│(88) (blue)│(normal) (blue)│(28) 1 (blue)│(231 22)a (203)=(231) (141)1(normal 22) (normal)
(blue)│(88) (blue)│(normal) (blue)│(28) 2 (blue)│(231 22)b (203)=(231) (141)234567(normal 22) (normal)"#);
- DeltaTest::with(&[
+ DeltaTest::with_args(&[
"--side-by-side",
"--width",
"41",
"--line-fill-method=ansi",
])
- .with_input(TWO_PLUS_LINES_DIFF)
.explain_ansi()
- .expect(r#"
+ .with_input(TWO_PLUS_LINES_DIFF)
+ .expect_after_header(r#"
(blue)│(88) (blue)│(normal) (blue) │(28) 1 (blue)│(231 22)a (203)=(231) (141)1(normal)
(blue)│(88) (blue)│(normal) (blue) │(28) 2 (blue)│(231 22)b (203)=(231) (141)234567(normal)"#);
}
@@ -701,14 +701,14 @@ pub mod tests {
#[test]
fn test_one_minus_one_plus_line() {
- DeltaTest::with(&[
+ DeltaTest::with_args(&[
"--side-by-side",
"--width",
"40",
"--line-fill-method=spaces",
])
.with_input(ONE_MINUS_ONE_PLUS_LINE_DIFF)
- .expect(
+ .expect_after_header(
r#"
│ 1 │a = 1 │ 1 │a = 1
│ 2 │b = 2 │ 2 │bb = 2 "#,
diff --git a/src/handlers/hunk.rs b/src/handlers/hunk.rs
index b541d326..2abd4187 100644
--- a/src/handlers/hunk.rs
+++ b/src/handlers/hunk.rs
@@ -281,11 +281,11 @@ mod tests {
#[test]
fn test_word_diff() {
- DeltaTest::with(&[])
+ DeltaTest::with_args(&[])
.with_calling_process("git diff --word-diff")
- .with_input(GIT_DIFF_WORD_DIFF)
.explain_ansi()
- .expect_skip(
+ .with_input(GIT_DIFF_WORD_DIFF)
+ .expect_after_skip(
11,
"
#indent_mark
@@ -299,11 +299,11 @@ mod tests {
#[test]
fn test_color_words() {
- DeltaTest::with(&[])
+ DeltaTest::with_args(&[])
.with_calling_process("git diff --color-words")
- .with_input(GIT_DIFF_COLOR_WORDS)
.explain_ansi()
- .expect_skip(
+ .with_input(GIT_DIFF_COLOR_WORDS)
+ .expect_after_skip(
11,
"
#indent_mark
@@ -318,15 +318,15 @@ mod tests {
#[test]
#[ignore] // FIXME
fn test_color_words_map_styles() {
- DeltaTest::with(&[
+ DeltaTest::with_args(&[
"--map-styles",
"red => bold yellow #dddddd, green => bold blue #dddddd",
])
.with_calling_process("git diff --color-words")
- .with_input(GIT_DIFF_COLOR_WORDS)
.explain_ansi()
+ .with_input(GIT_DIFF_COLOR_WORDS)
.inspect()
- .expect_skip(
+ .expect_after_skip(
11,
r##"
#indent_mark
@@ -340,10 +340,10 @@ mod tests {
#[test]
fn test_hunk_line_style_raw() {
- DeltaTest::with(&["--minus-style", "raw", "--plus-style", "raw"])
- .with_input(GIT_DIFF_WITH_COLOR)
+ DeltaTest::with_args(&["--minus-style", "raw", "--plus-style", "raw"])
.explain_ansi()
- .expect_skip(
+ .with_input(GIT_DIFF_WITH_COLOR)
+ .expect_after_skip(
14,
"
(red)aaa(normal)
@@ -354,7 +354,7 @@ mod tests {
#[test]
fn test_hunk_line_style_raw_map_styles() {
- DeltaTest::with(&[
+ DeltaTest::with_args(&[
"--minus-style",
"raw",
"--plus-style",
@@ -362,9 +362,9 @@ mod tests {
"--map-styles",
"red => bold blue, green => dim yellow",
])
- .with_input(GIT_DIFF_WITH_COLOR)
.explain_ansi()
- .expect_skip(
+ .with_input(GIT_DIFF_WITH_COLOR)
+ .expect_after_skip(
14,
"
(bold blue)aaa(normal)
diff --git a/src/tests/integration_test_utils.rs b/src/tests/integration_test_utils.rs
index a1ec62e3..2e7e24cf 100644
--- a/src/tests/integration_test_utils.rs
+++ b/src/tests/integration_test_utils.rs
@@ -12,6 +12,7 @@ use crate::cli;
use crate::config;
use crate::delta::delta;
use crate::git_config::GitConfig;
+use crate::tests::test_utils;
use crate::utils::process::tests::FakeParentArgs;
pub fn make_options_from_args_and_git_config(
@@ -94,19 +95,25 @@ pub fn get_line_of_code_from_delta(
// line1"#;` // line 2 etc.
// ignore the first newline and compare the following `lines()` to those produced
// by `have`, `skip`-ping the first few. The leading spaces of the first line
+// to indicate the last line in the list). The leading spaces of the first line
// are stripped from every following line (and verified), unless the first line
// marks the indentation level with `#indent_mark`.
-pub fn lines_match(expected: &str, have: &str, skip: Option<usize>) {
+pub fn assert_lines_match_after_skip(skip: usize, expected: &str, have: &str) {
let mut exp = expected.lines().peekable();
- assert!(exp.next() == Some(""), "first line must be empty");
- let line1 = exp.peek().unwrap();
+ let mut line1 = exp.next().unwrap();
+ let allow_partial = line1 == "#partial";
+ assert!(
+ allow_partial || line1.is_empty(),
+ "first line must be empty or \"#partial\""
+ );
+ line1 = exp.peek().unwrap();
let indentation = line1.find(|c| c != ' ').unwrap_or(0);
let ignore_indent = &line1[indentation..] == "#indent_mark";
if ignore_indent {
let _indent_mark = exp.next();
}
- let mut it = have.lines().skip(skip.unwrap_or(0));
+ let mut it = have.lines().skip(skip);
for (i, expected) in exp.enumerate() {
if !ignore_indent {
@@ -119,27 +126,51 @@ pub fn lines_match(expected: &str, have: &str, skip: Option<usize>) {
assert_eq!(
&expected[indentation..],
it.next().unwrap(),
- "on line {} of input",
- i + 1
+ "on line {} of input:\n{}",
+ i + 1,
+ delineated_string(have),
);
}
- assert_eq!(it.next(), None, "more input than expected");
+ if !allow_partial {
+ assert_eq!(it.next(), None, "more input than expected");
+ }
+}
+
+pub fn assert_lines_match(expected: &str, have: &str) {
+ assert_lines_match_after_skip(0, expected, have)
+}
+
+pub fn delineated_string(txt: &str) -> String {
+ let top = "▼".repeat(100);
+ let btm = "▲".repeat(100);
+ let nl = "\n";
+ top + &nl + txt + &nl + &btm
}
pub struct DeltaTest {
config: config::Config,
calling_process: Option<String>,
+ explain_ansi_: bool,
}
impl DeltaTest {
- pub fn with(args: &[&str]) -> Self {
+ pub fn with_args(args: &[&str]) -> Self {
Self {
config: make_config_from_args(args),
calling_process: None,
+ explain_ansi_: false,
+ }
+ }
+
+ pub fn with_config(config: config::Config) -> Self {
+ Self {
+ config: config,
+ calling_process: None,
+ explain_ansi_: false,
}
}
- pub fn set_cfg<F>(mut self, f: F) -> Self
+ pub fn set_config<F>(mut self, f: F) -> Self
where
F: Fn(&mut config::Config),
{
@@ -152,22 +183,30 @@ impl DeltaTest {
self
}
- pub fn with_config_and_input(config: &config::Config, input: &str) -> DeltaTestOutput {
- DeltaTestOutput {
- output: run_delta(input, &config),
- explain_ansi_: false,
- }
+ pub fn explain_ansi(mut self) -> Self {
+ self.explain_ansi_ = true;
+ self
}
pub fn with_input(&self, input: &str) -> DeltaTestOutput {
let _args = FakeParentArgs::for_scope(self.calling_process.as_deref().unwrap_or(""));
- DeltaTest::with_config_and_input(&self.config, input)
+ let raw = run_delta(input, &self.config);
+ let cooked = if self.explain_ansi_ {
+ ansi::explain_ansi(&raw, false)
+ } else {
+ ansi::strip_ansi_codes(&raw)
+ };
+
+ DeltaTestOutput {
+ raw_output: raw,
+ output: cooked,
+ }
}
}
pub struct DeltaTestOutput {
- output: String,
- explain_ansi_: bool,
+ pub raw_output: String,
+ pub output: String,
}
impl DeltaTestOutput {
@@ -175,42 +214,58 @@ impl DeltaTestOutput {
/// with ASCII explanation of ANSI escape sequences.
#[allow(unused)]
pub fn inspect(self) -> Self {
- eprintln!("{}", "▼".repeat(100));
- eprintln!("{}", self.format_output());
- eprintln!("{}", "▲".repeat(100));
+ eprintln!("{}", delineated_string(&self.output.as_str()));
self
}
/// Print raw output, with any ANSI escape sequences.
#[allow(unused)]
pub fn inspect_raw(self) -> Self {
- eprintln!("{}", "▼".repeat(100));
- eprintln!("{}", self.output);
- eprintln!("{}", "▲".repeat(100));
+ eprintln!("{}", delineated_string(&self.raw_output));
self
}
- pub fn explain_ansi(mut self) -> Self {
- self.explain_ansi_ = true;
+ pub fn expect_after_skip(self, skip: usize, expected: &str) -> Self {
+ assert_lines_match_after_skip(skip, expected, &self.output);
self
}
- pub fn expect_skip(self, skip: usize, expected: &str) -> String {
- let processed = self.format_output();
- lines_match(expected, &processed, Some(skip));
- processed
+ pub fn expect(self, expected: &str) -> Self {
+ self.expect_after_skip(0, expected)
}
- pub fn expect(self, expected: &str) -> String {
- self.expect_skip(crate::config::HEADER_LEN, expected)
+ pub fn expect_after_header(self, expected: &str) -> Self {
+ self.expect_after_skip(crate::config::HEADER_LEN, expected)
}
- fn format_output(&self) -> String {
- if self.explain_ansi_ {
- ansi::explain_ansi(&self.output, false)
- } else {
- ansi::strip_ansi_codes(&self.output)
- }
+ pub fn expect_contains(self, expected: &str) -> Self {
+ assert!(
+ self.output.contains(expected),
+ "Output does not contain \"{}\":\n{}",
+ expected,
+ delineated_string(&self.output.as_str())
+ );
+ self
+ }
+
+ pub fn expect_raw_contains(self, expected: &str) -> Self {
+ assert!(
+ self.raw_output.contains(expected),
+ "Raw output does not contain \"{}\":\n{}",
+ expected,
+ delineated_string(&self.raw_output.as_str())
+ );
+ self
+ }
+
+ pub fn expect_contains_once(self, expected: &str) -> Self {
+ assert!(
+ test_utils::contains_once(&self.output, expected),
+ "Output does not contain \"{}\" exactly once:\n{}",
+ expected,
+ delineated_string(&self.output.as_str())
+ );
+ self
}
}
@@ -235,30 +290,30 @@ pub mod tests {
one
two
three"#;
- lines_match(expected, "one\ntwo\nthree", None);
+ assert_lines_match(expected, "one\ntwo\nthree");
let expected = r#"
#indent_mark
one
2
three"#;
- lines_match(expected, "one\n 2\nthree", None);
+ assert_lines_match(expected, "one\n 2\nthree");
let expected = r#"
#indent_mark
1
2
3"#;
- lines_match(expected, " 1 \n 2 \n 3", None);
+ assert_lines_match(expected, " 1 \n 2 \n 3");
let expected = r#"
#indent_mark
1
ignored! 2
3"#;
- lines_match(expected, " 1 \n 2 \n 3", None);
+ assert_lines_match(expected, " 1 \n 2 \n 3");
let expected = "\none\ntwo\nthree";
- lines_match(expected, "one\ntwo\nthree", None);
+ assert_lines_match(expected, "one\ntwo\nthree");
}
#[test]
@@ -266,7 +321,7 @@ ignored! 2
fn test_lines_match_no_nl() {
let expected = r#"bad
lines"#;
- lines_match(expected, "bad\nlines", None);
+ assert_lines_match(expected, "bad\nlines");
}
#[test]
@@ -276,7 +331,7 @@ ignored! 2
one
two
three"#;
- lines_match(expected, "one\ntwo\nthree\nFOUR", None);
+ assert_lines_match(expected, "one\ntwo\nthree\nFOUR");
}
#[test]
@@ -286,7 +341,7 @@ ignored! 2
ok
wrong_indent
"#;
- lines_match(expected, "ok", None);
+ assert_lines_match(expected, "ok");
}
#[test]
@@ -296,18 +351,17 @@ ignored! 2
ok
wrong_indent
"#;
- lines_match(expected, "ok", None);
+ assert_lines_match(expected, "ok");
}
#[test]
fn test_delta_test() {
let input = "@@ -1,1 +1,1 @@ fn foo() {\n-1\n+2\n";
- DeltaTest::with(&["--raw"])
- .set_cfg(|c| c.pager = None)
- .set_cfg(|c| c.line_numbers = true)
+ DeltaTest::with_args(&["--raw"])
+ .set_config(|c| c.pager = None)
+ .set_config(|c| c.line_numbers = true)
.with_input(input)
- .expect_skip(
- 0,
+ .expect(
r#"
#indent_mark
@@ -1,1 +1,1 @@ fn foo() {
@@ -315,18 +369,19 @@ ignored! 2
⋮ 1 │+2"#,
);
- DeltaTest::with(&[]).with_input(input).expect_skip(
- 4,
- r#"
+ DeltaTest::with_args(&[])
+ .with_input(input)
+ .expect_after_skip(
+ 4,
+ r#"
1
2"#,
- );
+ );
- DeltaTest::with(&["--raw"])
- .with_input(input)
+ DeltaTest::with_args(&["--raw"])
.explain_ansi()
- .expect_skip(
- 0,
+ .with_input(input)
+ .expect(
"\n\
(normal)@@ -1,1 +1,1 @@ fn foo() {\n\
(red)-1(normal)\n\
diff --git a/src/tests/test_example_diffs.rs b/src/tests/test_example_diffs.rs
index a135a9b2..6e0c542c 100644
--- a/src/tests/test_example_diffs.rs
+++ b/src/tests/test_example_diffs.rs
@@ -7,67 +7,53 @@ mod tests {
use crate::style;
use crate::tests::ansi_test_utils::ansi_test_utils;
use crate::tests::integration_test_utils;
- use crate::tests::test_utils;
- use regex::Regex;
+ use crate::tests::integration_test_utils::DeltaTest;
#[test]
fn test_added_file() {
- let config = integration_test_utils::make_config_from_args(&[]);
- let output = integration_test_utils::run_delta(ADDED_FILE_INPUT, &config);
- let output = strip_ansi_codes(&output);
- assert!(output.contains("\nadded: a.py\n"));
+ DeltaTest::with_args(&[])
+ .with_input(ADDED_FILE_INPUT)
+ .expect_contains("\nadded: a.py\n");
}
#[test]
#[ignore] // #128
fn test_added_empty_file() {
- let config = integration_test_utils::make_config_from_args(&[]);
- let output = integration_test_utils::run_delta(ADDED_EMPTY_FILE, &config);
- let output = strip_ansi_codes(&output);
- assert!(output.contains("\nadded: file\n"));
+ DeltaTest::with_args(&[])
+ .with_input(ADDED_EMPTY_FILE)
+ .expect_contains("\nadded: file\n");
}
#[test]
fn test_added_file_directory_path_containing_space() {
- let config = integration_test_utils::make_config_from_args(&[]);
- let output =
- integration_test_utils::run_delta(ADDED_FILES_DIRECTORY_PATH_CONTAINING_SPACE, &config);
- let output = strip_ansi_codes(&output);
- assert!(output.contains("\nadded: with space/file1\n"));
- assert!(output.contains("\nadded: nospace/file2\n"));
+ DeltaTest::with_args(&[])
+ .with_input(ADDED_FILES_DIRECTORY_PATH_CONTAINING_SPACE)
+ .expect_contains("\nadded: with space/file1\n")
+ .expect_contains("\nadded: nospace/file2\n");
}
#[test]
fn test_renamed_file() {
- let config = integration_test_utils::make_config_from_args(&[]);
- let output = integration_test_utils::run_delta(RENAMED_FILE_INPUT, &config);
- let output = strip_ansi_codes(&output);
- assert!(test_utils::contains_once(
- &output,
- "\nrenamed: a.py ⟶ b.py\n"
- ));
+ DeltaTest::with_args(&[])
+ .with_input(RENAMED_FILE_INPUT)
+ .expect_contains_once("\nrenamed: a.py ⟶ b.py\n");
}
#[test]
fn test_copied_file() {
- let config = integration_test_utils::make_config_from_args(&[]);
- let output = integration_test_utils::run_delta(GIT_DIFF_WITH_COPIED_FILE, &config);
- let output = strip_ansi_codes(&output);
- assert!(test_utils::contains_once(
- &output,
- "\ncopied: first_file ⟶ copied_file\n"
- ));
+ DeltaTest::with_args(&[])
+ .with_input(GIT_DIFF_WITH_COPIED_FILE)
+ .expect_contains_once("\ncopied: first_file ⟶ copied_file\n");
}
#[test]
fn test_renamed_file_with_changes() {
- let config = integration_test_utils::make_config_from_args(&[]);
- let output = integration_test_utils::run_delta(RENAMED_FILE_WITH_CHANGES_INPUT, &config);
- let output = strip_ansi_codes(&output);
- println!("{}", output);
- assert!(test_utils::contains_once(
- &output,
- "\nrenamed: Casks/font-dejavusansmono-nerd-font.rb ⟶ Casks/font-dejavu-sans-mono-nerd-font.rb\n"));
+ let t = DeltaTest::with_args(&[])
+ .with_input(RENAMED_FILE_WITH_CHANGES_INPUT)
+ .expect_contains_once(
+ "\nrenamed: Casks/font-dejavusansmono-nerd-font.rb ⟶ Casks/font-dejavu-sans-mono-nerd-font.rb\n"
+ );
+ println!("{}", t.output);
}
#[test]
@@ -1587,84 +1573,65 @@ src/align.rs:71: impl<'a> Alignment<'a> { │
#[test]
fn test_file_mode_change_gain_executable_bit() {
- let config = integration_test_utils::make_config_from_args(&[]);
- let output = integration_test_utils::run_delta(
- GIT_DIFF_FILE_MODE_CHANGE_GAIN_EXECUTABLE_BIT,
- &config,
- );
- let output = strip_ansi_codes(&output);
- assert!(output.contains(r"src/delta.rs: mode +x"));
+ DeltaTest::with_args(&[])
+ .with_input(GIT_DIFF_FILE_MODE_CHANGE_GAIN_EXECUTABLE_BIT)
+ .expect_contains(r"src/delta.rs: mode +x");
}
#[test]
fn test_file_mode_change_lose_executable_bit() {
- let config = integration_test_utils::make_config_from_args(&[]);
- let output = integration_test_utils::run_delta(
- GIT_DIFF_FILE_MODE_CHANGE_LOSE_EXECUTABLE_BIT,
- &config,
- );
- let output = strip_ansi_codes(&output);
- assert!(output.contains(r"src/delta.rs: mode -x"));
+ DeltaTest::with_args(&[])
+ .with_input(GIT_DIFF_FILE_MODE_CHANGE_LOSE_EXECUTABLE_BIT)
+ .expect_contains(r"src/delta.rs: mode -x");
}
#[test]
fn test_file_mode_change_unexpected_bits() {
- let config =
- integration_test_utils::make_config_from_args(&["--navigate", "--right-arrow=->"]);
- let output =
- integration_test_utils::run_delta(GIT_DIFF_FILE_MODE_CHANGE_UNEXPECTED_BITS, &config);
- let output = strip_ansi_codes(&output);
- assert!(output.contains(r"Δ src/delta.rs: 100700 -> 100644"));
+ DeltaTest::with_args(&["--navigate", "--right-arrow=->"])
+ .with_input(GIT_DIFF_FILE_MODE_CHANGE_UNEXPECTED_BITS)
+ .expect_contains(r"Δ src/delta.rs: 100700 -> 100644");
}
#[test]
fn test_file_mode_change_with_diff() {
- let config = integration_test_utils::make_config_from_args(&[
- "--navigate",
- "--keep-plus-minus-markers",
- ]);
- let output =
- integration_test_utils::run_delta(GIT_DIFF_FILE_MODE_CHANGE_WITH_DIFF, &config);
- let output = strip_ansi_codes(&output);
- let re = Regex::new(r"\n─+\n").unwrap();
- let output = re.replace(&output, "\n-----\n");
- assert!(output.contains(
- "Δ src/script: mode +x
------
-
-─────┐
-• 1: │
-─────┘
--#!/bin/sh
-+#!/bin/bash
-"
- ));
+ DeltaTest::with_args(&["--navigate", "--keep-plus-minus-markers"])
+ .with_input(GIT_DIFF_FILE_MODE_CHANGE_WITH_DIFF)
+ .expect_contains("Δ src/script: mode +x")
+ .expect_after_skip(
+ 5,
+ "
+ ─────┐
+ • 1: │
+ ─────┘
+ -#!/bin/sh
+ +#!/bin/bash",
+ );
}
#[test]
fn test_hyperlinks_commit_link_format() {
- let config = integration_test_utils::make_config_from_args(&[
- // If commit-style is not set then the commit line is handled in raw
- // mode, in which case we only format hyperlinks if output is a tty;
- // this causes the test to fail on Github Actions, but pass locally
- // if output is left going to the screen.
- "--commit-style",
- "blue",
- "--hyperlinks",
- "--hyperlinks-commit-link-format",
- "https://invent.kde.org/utilities/konsole/-/commit/{commit}",
- ]);
- let output = integration_test_utils::run_delta(GIT_DIFF_SINGLE_HUNK, &config);
- assert!(output.contains(r"https://invent.kde.org/utilities/konsole/-/commit/94907c0f136f46dc46ffae2dc92dca9af7eb7c2e"));
+ // If commit-style is not set then the commit line is handled in raw
+ // mode, in which case we only format hyperlinks if output is a tty;
+ // this causes the test to fail on Github Actions, but pass locally
+ // if output is left going to the screen.
+ DeltaTest::with_args(&[
+ "--commit-style",
+ "blue",
+