Skip to content

Commit

Permalink
CI: prettier testing, (slightly) easier local dev/testing
Browse files Browse the repository at this point in the history
  • Loading branch information
HumorBaby committed Aug 7, 2019
1 parent 7d6f1aa commit 4360a0b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ script:
# Initial build with default parameters
- docker build --build-arg VERSION="${INSP_VERSION}" -t inspircd:testing .
# Run all tests from test directory
- for file in tests/*.sh; do sh $file || exit $?;done
- ./run_tests.sh

after_success:
# Push successful builds of the master branch to Docker Hub
Expand Down
47 changes: 47 additions & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

export INSP_VERSION

clean_up() {
local ret_val="$?"

# Clean up any remaining containers (e.g., due to fast-failing test)
local inspircd_containers="$(docker ps -q -a -f "ancestor=inspircd:testing")"
if [[ -n "${inspircd_containers}" ]]; then
docker rm -fv ${inspircd_containers}
fi

# Exit with ultimate exit code
exit "${ret_val}"
}
trap clean_up EXIT

# Make sure test-tracking file exists
touch ok_tests.txt
pad=$(printf '.%.0s' {1..100})

for test_file in tests/*.sh; do
printf "%.35s " "${test_file} ${pad}"

# Check if test already passed.
grep -w -q "$(sha1sum "${test_file}")" ok_tests.txt \
&& { printf "0 ( OK )\n"; continue; } \
|| true

# Run test, capturing all output to log variable
test_log=$(sh "${test_file}" 2>&1)
[[ $? -eq 0 ]] \
&& {
echo "0 ( OK )"
sha1sum "${test_file}" >> ok_tests.txt
} \
|| {
ret=$?
echo "${ret} (FAIL)"
# Print full output of test script
echo "${test_log}"
exit ${ret}
}
done
# Remove test-tracking cache on successful tests.
rm ok_tests.txt

0 comments on commit 4360a0b

Please sign in to comment.