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.
This commit is contained in:
Jose Diaz-Gonzalez
2026-05-08 18:51:02 -04:00
parent 47c8141148
commit 2cf2846c6b
2 changed files with 3 additions and 6 deletions

View File

@@ -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

View File

@@ -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"