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:
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user