From 2cf2846c6b2c9b39cbb059484d207d5c0a92d6c8 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 8 May 2026 18:51:02 -0400 Subject: [PATCH] test: count assert_output_contains matches as fixed strings Replace the bash pattern-substitution loop with grep -F -o piped to wc -l so the helper counts literal substring occurrences instead of treating the expected value as a glob pattern. The old implementation interpreted `[`, `]`, `*`, `?`, and `\` as pattern syntax, which made `assert_output_contains "['task.py', 'test']"` report 17 matches against an output that contained the string exactly once - the inner characters were being matched as a character class. assert_output_not_contains delegates to assert_output_contains and is fixed transitively. --- tests/unit/test_helper.bash | 7 ++----- tests/unit/traefik.bats | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/unit/test_helper.bash b/tests/unit/test_helper.bash index 60ba322e9..08fbd4a63 100644 --- a/tests/unit/test_helper.bash +++ b/tests/unit/test_helper.bash @@ -143,11 +143,8 @@ assert_output_contains() { local input="$output" local expected="$1" local count="${2:-1}" - local found=0 - until [ "${input/$expected/}" = "$input" ]; do - input="${input/$expected/}" - found=$((found + 1)) - done + local found + found=$(printf '%s' "$input" | grep -F -o -- "$expected" | wc -l | tr -d ' ') if [[ "$count" -eq -1 ]]; then if [[ "$found" -gt 0 ]]; then diff --git a/tests/unit/traefik.bats b/tests/unit/traefik.bats index f07f2a6f6..9c808d89e 100644 --- a/tests/unit/traefik.bats +++ b/tests/unit/traefik.bats @@ -468,7 +468,7 @@ teardown() { assert_success assert_output_contains "dns provider cf_api_email" assert_output_contains "dns provider cf_api_key" - assert_output_contains "*******" + assert_output_contains "*******" 2 assert_output_not_contains "test@example.com" assert_output_not_contains "secret-key"