Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion exercises/practice/acronym/bats-extra.bash
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
# <http://creativecommons.org/publicdomain/zero/1.0/>.
#

# shellcheck disable=SC2120 # (warning): fail references arguments, but none are ever passed.
fail() {
# shellcheck disable=2015 # (info): Note that A && B || C is not if-then-else. C may run when A is true.
(( $# == 0 )) && batslib_err || batslib_err "$@"
return 1
}
Expand Down Expand Up @@ -119,7 +121,7 @@ batslib_print_kv_single_or_multi() {
else
local -i i
for (( i=1; i < ${#pairs[@]}; i+=2 )); do
pairs[$i]="$( batslib_prefix < <(printf '%s' "${pairs[$i]}") )"
pairs[i]="$( batslib_prefix < <(printf '%s' "${pairs[$i]}") )"
done
batslib_print_kv_multi "${pairs[@]}"
fi
Expand All @@ -136,6 +138,7 @@ batslib_prefix() {
batslib_mark() {
local -r symbol="$1"; shift
# Sort line numbers.
# shellcheck disable=SC2046 # (warning): Quote this to prevent word splitting.
set -- $( sort -nu <<< "$( printf '%d\n' "$@" )" )

local line
Expand Down Expand Up @@ -366,7 +369,9 @@ assert_output() {
| fail
fi
elif (( is_mode_regexp )); then
# shellcheck disable=SC2319 # (warning) `$?` in a conditional expression: https://github.com/koalaman/shellcheck/wiki/SC2319
if [[ '' =~ $expected ]] || (( $? == 2 )); then
# the regex matches an empty string or it is syntactically incorrect.
Comment on lines +372 to +374

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect matching the empty string is not intentional. We could allow an empty match and/or fail explicitly on an empty match.

[[ '' =~ $expected ]]
match=$?
msg=""
if (( match == 0 )); then
  msg="Regex matches an empty string"
elif (( match == 2 )); then
  msg="Invalid regex"
fi
if [[ -n $msg ]]; then
  echo "${msg}: ${expected@Q}"
  ...

@glennj glennj Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect matching the empty string is not intentional.

Betcha it is.

I don't really want to diverge the code we took from bats-core/bats-assert.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add an ignore for these files. There's an ignore option in the workflow.

echo "Invalid extended regular expression: \`$expected'" \
| batslib_decorate 'ERROR: assert_output' \
| fail
Expand Down
7 changes: 6 additions & 1 deletion exercises/practice/affine-cipher/bats-extra.bash
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
# <http://creativecommons.org/publicdomain/zero/1.0/>.
#

# shellcheck disable=SC2120 # (warning): fail references arguments, but none are ever passed.
fail() {
# shellcheck disable=2015 # (info): Note that A && B || C is not if-then-else. C may run when A is true.
(( $# == 0 )) && batslib_err || batslib_err "$@"
return 1
}
Expand Down Expand Up @@ -119,7 +121,7 @@ batslib_print_kv_single_or_multi() {
else
local -i i
for (( i=1; i < ${#pairs[@]}; i+=2 )); do
pairs[$i]="$( batslib_prefix < <(printf '%s' "${pairs[$i]}") )"
pairs[i]="$( batslib_prefix < <(printf '%s' "${pairs[$i]}") )"
done
batslib_print_kv_multi "${pairs[@]}"
fi
Expand All @@ -136,6 +138,7 @@ batslib_prefix() {
batslib_mark() {
local -r symbol="$1"; shift
# Sort line numbers.
# shellcheck disable=SC2046 # (warning): Quote this to prevent word splitting.
set -- $( sort -nu <<< "$( printf '%d\n' "$@" )" )

local line
Expand Down Expand Up @@ -366,7 +369,9 @@ assert_output() {
| fail
fi
elif (( is_mode_regexp )); then
# shellcheck disable=SC2319 # (warning) `$?` in a conditional expression: https://github.com/koalaman/shellcheck/wiki/SC2319
if [[ '' =~ $expected ]] || (( $? == 2 )); then
# the regex matches an empty string or it is syntactically incorrect.
echo "Invalid extended regular expression: \`$expected'" \
| batslib_decorate 'ERROR: assert_output' \
| fail
Expand Down
7 changes: 6 additions & 1 deletion exercises/practice/all-your-base/bats-extra.bash
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
# <http://creativecommons.org/publicdomain/zero/1.0/>.
#

# shellcheck disable=SC2120 # (warning): fail references arguments, but none are ever passed.
fail() {
# shellcheck disable=2015 # (info): Note that A && B || C is not if-then-else. C may run when A is true.
(( $# == 0 )) && batslib_err || batslib_err "$@"
return 1
}
Expand Down Expand Up @@ -119,7 +121,7 @@ batslib_print_kv_single_or_multi() {
else
local -i i
for (( i=1; i < ${#pairs[@]}; i+=2 )); do
pairs[$i]="$( batslib_prefix < <(printf '%s' "${pairs[$i]}") )"
pairs[i]="$( batslib_prefix < <(printf '%s' "${pairs[$i]}") )"
done
batslib_print_kv_multi "${pairs[@]}"
fi
Expand All @@ -136,6 +138,7 @@ batslib_prefix() {
batslib_mark() {
local -r symbol="$1"; shift
# Sort line numbers.
# shellcheck disable=SC2046 # (warning): Quote this to prevent word splitting.
set -- $( sort -nu <<< "$( printf '%d\n' "$@" )" )

local line
Expand Down Expand Up @@ -366,7 +369,9 @@ assert_output() {
| fail
fi
elif (( is_mode_regexp )); then
# shellcheck disable=SC2319 # (warning) `$?` in a conditional expression: https://github.com/koalaman/shellcheck/wiki/SC2319
if [[ '' =~ $expected ]] || (( $? == 2 )); then
# the regex matches an empty string or it is syntactically incorrect.
echo "Invalid extended regular expression: \`$expected'" \
| batslib_decorate 'ERROR: assert_output' \
| fail
Expand Down
7 changes: 6 additions & 1 deletion exercises/practice/allergies/bats-extra.bash
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
# <http://creativecommons.org/publicdomain/zero/1.0/>.
#

# shellcheck disable=SC2120 # (warning): fail references arguments, but none are ever passed.
fail() {
# shellcheck disable=2015 # (info): Note that A && B || C is not if-then-else. C may run when A is true.
(( $# == 0 )) && batslib_err || batslib_err "$@"
return 1
}
Expand Down Expand Up @@ -119,7 +121,7 @@ batslib_print_kv_single_or_multi() {
else
local -i i
for (( i=1; i < ${#pairs[@]}; i+=2 )); do
pairs[$i]="$( batslib_prefix < <(printf '%s' "${pairs[$i]}") )"
pairs[i]="$( batslib_prefix < <(printf '%s' "${pairs[$i]}") )"
done
batslib_print_kv_multi "${pairs[@]}"
fi
Expand All @@ -136,6 +138,7 @@ batslib_prefix() {
batslib_mark() {
local -r symbol="$1"; shift
# Sort line numbers.
# shellcheck disable=SC2046 # (warning): Quote this to prevent word splitting.
set -- $( sort -nu <<< "$( printf '%d\n' "$@" )" )

local line
Expand Down Expand Up @@ -366,7 +369,9 @@ assert_output() {
| fail
fi
elif (( is_mode_regexp )); then
# shellcheck disable=SC2319 # (warning) `$?` in a conditional expression: https://github.com/koalaman/shellcheck/wiki/SC2319
if [[ '' =~ $expected ]] || (( $? == 2 )); then
# the regex matches an empty string or it is syntactically incorrect.
echo "Invalid extended regular expression: \`$expected'" \
| batslib_decorate 'ERROR: assert_output' \
| fail
Expand Down
7 changes: 6 additions & 1 deletion exercises/practice/anagram/bats-extra.bash
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
# <http://creativecommons.org/publicdomain/zero/1.0/>.
#

# shellcheck disable=SC2120 # (warning): fail references arguments, but none are ever passed.
fail() {
# shellcheck disable=2015 # (info): Note that A && B || C is not if-then-else. C may run when A is true.
(( $# == 0 )) && batslib_err || batslib_err "$@"
return 1
}
Expand Down Expand Up @@ -119,7 +121,7 @@ batslib_print_kv_single_or_multi() {
else
local -i i
for (( i=1; i < ${#pairs[@]}; i+=2 )); do
pairs[$i]="$( batslib_prefix < <(printf '%s' "${pairs[$i]}") )"
pairs[i]="$( batslib_prefix < <(printf '%s' "${pairs[$i]}") )"
done
batslib_print_kv_multi "${pairs[@]}"
fi
Expand All @@ -136,6 +138,7 @@ batslib_prefix() {
batslib_mark() {
local -r symbol="$1"; shift
# Sort line numbers.
# shellcheck disable=SC2046 # (warning): Quote this to prevent word splitting.
set -- $( sort -nu <<< "$( printf '%d\n' "$@" )" )

local line
Expand Down Expand Up @@ -366,7 +369,9 @@ assert_output() {
| fail
fi
elif (( is_mode_regexp )); then
# shellcheck disable=SC2319 # (warning) `$?` in a conditional expression: https://github.com/koalaman/shellcheck/wiki/SC2319
if [[ '' =~ $expected ]] || (( $? == 2 )); then
# the regex matches an empty string or it is syntactically incorrect.
echo "Invalid extended regular expression: \`$expected'" \
| batslib_decorate 'ERROR: assert_output' \
| fail
Expand Down
7 changes: 6 additions & 1 deletion exercises/practice/armstrong-numbers/bats-extra.bash
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
# <http://creativecommons.org/publicdomain/zero/1.0/>.
#

# shellcheck disable=SC2120 # (warning): fail references arguments, but none are ever passed.
fail() {
# shellcheck disable=2015 # (info): Note that A && B || C is not if-then-else. C may run when A is true.
(( $# == 0 )) && batslib_err || batslib_err "$@"
return 1
}
Expand Down Expand Up @@ -119,7 +121,7 @@ batslib_print_kv_single_or_multi() {
else
local -i i
for (( i=1; i < ${#pairs[@]}; i+=2 )); do
pairs[$i]="$( batslib_prefix < <(printf '%s' "${pairs[$i]}") )"
pairs[i]="$( batslib_prefix < <(printf '%s' "${pairs[$i]}") )"
done
batslib_print_kv_multi "${pairs[@]}"
fi
Expand All @@ -136,6 +138,7 @@ batslib_prefix() {
batslib_mark() {
local -r symbol="$1"; shift
# Sort line numbers.
# shellcheck disable=SC2046 # (warning): Quote this to prevent word splitting.
set -- $( sort -nu <<< "$( printf '%d\n' "$@" )" )

local line
Expand Down Expand Up @@ -366,7 +369,9 @@ assert_output() {
| fail
fi
elif (( is_mode_regexp )); then
# shellcheck disable=SC2319 # (warning) `$?` in a conditional expression: https://github.com/koalaman/shellcheck/wiki/SC2319
if [[ '' =~ $expected ]] || (( $? == 2 )); then
# the regex matches an empty string or it is syntactically incorrect.
echo "Invalid extended regular expression: \`$expected'" \
| batslib_decorate 'ERROR: assert_output' \
| fail
Expand Down
7 changes: 6 additions & 1 deletion exercises/practice/atbash-cipher/bats-extra.bash
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
# <http://creativecommons.org/publicdomain/zero/1.0/>.
#

# shellcheck disable=SC2120 # (warning): fail references arguments, but none are ever passed.
fail() {
# shellcheck disable=2015 # (info): Note that A && B || C is not if-then-else. C may run when A is true.
(( $# == 0 )) && batslib_err || batslib_err "$@"
return 1
}
Expand Down Expand Up @@ -119,7 +121,7 @@ batslib_print_kv_single_or_multi() {
else
local -i i
for (( i=1; i < ${#pairs[@]}; i+=2 )); do
pairs[$i]="$( batslib_prefix < <(printf '%s' "${pairs[$i]}") )"
pairs[i]="$( batslib_prefix < <(printf '%s' "${pairs[$i]}") )"
done
batslib_print_kv_multi "${pairs[@]}"
fi
Expand All @@ -136,6 +138,7 @@ batslib_prefix() {
batslib_mark() {
local -r symbol="$1"; shift
# Sort line numbers.
# shellcheck disable=SC2046 # (warning): Quote this to prevent word splitting.
set -- $( sort -nu <<< "$( printf '%d\n' "$@" )" )

local line
Expand Down Expand Up @@ -366,7 +369,9 @@ assert_output() {
| fail
fi
elif (( is_mode_regexp )); then
# shellcheck disable=SC2319 # (warning) `$?` in a conditional expression: https://github.com/koalaman/shellcheck/wiki/SC2319
if [[ '' =~ $expected ]] || (( $? == 2 )); then
# the regex matches an empty string or it is syntactically incorrect.
echo "Invalid extended regular expression: \`$expected'" \
| batslib_decorate 'ERROR: assert_output' \
| fail
Expand Down
7 changes: 6 additions & 1 deletion exercises/practice/beer-song/bats-extra.bash
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
# <http://creativecommons.org/publicdomain/zero/1.0/>.
#

# shellcheck disable=SC2120 # (warning): fail references arguments, but none are ever passed.
fail() {
# shellcheck disable=2015 # (info): Note that A && B || C is not if-then-else. C may run when A is true.
(( $# == 0 )) && batslib_err || batslib_err "$@"
return 1
}
Expand Down Expand Up @@ -119,7 +121,7 @@ batslib_print_kv_single_or_multi() {
else
local -i i
for (( i=1; i < ${#pairs[@]}; i+=2 )); do
pairs[$i]="$( batslib_prefix < <(printf '%s' "${pairs[$i]}") )"
pairs[i]="$( batslib_prefix < <(printf '%s' "${pairs[$i]}") )"
done
batslib_print_kv_multi "${pairs[@]}"
fi
Expand All @@ -136,6 +138,7 @@ batslib_prefix() {
batslib_mark() {
local -r symbol="$1"; shift
# Sort line numbers.
# shellcheck disable=SC2046 # (warning): Quote this to prevent word splitting.
set -- $( sort -nu <<< "$( printf '%d\n' "$@" )" )

local line
Expand Down Expand Up @@ -366,7 +369,9 @@ assert_output() {
| fail
fi
elif (( is_mode_regexp )); then
# shellcheck disable=SC2319 # (warning) `$?` in a conditional expression: https://github.com/koalaman/shellcheck/wiki/SC2319
if [[ '' =~ $expected ]] || (( $? == 2 )); then
# the regex matches an empty string or it is syntactically incorrect.
echo "Invalid extended regular expression: \`$expected'" \
| batslib_decorate 'ERROR: assert_output' \
| fail
Expand Down
7 changes: 6 additions & 1 deletion exercises/practice/binary-search/bats-extra.bash
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
# <http://creativecommons.org/publicdomain/zero/1.0/>.
#

# shellcheck disable=SC2120 # (warning): fail references arguments, but none are ever passed.
fail() {
# shellcheck disable=2015 # (info): Note that A && B || C is not if-then-else. C may run when A is true.
(( $# == 0 )) && batslib_err || batslib_err "$@"
return 1
}
Expand Down Expand Up @@ -119,7 +121,7 @@ batslib_print_kv_single_or_multi() {
else
local -i i
for (( i=1; i < ${#pairs[@]}; i+=2 )); do
pairs[$i]="$( batslib_prefix < <(printf '%s' "${pairs[$i]}") )"
pairs[i]="$( batslib_prefix < <(printf '%s' "${pairs[$i]}") )"
done
batslib_print_kv_multi "${pairs[@]}"
fi
Expand All @@ -136,6 +138,7 @@ batslib_prefix() {
batslib_mark() {
local -r symbol="$1"; shift
# Sort line numbers.
# shellcheck disable=SC2046 # (warning): Quote this to prevent word splitting.
set -- $( sort -nu <<< "$( printf '%d\n' "$@" )" )

local line
Expand Down Expand Up @@ -366,7 +369,9 @@ assert_output() {
| fail
fi
elif (( is_mode_regexp )); then
# shellcheck disable=SC2319 # (warning) `$?` in a conditional expression: https://github.com/koalaman/shellcheck/wiki/SC2319
if [[ '' =~ $expected ]] || (( $? == 2 )); then
# the regex matches an empty string or it is syntactically incorrect.
echo "Invalid extended regular expression: \`$expected'" \
| batslib_decorate 'ERROR: assert_output' \
| fail
Expand Down
7 changes: 6 additions & 1 deletion exercises/practice/bob/bats-extra.bash
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
# <http://creativecommons.org/publicdomain/zero/1.0/>.
#

# shellcheck disable=SC2120 # (warning): fail references arguments, but none are ever passed.
fail() {
# shellcheck disable=2015 # (info): Note that A && B || C is not if-then-else. C may run when A is true.
(( $# == 0 )) && batslib_err || batslib_err "$@"
return 1
}
Expand Down Expand Up @@ -119,7 +121,7 @@ batslib_print_kv_single_or_multi() {
else
local -i i
for (( i=1; i < ${#pairs[@]}; i+=2 )); do
pairs[$i]="$( batslib_prefix < <(printf '%s' "${pairs[$i]}") )"
pairs[i]="$( batslib_prefix < <(printf '%s' "${pairs[$i]}") )"
done
batslib_print_kv_multi "${pairs[@]}"
fi
Expand All @@ -136,6 +138,7 @@ batslib_prefix() {
batslib_mark() {
local -r symbol="$1"; shift
# Sort line numbers.
# shellcheck disable=SC2046 # (warning): Quote this to prevent word splitting.
set -- $( sort -nu <<< "$( printf '%d\n' "$@" )" )

local line
Expand Down Expand Up @@ -366,7 +369,9 @@ assert_output() {
| fail
fi
elif (( is_mode_regexp )); then
# shellcheck disable=SC2319 # (warning) `$?` in a conditional expression: https://github.com/koalaman/shellcheck/wiki/SC2319
if [[ '' =~ $expected ]] || (( $? == 2 )); then
# the regex matches an empty string or it is syntactically incorrect.
echo "Invalid extended regular expression: \`$expected'" \
| batslib_decorate 'ERROR: assert_output' \
| fail
Expand Down
Loading