Skip to content

Commit a392cf6

Browse files
fix: too brittle invalid regex tests under bash 5.3
The exact error details depend on the system
1 parent 1ba47b9 commit a392cf6

10 files changed

+36
-20
lines changed

test/assert_line.bats

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,17 @@ ERR_MSG
337337
run assert_line --regexp '[.*'
338338

339339
if (( BASH_VERSINFO[0] > 5 || (BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] >=3) )); then
340-
assert_test_fail <<'ERR_MSG'
340+
[[ "$output" =~ "invalid regular expression "([^$'\n']+) ]]
341+
cat <<ERR_MSG
342+
343+
-- ERROR: assert_line --
344+
invalid regular expression ${BASH_REMATCH[1]}
345+
--
346+
ERR_MSG
347+
assert_test_fail <<ERR_MSG
341348
342349
-- ERROR: assert_line --
343-
invalid regular expression `[.*': Missing ']'
350+
invalid regular expression ${BASH_REMATCH[1]}
344351
--
345352
ERR_MSG
346353
else

test/assert_output.bats

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,11 @@ ERR_MSG
255255
run assert_output --regexp '[.*'
256256

257257
if (( BASH_VERSINFO[0] > 5 || (BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] >=3) )); then
258-
assert_test_fail <<'ERR_MSG'
258+
[[ "$output" =~ "invalid regular expression "([^$'\n']+) ]]
259+
assert_test_fail <<ERR_MSG
259260
260261
-- ERROR: assert_output --
261-
invalid regular expression `[.*': Missing ']'
262+
invalid regular expression ${BASH_REMATCH[1]}
262263
--
263264
ERR_MSG
264265
else

test/assert_regex.bats

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,11 @@ ERR_MSG
7474
run assert_regex value '[.*'
7575

7676
if (( BASH_VERSINFO[0] > 5 || (BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] >=3) )); then
77-
assert_test_fail <<'ERR_MSG'
77+
[[ "$output" =~ "invalid regular expression "([^$'\n']+) ]]
78+
assert_test_fail <<ERR_MSG
7879
7980
-- ERROR: assert_regex --
80-
invalid regular expression `[.*': Missing ']'
81+
invalid regular expression ${BASH_REMATCH[1]}
8182
--
8283
ERR_MSG
8384
else

test/assert_stderr.bats

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,11 @@ ERR_MSG
268268
run assert_stderr --regexp '[.*'
269269

270270
if (( BASH_VERSINFO[0] > 5 || (BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] >=3) )); then
271-
assert_test_fail <<'ERR_MSG'
271+
[[ "$output" =~ "invalid regular expression "([^$'\n']+) ]]
272+
assert_test_fail <<ERR_MSG
272273
273274
-- ERROR: assert_stderr --
274-
invalid regular expression `[.*': Missing ']'
275+
invalid regular expression ${BASH_REMATCH[1]}
275276
--
276277
ERR_MSG
277278
else

test/assert_stderr_line.bats

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,11 @@ ERR_MSG
350350
run assert_stderr_line --regexp '[.*'
351351

352352
if (( BASH_VERSINFO[0] > 5 || (BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] >=3) )); then
353-
assert_test_fail <<'ERR_MSG'
353+
[[ "$output" =~ "invalid regular expression "([^$'\n']+) ]]
354+
assert_test_fail <<ERR_MSG
354355
355356
-- ERROR: assert_stderr_line --
356-
invalid regular expression `[.*': Missing ']'
357+
invalid regular expression ${BASH_REMATCH[1]}
357358
--
358359
ERR_MSG
359360
else

test/refute_line.bats

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,11 @@ ERR_MSG
330330
run refute_line --regexp '[.*'
331331

332332
if (( BASH_VERSINFO[0] > 5 || (BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] >=3) )); then
333-
assert_test_fail <<'ERR_MSG'
333+
[[ "$output" =~ "invalid regular expression "([^$'\n']+) ]]
334+
assert_test_fail <<ERR_MSG
334335
335336
-- ERROR: refute_line --
336-
invalid regular expression `[.*': Missing ']'
337+
invalid regular expression ${BASH_REMATCH[1]}
337338
--
338339
ERR_MSG
339340
else

test/refute_output.bats

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,11 @@ ERR_MSG
199199
@test 'refute_output() --regexp <regexp>: returns 1 and displays an error message if <regexp> is not a valid extended regular expression' {
200200
run refute_output --regexp '[.*'
201201
if (( BASH_VERSINFO[0] > 5 || (BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] >=3) )); then
202-
assert_test_fail <<'ERR_MSG'
202+
[[ "$output" =~ "invalid regular expression "([^$'\n']+) ]]
203+
assert_test_fail <<ERR_MSG
203204
204205
-- ERROR: refute_output --
205-
invalid regular expression `[.*': Missing ']'
206+
invalid regular expression ${BASH_REMATCH[1]}
206207
--
207208
ERR_MSG
208209
else

test/refute_regex.bats

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,11 @@ ERR_MSG
9090
run refute_regex value '[.*'
9191

9292
if (( BASH_VERSINFO[0] > 5 || (BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] >=3) )); then
93-
assert_test_fail <<'ERR_MSG'
93+
[[ "$output" =~ "invalid regular expression "([^$'\n']+) ]]
94+
assert_test_fail <<ERR_MSG
9495
9596
-- ERROR: refute_regex --
96-
invalid regular expression `[.*': Missing ']'
97+
invalid regular expression ${BASH_REMATCH[1]}
9798
--
9899
ERR_MSG
99100
else

test/refute_stderr.bats

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,11 @@ ERR_MSG
212212
run refute_stderr --regexp '[.*'
213213

214214
if (( BASH_VERSINFO[0] > 5 || (BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] >=3) )); then
215-
assert_test_fail <<'ERR_MSG'
215+
[[ "$output" =~ "invalid regular expression "([^$'\n']+) ]]
216+
assert_test_fail <<ERR_MSG
216217
217218
-- ERROR: refute_stderr --
218-
invalid regular expression `[.*': Missing ']'
219+
invalid regular expression ${BASH_REMATCH[1]}
219220
--
220221
ERR_MSG
221222
else

test/refute_stderr_line.bats

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,11 @@ ERR_MSG
342342
run refute_stderr_line --regexp '[.*'
343343

344344
if (( BASH_VERSINFO[0] > 5 || (BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] >=3) )); then
345-
assert_test_fail <<"ERR_MSG"
345+
[[ "$output" =~ "invalid regular expression "([^$'\n']+) ]]
346+
assert_test_fail <<ERR_MSG
346347
347348
-- ERROR: refute_stderr_line --
348-
invalid regular expression `[.*': Missing ']'
349+
invalid regular expression ${BASH_REMATCH[1]}
349350
--
350351
ERR_MSG
351352
else

0 commit comments

Comments
 (0)