Add devshell and initial bats tests

This commit is contained in:
Sven van Heugten 2026-03-05 19:29:32 +01:00
parent af8fae68fe
commit d3b3862040
No known key found for this signature in database
GPG key ID: D612F88666F4F660
4 changed files with 102 additions and 4 deletions

50
test/mechanicaldiff.bats Executable file
View file

@ -0,0 +1,50 @@
#!/usr/bin/env bats
setup() {
set -euo pipefail
bats_load_library bats-support
bats_load_library bats-assert
DIR="$(cd "$(dirname "$BATS_TEST_FILENAME")" >/dev/null 2>&1 && pwd)"
PATH="$DIR/../bin:$PATH"
}
@test "keeps hunk when replacement matches" {
run bash -c 'cat <<"EOF" | mechanicaldiff.py foo bar
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_success
expected="$(
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" {
run bash -c 'cat <<"EOF" | mechanicaldiff.py foo bar
diff --git a/file.txt b/file.txt
index 1111111..2222222 100644
--- a/file.txt
+++ b/file.txt
@@ -1,1 +1,1 @@
-foo
+baz
EOF'
assert_success
assert_output ""
}