A collection of helper functions for shell-script testing
. ./test-helper.sh
. ./test-helper.sh
mock_path /home/jf/shell/test/bin
echo $PATH
Result: /home/jf/shell/test/bin:/bin:/sbin/...
. ./test-helper.sh
PARENT_MOCK_PATH=/tests/bin
mock_path for-script1:for-script2:for-script3
echo $PATH
Result: /tests/bin/for-script1:/tests/bin/for-script2:/tests/bin/for-script3:/bin:/sbin/.....
The function source_exec
includes a file until a separator string
appears. By default the separator is:
## This SEPARATOR is required for test purposes. Please don’t remove! ##
cat executable_script.sh
:
#! /bin/sh
_echo_lol() {
echo lol
}
## This SEPARATOR is required for test purposes. Please don’t remove! ##
echo "If you see this text, then the function didn’t work"
In your test environment:
. ./test-helper.sh
source_exec executable_script.sh
test_lol() {
assert _echo_lol ....
}
Use the environment variable SOURCE_EXEC_SEPARATOR
to set your own
separator string.
Useful to rename builtin command.
patch <file> <sed-statements>
patch test-helper.sh 's/local /superlocal /g'
or multiple sed
statements
patch test-helper.sh -e 's/local /superlocal /g' -e 's/for /superfor /g'