Skip to content

Commit

Permalink
Merge pull request #378 from pamarcos/add_unit_tests_to_ci
Browse files Browse the repository at this point in the history
Add unit test run to the CI
  • Loading branch information
marcobambini authored Jul 22, 2021
2 parents 4eea725 + 9783926 commit 6ec69ff
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ os:
compiler:
- gcc
- clang
script: make
script:
- make
- test/unittest/run_all.sh
46 changes: 46 additions & 0 deletions test/unittest/run_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

# This script is intended to be used either by the CI or by a developer that
# wants to check that no unit tests have been broken to ensure there are no
# regressions. At the end, it reports how many tests were successful. However,
# using grep we can easily filter out everything except for those tests that
# time out. e.g. ./run_all.sh | grep -i timeout -B1

set -u -o pipefail

readonly SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
readonly GRAVITY_BIN=$SCRIPT_DIR/../../gravity
files=$(find $SCRIPT_DIR -iname "*.gravity" | grep -v disabled)
tests_total=$(echo "$files" | wc -l)
tests_success=0
tests_fail=0
tests_timeout=0
i=1

for test in $files; do
echo "Testing $i/$tests_total - $test..."
# Set 0.1s by default, but fallback to 10s in case of memory or recursion test
timeout=0.1
if [[ "$test" =~ "mem" || "$test" =~ "recursion" ]]; then
timeout=10
fi
timeout $timeout "$GRAVITY_BIN" "$test"
res=$?
if [[ $res -eq 0 ]]; then
tests_success=$(($tests_success+1))
echo "Success!"
elif [[ $res -eq 124 ]]; then
echo "Timeout!"
tests_timeout=$(($tests_timeout+1))
else
echo "Fail!"
tests_fail=$(($tests_fail+1))
fi
i=$(($i+1))
done

echo "Tests run successfully: $tests_success/$tests_total. $tests_fail failed and $tests_timeout timed out"

if [[ $(($tests_fail+$tests_timeout)) -ne 0 ]]; then
exit 1
fi

0 comments on commit 6ec69ff

Please sign in to comment.