diff --git a/default.nix b/default.nix index 64a50d3..6f20c08 100644 --- a/default.nix +++ b/default.nix @@ -169,4 +169,10 @@ in rec { mv Isle-* "$out"/bin/isle ''; }; + + tests = pkgs.writeShellScript "isle-tests" '' + export PATH=$PATH:${appImage}/bin + test_dir=${./tests} + exec $SHELL $test_dir/entrypoint.sh + ''; } diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..68149b4 --- /dev/null +++ b/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +$(nix-build --no-out-link -A tests) diff --git a/tests/00-version.sh b/tests/00-version.sh new file mode 100644 index 0000000..51f4d9d --- /dev/null +++ b/tests/00-version.sh @@ -0,0 +1,2 @@ +version="$(isle version)" +test "$(echo "$version" | wc -l)" -gt 0 diff --git a/tests/entrypoint.sh b/tests/entrypoint.sh new file mode 100644 index 0000000..02cb6f7 --- /dev/null +++ b/tests/entrypoint.sh @@ -0,0 +1,27 @@ +set -e + +# cd into script's directory +cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null + +tmp="$(mktemp --tmpdir -d isle-tests.XXXXXX)" +trap 'rm -rf $tmp' EXIT + +export TMPDIR="$tmp" +echo "tmp dir is $TMPDIR" + +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 + echo "TEST FAILED" + echo "output of test is as follows" + echo "------------------------------" + cat "$tmp/$file.log" + echo "------------------------------" + exit 1 + fi +done + +echo -e '\ntests succeeded!' +