Shellcheck part 1: bin scripts and non-example exercise files#784
Conversation
|
This PR touches files which potentially affect the outcome of the tests of an exercise. This will cause all students' solutions to affected exercises to be re-tested. If this PR does not affect the result of the test (or, for example, adds an edge case that is not worth rerunning all tests for), please add the following to the merge-commit message which will stops student's tests from re-running. Please copy-paste to avoid typos. For more information, refer to the documentation. If you are unsure whether to add the message or not, please ping |
| local list1=() | ||
| local list2=() |
There was a problem hiding this comment.
The test variables are now localized: shell check was complaining about result being used as a scalar after previously being an array.
| # 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. |
There was a problem hiding this comment.
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}"
...
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
We could add an ignore for these files. There's an ignore option in the workflow.
Ref: issue #783
This PR will satisfy
find exercises/practice bin \ \( -name '*.sh' -o -name '*.bash' \) \ -not \( -name example.sh -o -path exercises/practice/markdown/markdown.sh \) \ -print0 \ | xargs -0 shellcheckI'd recommend reviewing by commit: the last commit is just copying one bats-extra.bash file to all the rest of the exercises.