From 4360a0b5400f3fd39b11fbf1e477652f8f37065c Mon Sep 17 00:00:00 2001 From: Humorous Baby Date: Tue, 6 Aug 2019 23:07:36 -0400 Subject: [PATCH] CI: prettier testing, (slightly) easier local dev/testing --- .travis.yml | 2 +- run_tests.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100755 run_tests.sh diff --git a/.travis.yml b/.travis.yml index c8b6938..1a5a8fb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/run_tests.sh b/run_tests.sh new file mode 100755 index 0000000..b248526 --- /dev/null +++ b/run_tests.sh @@ -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