From 3036d6d37e378d7010c89f740373ce517246983e Mon Sep 17 00:00:00 2001 From: Sven van Heugten Date: Tue, 3 Mar 2026 20:29:39 +0100 Subject: [PATCH] Introduce --partial on assert_output --- bin/git-check-assertions | 9 +++++++++ test/git-check-assertions.bats | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/bin/git-check-assertions b/bin/git-check-assertions index ea221fc..9e85abf 100755 --- a/bin/git-check-assertions +++ b/bin/git-check-assertions @@ -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" diff --git a/test/git-check-assertions.bats b/test/git-check-assertions.bats index a6a2bba..697d47d 100755 --- a/test/git-check-assertions.bats +++ b/test/git-check-assertions.bats @@ -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" +}