Introduce a DSL to replace the plain bash scripts

It's really important for `git-check-assertions` blocks to be 'obviously
correct', so that we don't need to... test the tests that test the tests.

Let's introduce a little DSL that is less error-prone than a plain bash
script.
This commit is contained in:
Sven van Heugten 2026-04-16 06:25:28 +02:00
parent ad10b2cc4c
commit 4704cc088d
No known key found for this signature in database
GPG key ID: D612F88666F4F660
3 changed files with 130 additions and 127 deletions

View file

@ -43,7 +43,7 @@ commit_with_assertion() {
}
@test "should not run any assertion blocks when on main" {
commit_with_assertion "touch ../test"
commit_with_assertion "[success] touch ../test"
run git-check-assertions
@ -87,7 +87,7 @@ commit_with_assertion() {
}
@test "should not run any assertion blocks from main when on a feature branch" {
commit_with_assertion "touch ../test"
commit_with_assertion "[success] touch ../test"
git checkout -b feature
git commit --allow-empty -m "feature"
@ -100,7 +100,7 @@ commit_with_assertion() {
@test "should not run any assertion blocks from master when on a feature branch" {
init_repo "$BATS_TEST_TMPDIR/repo-master" master
commit_with_assertion "touch ../test"
commit_with_assertion "[success] touch ../test"
git checkout -b feature
git commit --allow-empty -m "feature"
@ -112,8 +112,8 @@ commit_with_assertion() {
@test "should run all succeeding assertion blocks on the feature branch and finally return to the original branch" {
git checkout -b feature
commit_with_assertion "touch ../test1"
commit_with_assertion "touch ../test2"
commit_with_assertion "[success] touch ../test1"
commit_with_assertion "[success] touch ../test2"
run git-check-assertions
@ -130,11 +130,11 @@ commit_with_assertion() {
test
\`\`\`git-check-assertions
touch ../test1
[success] touch ../test1
\`\`\`
\`\`\`git-check-assertions
touch ../test2
[success] touch ../test2
\`\`\`
EOF
@ -159,11 +159,11 @@ commit_with_assertion() {
update
\`\`\`git-check-assertions
git checkout HEAD~
[success] git checkout HEAD~
\`\`\`
\`\`\`git-check-assertions
grep new readme
[success] grep new readme
\`\`\`
EOF
@ -174,8 +174,8 @@ commit_with_assertion() {
@test "should stop at the first failing assertion block and return to the original branch" {
git checkout -b feature
commit_with_assertion "touch ../test1 && exit 3"
commit_with_assertion "touch ../test2"
commit_with_assertion "[success] touch ../test1 && exit 3"
commit_with_assertion "[success] touch ../test2"
run git-check-assertions
@ -188,7 +188,7 @@ commit_with_assertion() {
@test "should restore worktree when finished" {
git checkout -b feature
commit_with_assertion 'echo blah >> readme'
commit_with_assertion '[success] echo blah >> readme'
run git-check-assertions
@ -198,8 +198,8 @@ commit_with_assertion() {
@test "should restore worktree between commits" {
git checkout -b feature
commit_with_assertion 'echo blah >> readme'
commit_with_assertion 'cp readme ../test'
commit_with_assertion '[success] echo blah >> readme'
commit_with_assertion '[success] cp readme ../test'
run git-check-assertions
@ -209,7 +209,7 @@ commit_with_assertion() {
@test "should restore worktree after a failure" {
git checkout -b feature
commit_with_assertion $'echo blah >> readme\nexit 3'
commit_with_assertion $'[success] echo blah >> readme\n[success] exit 3'
run git-check-assertions
@ -219,7 +219,7 @@ commit_with_assertion() {
@test "should restore index when finished" {
git checkout -b feature
commit_with_assertion $'echo blah >> readme\ngit add readme'
commit_with_assertion $'[success] echo blah >> readme\n[success] git add readme'
run git-check-assertions
@ -229,8 +229,8 @@ commit_with_assertion() {
@test "should restore index between commits" {
git checkout -b feature
commit_with_assertion $'echo blah >> readme\ngit add readme'
commit_with_assertion 'cp readme ../test'
commit_with_assertion $'[success] echo blah >> readme\n[success] git add readme'
commit_with_assertion '[success] cp readme ../test'
run git-check-assertions
@ -240,7 +240,7 @@ commit_with_assertion() {
@test "should restore index after a failure" {
git checkout -b feature
commit_with_assertion $'echo blah >> readme\ngit add readme\nexit 3'
commit_with_assertion $'[success] echo blah >> readme\n[success] git add readme\n[success] exit 3'
run git-check-assertions
@ -250,7 +250,7 @@ commit_with_assertion() {
@test "should skip cached commits on subsequent runs" {
git checkout -b feature
commit_with_assertion "touch ../test"
commit_with_assertion "[success] touch ../test"
run git-check-assertions
@ -266,7 +266,7 @@ commit_with_assertion() {
@test "should not cache failed commits" {
git checkout -b feature
commit_with_assertion "touch ../test && exit 3"
commit_with_assertion "[success] touch ../test && exit 3"
run git-check-assertions
@ -282,8 +282,8 @@ commit_with_assertion() {
@test "should skip cached commits when multiple commits are cached" {
git checkout -b feature
commit_with_assertion "touch ../test1"
commit_with_assertion "touch ../test2"
commit_with_assertion "[success] touch ../test1"
commit_with_assertion "[success] touch ../test2"
run git-check-assertions
@ -303,10 +303,10 @@ commit_with_assertion() {
git checkout -b feature
echo commit1 >readme
git add readme
commit_with_assertion 'grep commit1 readme'
commit_with_assertion '[success] grep commit1 readme'
echo commit2 >readme
git add readme
commit_with_assertion 'grep commit2 readme'
commit_with_assertion '[success] grep commit2 readme'
run git-check-assertions
@ -322,7 +322,7 @@ commit_with_assertion() {
echo goodbye >src
echo 'grep goodbye src' >tests
git add src tests
commit_with_assertion $'git checkout HEAD~ src\nrun bash tests\nassert_failure'
commit_with_assertion $'[success] git checkout HEAD~ src\n[failure] bash tests'
run git-check-assertions
@ -330,18 +330,18 @@ commit_with_assertion() {
assert_file_contains src goodbye
}
@test "assert_success should succeed if the executed command succeeded" {
@test "a [success] command should succeed if the executed command succeeded" {
git checkout -b feature
commit_with_assertion $'run exit 0\nassert_success'
commit_with_assertion '[success] exit 0'
run git-check-assertions
assert_success
}
@test "assert_success should fail if the executed command failed" {
@test "a [success] command should fail if the executed command failed" {
git checkout -b feature
commit_with_assertion $'run exit 1\nassert_success'
commit_with_assertion '[success] exit 1'
run git-check-assertions
@ -349,18 +349,18 @@ commit_with_assertion() {
assert_output --partial "Expected command to succeed, but it failed."
}
@test "assert_failure should succeed if the executed command failed" {
@test "a [failure] command should succeed if the executed command failed" {
git checkout -b feature
commit_with_assertion $'run exit 1\nassert_failure'
commit_with_assertion '[failure] exit 1'
run git-check-assertions
assert_success
}
@test "assert_failure should fail if the executed command succeeded" {
@test "a [failure] command should fail if the executed command succeeded" {
git checkout -b feature
commit_with_assertion $'run exit 0\nassert_failure'
commit_with_assertion '[failure] exit 0'
run git-check-assertions
@ -368,47 +368,47 @@ commit_with_assertion() {
assert_output --partial "Expected command to fail, but it succeeded."
}
@test "assert_output should succeed if the output matches the given string" {
@test "an output line should succeed if the output contains the given string" {
git checkout -b feature
commit_with_assertion $'run echo hello\nassert_output hello'
commit_with_assertion $'[success] echo hello\nhello'
run git-check-assertions
assert_success
}
@test "assert_output should fail if the output does not match the given string" {
@test "an output line should fail if the output does not contain the given string" {
git checkout -b feature
commit_with_assertion $'run echo hello\nassert_output goodbye'
commit_with_assertion $'[success] echo hello\ngoodbye'
run git-check-assertions
assert_failure
assert_output --partial "Expected output to equal: goodbye"
assert_output --partial "Expected output to contain: goodbye"
assert_output --partial "Actual output: hello"
}
@test "assert_output should also check stderr output" {
@test "an output line should also check stderr output" {
git checkout -b feature
commit_with_assertion $'run sh -c "echo err 1>&2"\nassert_output err'
commit_with_assertion $'[success] sh -c "echo err 1>&2"\nerr'
run git-check-assertions
assert_success
}
@test "assert_output --partial should succeed if output contains the given string" {
@test "multiple output lines should all be checked against the same command output" {
git checkout -b feature
commit_with_assertion $'run echo hello\nassert_output --partial ell'
commit_with_assertion $'[success] printf "hello\\n"\nhell\nello'
run git-check-assertions
assert_success
}
@test "assert_output --partial should fail if output does not contain the given string" {
@test "an output line should fail with the missing substring" {
git checkout -b feature
commit_with_assertion $'run echo hello\nassert_output --partial xyz'
commit_with_assertion $'[success] echo hello\nxyz'
run git-check-assertions
@ -417,9 +417,9 @@ commit_with_assertion() {
assert_output --partial "Actual output: hello"
}
@test "run should print command output" {
@test "executed commands should print command output" {
git checkout -b feature
commit_with_assertion $'run sh -c "echo -n hello; echo -n world"\nassert_success'
commit_with_assertion '[success] sh -c "echo -n hello; echo -n world"'
run git-check-assertions