easyrsa/op-test.sh
Richard T Bonhomme 7d1b00813c
Final improvements to vars_setup()
New standards introduced:
* Use '-e' to test for existence not '-f' file.
* Only use '-z' not '-n', more visually distinct.

Minor code improvement: Use 'if command' to test for success.

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
2022-04-06 19:42:34 +01:00

78 lines
1.8 KiB
Bash

#!/bin/sh
#
# Downloads the run_unit_tests.sh file from easyrsa-unit-tests repo
# and executes that - allows for disconnected testing from the easy-rsa
# repo with TravisCI.
verb='-v'
enable_shellcheck=1
while [ -n "$1" ]; do
case "$1" in
-v) verb='-v' ;;
-vv) verb='-vv' ;;
-scoff) unset -v enable_shellcheck ;;
*) verb='-v'
esac
shift
done
github_url='https://raw.githubusercontent.com'
if [ "$enable_shellcheck" ]; then
if [ -e "shellcheck" ] && [ "$EASYRSA_NIX" ]; then
chmod +x shellcheck
./shellcheck -V
if [ -e easyrsa3/easyrsa ]; then
./shellcheck -s sh -S warning -x easyrsa3/easyrsa
echo "* shellcheck completed *"
else
echo "* easyrsa binary not present, using path, no shellcheck"
fi
elif [ "$EASYRSA_NIX" ]; then
github_target='OpenVPN/easyrsa-unit-tests/master/shellcheck'
curl -O "${github_url}/${github_target}"
[ -e "shellcheck" ] || { echo "shellcheck download failed."; exit 9; }
chmod +x shellcheck
./shellcheck -V
if [ -e easyrsa3/easyrsa ]; then
./shellcheck -s sh -S warning -x easyrsa3/easyrsa
echo "* shellcheck completed *"
else
echo "* easyrsa binary not present, using path, no shellcheck"
fi
rm -f ./shellcheck
fi
else
# shellcheck is disabled
:
fi
estat=0
if [ -e "easyrsa-unit-tests.sh" ]; then
if sh easyrsa-unit-tests.sh "$verb"; then
if [ "$EASYRSA_NIX" ] && [ "$EASYRSA_BY_TINCANTECH" ]; then
sh easyrsa-unit-tests.sh "$verb" -x || estat=2
fi
else
estat=1
fi
else
github_target='OpenVPN/easyrsa-unit-tests/master/easyrsa-unit-tests.sh'
curl -O "${github_url}/${github_target}"
[ -e "easyrsa-unit-tests.sh" ] || { echo "Unit-test download failed."; exit 9; }
if sh easyrsa-unit-tests.sh "$verb"; then
: # ok
else
estat=1
fi
rm -f easyrsa-unit-tests.sh
fi
echo "estat: $estat"
exit $estat