-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #378 from pamarcos/add_unit_tests_to_ci
Add unit test run to the CI
- Loading branch information
Showing
2 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,6 @@ os: | |
compiler: | ||
- gcc | ||
- clang | ||
script: make | ||
script: | ||
- make | ||
- test/unittest/run_all.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |