You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have script that I source in order to provide common/library env vars & functions and am struggling to test that the expected env vars & function(s) exist as a result of the inclusion. MWE - assuming an included file of t.sh...
export -A SOME_VAR
some-func() {
:
}
... and t_spec.sh containing...
It "GP: includes successfully with correct defaults"
preserve() { %preserve SOME_VAR ; }
AfterRun preserve
When run source src/main/${FNNAME//./\/}.sh
The status should be success
The stdout should equal ''
The stderr should equal ''
The variable SOME_VAR should exist
The function some-func should exist
End
My problem is that neither of the assertions pass since the assertions consider that the subjects i.e. SOME_VAR & some-func, are undefined - as follows...
$ shellspec t_spec.sh
Running: /bin/bash [bash 5.0.17(1)-release]
F
Examples:
1) GP: includes successfully with correct defaults
When run source t.sh
1.1) The variable SOME_VAR should exist
expected <unset> to exist
# t_spec.sh:9
1.2) The function some-func should exist
expected "some-func" to exist
# t_spec.sh:10
Finished in 0.09 seconds (user 0.09 seconds, sys 0.00 seconds)
1 example, 1 failure
Failure examples / Errors: (Listed here affect your suite's status)
shellspec t_spec.sh:1 # 1) GP: includes successfully with correct defaults FAILED
But, informally, I know that the script works perfectly well when run "in anger".
BTW, I use run source since I want to ensure that the inclusion doesn't blow up the whole test run.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hey all,
I have script that I source in order to provide common/library env vars & functions and am struggling to test that the expected env vars & function(s) exist as a result of the inclusion. MWE - assuming an included file of
t.sh
...... and
t_spec.sh
containing...My problem is that neither of the assertions pass since the assertions consider that the subjects i.e.
SOME_VAR
&some-func
, are undefined - as follows...But, informally, I know that the script works perfectly well when run "in anger".
BTW, I use
run source
since I want to ensure that the inclusion doesn't blow up the whole test run.Any & all help very greatly appreciated
Beta Was this translation helpful? Give feedback.
All reactions