Introduce assert_failure
This commit is contained in:
parent
1a10b24b06
commit
f9d6696687
2 changed files with 26 additions and 1 deletions
|
|
@ -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)"
|
||||
|
|
|
|||
|
|
@ -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."
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue