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
When sourcing a file into a shunit2 test, Bash's [[ is not recognized.
Consider the file above, called example.sh:
#!/usr/bin/env bash# example.shif [[ "$1"=="OK" ]]
thenecho Everything is OK
elseecho Something is not OK
fi
Now, let's call it from inside a shunit2 test script, called here test.sh:
#!/bin/bash# test.shtest_ok() {
./example.sh OK
}
test_not_ok() {
./example.sh NOK
}
This works:
$ shunit2 test.sh
test_ok
Everything is OK
test_not_ok
Something is not OK
Ran 2 tests.
OK
Now, if I source example.sh into test-sourced.sh, like this...
$ cat test.sh
#!/bin/bash# test-sourced.shtest_ok() {
source ./example.sh OK
}
test_not_ok() {
source ./example.sh NOK
}
...now the tests fail because source is not found.
$ shunit2 test-sourced.sh
test_ok
/home/adam/bin/shunit2: 4: eval: source: not found
shunit2:ERROR test_ok() returned non-zero return code.
test_not_ok
/home/adam/bin/shunit2: 7: eval: source: not found
shunit2:ERROR test_not_ok() returned non-zero return code.
Ran 2 tests.
FAILED (failures=2)
If I use . instead of source, as in the test-dot.sh file below
#!/bin/bashtest_ok() {
. ./example.sh OK
}
test_not_ok() {
. ./example.sh NOK
}
...it fails because [[ is "not found":
$ shunit2 ./test.sh
test_ok
/home/adam/bin/shunit2: 2: ./example.sh: [[: not found
Something is not OK
test_not_ok
/home/adam/bin/shunit2: 2: ./example.sh: [[: not found
Something is not OK
Ran 2 tests.
OK
I confess I don't understand why it is happening. I suppose it is a bug, but I'm not dead sure it is a mistake on my side. Do you see what is going on?
Thanks!
The text was updated successfully, but these errors were encountered:
When sourcing a file into a shunit2 test, Bash's
[[
is not recognized.Consider the file above, called
example.sh
:Now, let's call it from inside a shunit2 test script, called here
test.sh
:This works:
Now, if I source
example.sh
intotest-sourced.sh
, like this......now the tests fail because
source
is not found.If I use
.
instead ofsource
, as in thetest-dot.sh
file below...it fails because
[[
is "not found":I confess I don't understand why it is happening. I suppose it is a bug, but I'm not dead sure it is a mistake on my side. Do you see what is going on?
Thanks!
The text was updated successfully, but these errors were encountered: