Added shunit helper script and updated README
This commit is contained in:
3
Makefile
3
Makefile
@@ -4,6 +4,7 @@ all:
|
|||||||
install:
|
install:
|
||||||
install lib/junit.sh /usr/lib/junit.sh
|
install lib/junit.sh /usr/lib/junit.sh
|
||||||
install lib/tunit.sh /usr/lib/tunit.sh
|
install lib/tunit.sh /usr/lib/tunit.sh
|
||||||
|
install shunit /usr/bin/shunit
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
rm /usr/lib/[tj]unit.sh
|
rm /usr/lib/[tj]unit.sh /usr/bin/shunit
|
||||||
|
|||||||
19
README.md
19
README.md
@@ -1,4 +1,21 @@
|
|||||||
shunit
|
The shunit script
|
||||||
|
======
|
||||||
|
|
||||||
|
shunit is a bash script for running tests scripts that are written with the shunit library. To use it, fir install it:
|
||||||
|
|
||||||
|
make install
|
||||||
|
|
||||||
|
... then run it with the name of a single bash test script or a whole directory of scripts:
|
||||||
|
|
||||||
|
shunit -t test_script.sh
|
||||||
|
shunit -t test_directory/
|
||||||
|
|
||||||
|
... The default output format is junit. You can select tunit with the '-f' flag:
|
||||||
|
|
||||||
|
shunit -t test_script.sh -f tunit
|
||||||
|
|
||||||
|
|
||||||
|
The shunit library
|
||||||
======
|
======
|
||||||
|
|
||||||
shunit is just a set of bash functions for producing unit test output from bash scripts. I wrote this library because I often found myself writing things in bash whose output I wanted to consume as discrete pass/fail tasks into Bamboo, so I wrote the junit functions. Then later on, I got sick and tired of (as a human) reading junit output, so I wrote the tunit functions, so my scripts could output tunit or junit depending on which flags I passed.
|
shunit is just a set of bash functions for producing unit test output from bash scripts. I wrote this library because I often found myself writing things in bash whose output I wanted to consume as discrete pass/fail tasks into Bamboo, so I wrote the junit functions. Then later on, I got sick and tired of (as a human) reading junit output, so I wrote the tunit functions, so my scripts could output tunit or junit depending on which flags I passed.
|
||||||
|
|||||||
49
shunit
Normal file
49
shunit
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
source /usr/lib/cmdarg.sh
|
||||||
|
|
||||||
|
cmdarg_info author "Andrew Kesterson <andrew@aklabs.net>"
|
||||||
|
cmdarg_info header "A bash script for unit testing other bash scripts in JUNIT or human-friendly formats"
|
||||||
|
cmdarg_info copyright "(MIT License)"
|
||||||
|
cmdarg 'f:' 'format' 'Format to print results in. Valid options are: [junit, tunit]' 'junit' 'echo ${OPTARG} | grep -E "^junit$|^tunit$" >/dev/null 2>&1'
|
||||||
|
cmdarg 't:' 'tests' 'Directory or single file to test.'
|
||||||
|
|
||||||
|
cmdarg_parse "$@"
|
||||||
|
|
||||||
|
FORMATTER=${cmdarg_cfg['format']}
|
||||||
|
|
||||||
|
set -e
|
||||||
|
source /usr/lib/${FORMATTER}.sh
|
||||||
|
set +e
|
||||||
|
|
||||||
|
${FORMATTER}_header
|
||||||
|
|
||||||
|
if [[ -d ${cmdarg_cfg[tests]} ]]; then
|
||||||
|
FILES=${cmdarg_cfg[tests]}/*sh
|
||||||
|
elif [[ -e ${cmdarg_cfg[tests]} ]]; then
|
||||||
|
FILES=${cmdarg_cfg[tests]}
|
||||||
|
fi
|
||||||
|
|
||||||
|
for file in $FILES;
|
||||||
|
do
|
||||||
|
declare -A tests
|
||||||
|
source $file
|
||||||
|
for key in $(declare -F | grep 'test_')
|
||||||
|
do
|
||||||
|
if [[ "$(type -t $key)" == "function" ]]; then
|
||||||
|
start=$(date "+%s")
|
||||||
|
ERR=$($key 2>&1)
|
||||||
|
ERRFLAG=$?
|
||||||
|
delta=$(($(date "+%s") - $start))
|
||||||
|
if [[ $ERRFLAG -eq 0 ]]; then
|
||||||
|
${FORMATTER}_testcase "$file" "$key" "$delta"
|
||||||
|
else
|
||||||
|
SHORTERR=$(echo "$ERR" | head -n 1)
|
||||||
|
${FORMATTER}_testcase "$file" "$key" "$delta" "Exit ${ERRFLAG}" "$SHORTERR" "${ERR}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
unset tests
|
||||||
|
done
|
||||||
|
|
||||||
|
${FORMATTER}_footer
|
||||||
Reference in New Issue
Block a user