Rewrite the tests to use a real diff
This commit is contained in:
parent
d3b3862040
commit
ceac602325
3 changed files with 14 additions and 30 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
stdenv,
|
stdenv,
|
||||||
lib,
|
lib,
|
||||||
bats,
|
bats,
|
||||||
|
gitMinimal,
|
||||||
python3,
|
python3,
|
||||||
python3Packages,
|
python3Packages,
|
||||||
shellcheck-minimal,
|
shellcheck-minimal,
|
||||||
|
|
@ -38,6 +39,7 @@ stdenv.mkDerivation {
|
||||||
p.bats-support
|
p.bats-support
|
||||||
p.bats-file
|
p.bats-file
|
||||||
]))
|
]))
|
||||||
|
gitMinimal
|
||||||
python3Packages.flake8
|
python3Packages.flake8
|
||||||
shellcheck-minimal
|
shellcheck-minimal
|
||||||
shfmt
|
shfmt
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
p.bats-support
|
p.bats-support
|
||||||
p.bats-file
|
p.bats-file
|
||||||
]))
|
]))
|
||||||
|
pkgs.gitMinimal
|
||||||
pkgs.python3
|
pkgs.python3
|
||||||
pkgs.python3Packages.flake8
|
pkgs.python3Packages.flake8
|
||||||
pkgs.shellcheck
|
pkgs.shellcheck
|
||||||
|
|
|
||||||
|
|
@ -11,40 +11,21 @@ setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "keeps hunk when replacement matches" {
|
@test "keeps hunk when replacement matches" {
|
||||||
run bash -c 'cat <<"EOF" | mechanicaldiff.py foo bar
|
printf "%s\n" "foo" >"$BATS_TEST_TMPDIR/old"
|
||||||
diff --git a/file.txt b/file.txt
|
printf "%s\n" "bar" >"$BATS_TEST_TMPDIR/new"
|
||||||
index 1111111..2222222 100644
|
diff_output="$(git diff --no-index "$BATS_TEST_TMPDIR/old" \
|
||||||
--- a/file.txt
|
"$BATS_TEST_TMPDIR/new" || true)"
|
||||||
+++ b/file.txt
|
run mechanicaldiff.py foo bar <<<"$diff_output"
|
||||||
@@ -1,1 +1,1 @@
|
|
||||||
-foo
|
|
||||||
+bar
|
|
||||||
EOF'
|
|
||||||
assert_success
|
assert_success
|
||||||
expected="$(
|
assert_output "$diff_output"
|
||||||
cat <<'EOF'
|
|
||||||
diff --git a/file.txt b/file.txt
|
|
||||||
index 1111111..2222222 100644
|
|
||||||
--- a/file.txt
|
|
||||||
+++ b/file.txt
|
|
||||||
@@ -1,1 +1,1 @@
|
|
||||||
-foo
|
|
||||||
+bar
|
|
||||||
EOF
|
|
||||||
)"
|
|
||||||
assert_output "$expected"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "drops diff when replacement does not match" {
|
@test "drops diff when replacement does not match" {
|
||||||
run bash -c 'cat <<"EOF" | mechanicaldiff.py foo bar
|
printf "%s\n" "foo" >"$BATS_TEST_TMPDIR/old"
|
||||||
diff --git a/file.txt b/file.txt
|
printf "%s\n" "baz" >"$BATS_TEST_TMPDIR/new"
|
||||||
index 1111111..2222222 100644
|
git diff --no-index "$BATS_TEST_TMPDIR/old" "$BATS_TEST_TMPDIR/new" \
|
||||||
--- a/file.txt
|
>"$BATS_TEST_TMPDIR/diff" || true
|
||||||
+++ b/file.txt
|
run mechanicaldiff.py foo bar <"$BATS_TEST_TMPDIR/diff"
|
||||||
@@ -1,1 +1,1 @@
|
|
||||||
-foo
|
|
||||||
+baz
|
|
||||||
EOF'
|
|
||||||
assert_success
|
assert_success
|
||||||
assert_output ""
|
assert_output ""
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue