From 4a9eb8522e1c718af5e77352801855a6020cd604 Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Tue, 10 May 2016 20:43:31 +0200 Subject: [PATCH] Add start of regression testing of packages Current plan is to have a tests/ folder in packages, where each file in this folder is a shell script which indicates a test failure by a non-zero exit value. --- .../ruby/tests/default_encoding_isutf8.sh | 1 + .../ruby/tests/extension_modules_installed.sh | 2 + scripts/test-runner.sh | 42 +++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 packages/ruby/tests/default_encoding_isutf8.sh create mode 100644 packages/ruby/tests/extension_modules_installed.sh create mode 100755 scripts/test-runner.sh diff --git a/packages/ruby/tests/default_encoding_isutf8.sh b/packages/ruby/tests/default_encoding_isutf8.sh new file mode 100644 index 000000000..87796c157 --- /dev/null +++ b/packages/ruby/tests/default_encoding_isutf8.sh @@ -0,0 +1 @@ +assert_equals '#' `ruby -e 'p Encoding.default_external'` diff --git a/packages/ruby/tests/extension_modules_installed.sh b/packages/ruby/tests/extension_modules_installed.sh new file mode 100644 index 000000000..d04b61c42 --- /dev/null +++ b/packages/ruby/tests/extension_modules_installed.sh @@ -0,0 +1,2 @@ +ruby -e "require 'readline'" +ruby -e "require 'openssl'" diff --git a/scripts/test-runner.sh b/scripts/test-runner.sh new file mode 100755 index 000000000..e48681616 --- /dev/null +++ b/scripts/test-runner.sh @@ -0,0 +1,42 @@ +#!/data/data/com.termux/files/usr/bin/bash + +if [ $# != 1 ]; then + echo "Specify package to run tests for as only argument" + exit 1 +fi + +PACKAGE=$1 +TEST_DIR=packages/$PACKAGE/tests + +if [ ! -d $TEST_DIR ]; then + echo "ERROR: No tests folder for package $PACKAGE" + exit 1 +fi + +NUM_TESTS=0 +NUM_FAILURES=0 + +for TEST_SCRIPT in $TEST_DIR/*; do + test -t 1 && printf "\033[32m" + echo "Running test ${TEST_SCRIPT}..." + (( NUM_TESTS += 1 )) + test -t 1 && printf "\033[31m" + ( + assert_equals() { + FIRST=$1 + SECOND=$2 + if [ "$FIRST" != "$SECOND" ]; then + echo "assertion failed - expected '$FIRST', got '$SECOND'" + exit 1 + fi + } + set -e -u + . $TEST_SCRIPT + ) + if [ $? != 0 ]; then + (( NUM_FAILURES += 1 )) + fi + test -t 1 && printf "\033[0m" +done + +echo "$NUM_TESTS tests run - $NUM_FAILURES failure(s)"