Closed
Description
I use Bash strict mode in my script and unit tests. When an unset parameter is expanded in my tested script (due to a bug), this cause an error in Shellspec core.
I added an example in the Shellspec specification to bring out this bug:
Context "When using Bash strict mode"
Skip if "not on Bash" test "${BASH:-}"x = x
set -o nounset
fDescribe "Shellspec"
It "runs an example which expands an unset parameter"
expand_unset() {
: "${UNSET_PARAMETER}"
}
When call expand_unset
The status should be failure
End
End
End
The expected result would be:
$ shellspec --focus
Running: /bin/sh [bash 5.0.11(1)-release]
F
Examples:
1) When using Bash strict mode Shellspec runs an example which expands an unset parameter
1.1) Example aborted (exit status: 1)
stderr:main: line 93: UNSET_PARAMETER: unbound variable
# spec/bugs_spec.sh:4
Finished in ? seconds (user ? seconds, sys ? seconds)
1 example, 1 failure
Failure examples: (Listed here affect your suite's status)
shellspec spec/bugs_spec.sh:30 # 1) When using Bash strict mode Shellspec runs an example which expands an unset parameter FAILED
But it is:
$ shellspec --focus
Running: /bin/sh [bash 5.0.11(1)-release]
/usr/lib/shellspec/lib/core/outputs.sh: line 176: LF: unbound variable
Unexpected output to the stderr at line 29-37 in 'spec/bugs_spec.sh'
Finished in ? seconds (user ? seconds, sys ? seconds)
0 examples, 0 failures, aborted by an unexpected error
An unexpected error occurred or output to the stderr. [0] [1] [102]
Fatal error occurred, terminated with exit status 1.
And with debug output:
But using the current Shellspec specification does not bring up the bug, because the LF
parameter is defined in the specification helper:
Line 66 in c298391
Because this parameter is not defined in my specification helper, it causes the error.