Introduce assert_failure

This commit is contained in:
Sven van Heugten 2026-03-03 20:23:39 +01:00
parent 1a10b24b06
commit f9d6696687
No known key found for this signature in database
GPG key ID: D612F88666F4F660
2 changed files with 26 additions and 1 deletions

View file

@ -46,7 +46,13 @@ assert_success() {
exit 1
fi
}
export -f run assert_success
assert_failure() {
if [ "$status" -eq 0 ]; then
echo "Expected command to fail, but it succeeded."
exit 1
fi
}
export -f run assert_success assert_failure
# main flow
orig_ref="$(git symbolic-ref --quiet --short HEAD || git rev-parse HEAD)"

View file

@ -131,3 +131,22 @@ commit_with_assertion() {
assert_failure
assert_output --partial "Expected command to succeed, but it failed."
}
@test "assert_failure should succeed if the executed command failed" {
git checkout -b feature
commit_with_assertion $'run exit 1\nassert_failure'
run git-check-assertions
assert_success
}
@test "assert_failure should fail if the executed command succeeded" {
git checkout -b feature
commit_with_assertion $'run exit 0\nassert_failure'
run git-check-assertions
assert_failure
assert_output --partial "Expected command to fail, but it succeeded."
}