#shunit2 — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #shunit2, aggregated by home.social.
-
What is the defacto way to locate where shunit2 is installed? The Debian and Arch package installs it into /usr/bin/, where as other distro packages install it into /usr/share/shunit2/. How many people vendor shunit2 directly into their test suite?
-
I figured out how to "stub" specific commands in shell script tests, but it's not pretty.
# stub the "command" command as a function
function command() {
if [[ "$1" == "-v" ]] && [[ "$2" == "java" ]]; then
# stub that java is not installed
return 1
else
/usr/bin/command $*
fi
}# and to remove the stub
unset command -
I wish there was a good way to stub/mock in shunit2 tests the existence or non-existence of a command. Say I have a bash function that checks `command -v someprog`. Stubbing the command's existence would require adding a fake bin directory to $PATH containing a dummy executable file `someprog`. However, how do you stub when a command *is not* installed on the system even when it is?
-
It looks like the shell scripts for our container infrastructure have become sufficiently complex that they would benefit from having #unit #tests.
So I started looking around for a unit test framework for #bash (well plain #bourne #shell actually) and came across #shunit2 by Kate Ward.
It seems like a nice library. https://github.com/kward/shunit2