From aa0d489e886115466ac127a1ae5ab0fc567db019 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Wed, 30 Aug 2023 20:08:40 +0200 Subject: [PATCH] Add verbose flag to test shell script --- default.nix | 2 +- tests/00-version.sh | 4 +++- tests/entrypoint.sh | 18 +++++++++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/default.nix b/default.nix index c69a8ec..b04bef3 100644 --- a/default.nix +++ b/default.nix @@ -167,6 +167,6 @@ in rec { tests = pkgs.writeShellScript "isle-tests" '' export PATH=$PATH:${appImage}/bin test_dir=${./tests} - exec $SHELL $test_dir/entrypoint.sh + exec $SHELL $test_dir/entrypoint.sh "$@" ''; } diff --git a/tests/00-version.sh b/tests/00-version.sh index 51f4d9d..f8b3bf4 100644 --- a/tests/00-version.sh +++ b/tests/00-version.sh @@ -1,2 +1,4 @@ version="$(isle version)" -test "$(echo "$version" | wc -l)" -gt 0 +echo "$version" | grep -q 'Release:' +echo "$version" | grep -q 'Platform:' +echo "$version" | grep -q 'Build Platform:' diff --git a/tests/entrypoint.sh b/tests/entrypoint.sh index 02cb6f7..bd84e28 100644 --- a/tests/entrypoint.sh +++ b/tests/entrypoint.sh @@ -1,5 +1,18 @@ set -e +while [[ $# -gt 0 ]]; do + case $1 in + -v|--verbose) + VERBOSE=1 + shift; + ;; + *) + echo "USAGE: [-v|--verbose]" + exit 1 + ;; + esac +done + # cd into script's directory cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null @@ -13,7 +26,10 @@ echo -e '\nrunning all tests...\n' for file in $(find . -type f -name '*.sh' | grep -v entrypoint.sh | sort -n); do echo "running test $file" - if ! $SHELL -e -x "$file" >"$tmp/$file.log" 2>&1; then + + [ -z "$VERBOSE" ] && output="$tmp/$file.log" || output=/dev/stdout + + if ! $SHELL -e -x "$file" >"$output" 2>&1; then echo "TEST FAILED" echo "output of test is as follows" echo "------------------------------"