Introduce --partial on assert_output

This commit is contained in:
Sven van Heugten 2026-03-03 20:29:39 +01:00
parent 475b0c6fa1
commit 3036d6d37e
No known key found for this signature in database
GPG key ID: D612F88666F4F660
2 changed files with 29 additions and 0 deletions

View file

@ -53,6 +53,15 @@ assert_failure() {
fi
}
assert_output() {
if [ "${1:-}" = "--partial" ]; then
local expected="$2"
if [[ "$output" != *"$expected"* ]]; then
echo "Expected output to contain: $expected"
echo "Actual output: $output"
exit 1
fi
return 0
fi
if [ "$output" != "$1" ]; then
echo "Expected output to equal: $1"
echo "Actual output: $output"

View file

@ -179,3 +179,23 @@ commit_with_assertion() {
assert_success
}
@test "assert_output --partial should succeed if output contains the given string" {
git checkout -b feature
commit_with_assertion $'run echo hello\nassert_output --partial ell'
run git-check-assertions
assert_success
}
@test "assert_output --partial should fail if output does not contain the given string" {
git checkout -b feature
commit_with_assertion $'run echo hello\nassert_output --partial xyz'
run git-check-assertions
assert_failure
assert_output --partial "Expected output to contain: xyz"
assert_output --partial "Actual output: hello"
}