Skip to content

Commit

Permalink
make test: handle skipped tests (no longer displayed as failed)
Browse files Browse the repository at this point in the history
This improvement was suggested in issue #54.
  • Loading branch information
eduble committed May 26, 2023
1 parent e759181 commit 3ec6222
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
20 changes: 18 additions & 2 deletions dev/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

THIS_DIR="$(cd "$(dirname $0)"; pwd)"
TESTS_DIR="$(cd "$THIS_DIR/../test"; pwd)"
TMP_DIR="$(mktemp -d)"

__test_suite_debug_tests=0

Expand All @@ -13,8 +14,14 @@ fi

__testsuite_num_tests=0
__testsuite_num_tests_failed=0
__testsuite_num_tests_skipped=0
__testsuite_test_name=""

skip_test() {
echo "$*" > $TMP_DIR/skipped
return 1
}

__testsuite_exec_prev_test() {
if [[ $__testsuite_test_name != "" ]]
then
Expand Down Expand Up @@ -49,6 +56,11 @@ __testsuite_exec_prev_test() {
if [ "$__testsuite_result" = 0 ]
then
echo -e '\r \xE2\x9C\x94'
elif [ -f $TMP_DIR/skipped ]
then
__testsuite_num_tests_skipped=$((__testsuite_num_tests_skipped+1))
echo -e "\e[33m\r - $__testsuite_test_name -- skipped -- $(cat $TMP_DIR/skipped)\e[0m"
rm $TMP_DIR/skipped
else
__testsuite_num_tests_failed=$((__testsuite_num_tests_failed+1))
echo -e "\e[31m\r \xE2\x9C\x97 $__testsuite_test_name"
Expand Down Expand Up @@ -90,7 +102,7 @@ then
TEST_TO_RUN=("$TESTS_DIR"/*.sh)
fi

__testsuite_modified_source="$(mktemp)"
__testsuite_modified_source="$TMPDIR/modified_source.sh"

for __testsuite_source_file in "${TEST_TO_RUN[@]}"
do
Expand All @@ -100,11 +112,15 @@ do
__testsuite_exec_prev_test
done

rm "$__testsuite_modified_source"
rm -rf "$TMPDIR"

# summary
echo
echo -n " $__testsuite_num_tests test(s), "
if [[ $__testsuite_num_tests_skipped -gt 0 ]]
then
echo -en "\e[33m$__testsuite_num_tests_skipped skipped\e[0m, "
fi
if [[ $__testsuite_num_tests_failed -eq 0 ]]
then
echo "no failure."
Expand Down
3 changes: 1 addition & 2 deletions test/walt-device.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ define_test "walt device shell (on non existing device)" as {
define_test "walt device expose" as {

which wget || {
echo 'This test requires the "wget" command.' >&2
return 1
skip_test 'requires the "wget" command'
}

# use walt device expose to redirect port localhost:8083 to <server-ip>:80
Expand Down
7 changes: 4 additions & 3 deletions test/walt-help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ define_test "walt help list" as {
walt help list
}

define_test "walt help show" as {
define_test "walt help show (no tty)" as {
# test non-interactive (no tty)
walt help show | grep -i walt
}

define_test "walt help show (tty)" as {
# test interactive session
# we use expect to emulate a tty session.
# we send "q" after 2 seconds.
# walt command should not timeout, and return code 0 (OK)
which expect || {
echo 'This test requires the "expect" command.' >&2
return 1
skip_test 'requires the "expect" command'
}

expect << EOF
Expand Down
3 changes: 1 addition & 2 deletions test/walt-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ define_test "walt node expose" as {
node="$(test_suite_node)"

which nc || {
echo 'This test requires the "nc" command.' >&2
return 1
skip_test 'requires the "nc" command'
}

# run a echo server on the node for 5 seconds
Expand Down

0 comments on commit 3ec6222

Please sign in to comment.