summaryrefslogtreecommitdiff
path: root/src/tests/test_example_diffs.rs
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 /src/tests/test_example_diffs.rs
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
Diffstat (limited to 'src/tests/test_example_diffs.rs')
-rw-r--r--src/tests/test_example_diffs.rs157
1 files changed, 62 insertions, 95 deletions
diff --git a/src/tests/test_example_diffs.rs b/src/tests/test_example_diffs.rs
index a135a9b..6e0c542 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",
+ "--hyperlinks",
+ "--hyperlinks-commit-link-format",
+ "https://invent.kde.org/utilities/konsole/-/commit/{commit}",
+ ])
+ .with_input(GIT_DIFF_SINGLE_HUNK)
+ .expect_raw_contains(
+ r"https://invent.kde.org/utilities/konsole/-/commit/94907c0f136f46dc46ffae2dc92dca9af7eb7c2e"
+ );
}
#[test]
fn test_filenames_with_spaces() {
- let config = integration_test_utils::make_config_from_args(&[]);
- let output =
- integration_test_utils::run_delta(GIT_DIFF_NO_INDEX_FILENAMES_WITH_SPACES, &config);
- let output = strip_ansi_codes(&output);
- assert!(output.contains("a b ⟶ c d\n"));
+ DeltaTest::with_args(&[])
+ .with_input(GIT_DIFF_NO_INDEX_FILENAMES_WITH_SPACES)
+ .expect_contains("a b ⟶ c d\n");
}
const GIT_DIFF_SINGLE_HUNK: &str = "\