Skip to content

Commit

Permalink
enh: tests: add --skip-functional-tests --skip-unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
speed47 committed Dec 31, 2024
1 parent 182af79 commit 1c8482b
Showing 1 changed file with 42 additions and 27 deletions.
69 changes: 42 additions & 27 deletions tests/functional/launch_tests_on_instance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,23 @@ opt_slowness_factor=1
opt_log_prefix=
opt_module=
opt_post_run=
opt_functional_tests=1
opt_unit_tests=1
declare -A capabilities=( [ed25519]=1 [mfa]=1 [mfa-password]=0 [pamtester]=1 [piv]=1 [sk]=0 )

# set the helptext now to get the proper default values
help_text=$(cat <<EOF
Test Options:
Functional Test Options:
--consistency-check Check system consistency between every test
--no-pause-on-fail Don't pause when a test fails
--log-prefix=X Prefix all logs by this name
--module=X Only test this module (specify a filename found in \`functional/tests.d/\`), can be specified multiple times
--slowness-factor=X If your test environment is slow, set this to 2, 3 or more to use higher timeouts (default: 1)
--post-run=X Commands to run after we're done testing
--skip-functional-tests Skip functional tests
Unit Test Options:
--skip-unit-tests Skip unit tests
Remote OS directory locations:
--remote-etc-bastion=X Override the default remote bastion configuration directory (default: $opt_remote_etc_bastion)
Expand Down Expand Up @@ -99,6 +105,12 @@ do
fi
opt_module="$opt_module $optval"
;;
--skip-functional-tests)
opt_functional_tests=0
;;
--skip-unit-tests)
opt_unit_tests=0
;;
--has-*=*)
optname=${1/--has-/}
optname=${optname/=*/}
Expand Down Expand Up @@ -743,35 +755,38 @@ runtests()
success "done" true
}

COUNTONLY=0
echo '=== running unit tests ==='
# a while read loop doesn't work well here:
# shellcheck disable=SC2044
for f in $(find "$basedir/tests/unit/" -mindepth 1 -maxdepth 1 -type f -name "*.pl" -print)
do
fbasename=$(basename "$f")
echo "-> $fbasename"
set +e
$r0 perl "$opt_remote_basedir/tests/unit/$fbasename"; ret=$?
set -e
if [ $ret != 0 ]; then
printf "%b%b%b\\n" "$WHITE_ON_RED" "Unit tests failed (ret=$ret) :(" "$NOC"
exit 1
fi
done
if [ "$opt_unit_tests" = 1 ]; then
echo '=== running unit tests ==='
# a while read loop doesn't work well here:
# shellcheck disable=SC2044
for f in $(find "$basedir/tests/unit/" -mindepth 1 -maxdepth 1 -type f -name "*.pl" -print)
do
fbasename=$(basename "$f")
echo "-> $fbasename"
set +e
$r0 perl "$opt_remote_basedir/tests/unit/$fbasename"; ret=$?
set -e
if [ $ret != 0 ]; then
printf "%b%b%b\\n" "$WHITE_ON_RED" "Unit tests failed (ret=$ret) :(" "$NOC"
exit 1
fi
done
fi

COUNTONLY=1
testno=0
echo '=== counting functional tests ==='
runtests
testcount=$testno
if [ "$opt_functional_tests" = 1 ]; then
COUNTONLY=1
testno=0
echo '=== counting functional tests ==='
runtests
testcount=$testno

echo "=== will run $testcount functional tests ==="
COUNTONLY=0
testno=0
runtests
fi

echo "=== will run $testcount functional tests ==="
COUNTONLY=0
testno=0
runtests
echo

if [ $((nbfailedret + nbfailedgrep + nbfailedcon + nbfailedgeneric)) -eq 0 ] ; then
printf "%b%b%b\\n" "$BLACK_ON_GREEN" "All tests succeeded :)" "$NOC"
else
Expand Down

0 comments on commit 1c8482b

Please sign in to comment.