diff --git a/default.nix b/default.nix index a281680..6e75765 100644 --- a/default.nix +++ b/default.nix @@ -164,18 +164,9 @@ in rec { ''; }; - tests = pkgs.writeShellScript "isle-tests" '' - export PATH=${appImage}/bin:$PATH - test_dir=${./tests} - - this_user="$(${pkgs.coreutils}/bin/whoami)" - - echo "Requesting sudo in order to set thread capabilities, will drop back down to user '$this_user' immediately" - sudo ${pkgs.libcap}/bin/capsh \ - --caps="cap_net_admin+eip cap_setpcap,cap_setuid,cap_setgid+ep" \ - --keep=1 \ - --user="$this_user" \ - --addamb=cap_net_admin \ - -- $test_dir/entrypoint.sh "$@" + tests = pkgs.writeScript "isle-tests" '' + export PATH=${pkgs.lib.makeBinPath [ appImage pkgs.busybox ]} + export SHELL=${pkgs.bash}/bin/bash + exec ${./tests}/entrypoint.sh "$@" ''; } diff --git a/nix/appimagetool.nix b/nix/appimagetool.nix index 3086842..a6b2706 100644 --- a/nix/appimagetool.nix +++ b/nix/appimagetool.nix @@ -12,7 +12,8 @@ let # The author of go-appimage has set up some crazy continuous integration build # system with github, which is really cool, except that it doesn't preserve # any older builds of the project. And it's pretty difficult to build it - # ourselves. So fuck it, just embed a tarball into the repo. + # ourselves. So fuck it, just embed the build artifacts directly in this + # project. src = { "x86_64" = "${srcDir}/appimagetool-${version}-x86_64.AppImage"; "aarch64" = "${srcDir}/go-appimage/appimagetool-${version}-aarch64.AppImage"; diff --git a/test.sh b/test.sh deleted file mode 100755 index 68149b4..0000000 --- a/test.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env sh - -$(nix-build --no-out-link -A tests) diff --git a/tests.sh b/tests.sh new file mode 100755 index 0000000..2cebb42 --- /dev/null +++ b/tests.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +set -e + +entrypoint="$(nix-build --no-out-link -A tests)" +this_user="$(whoami)" + +echo "Requesting sudo in order to set thread capabilities, will drop back down to user '$this_user' immediately" + +sudo -E capsh \ + --caps="cap_net_admin+eip cap_setpcap,cap_setuid,cap_setgid+ep" \ + --keep=1 \ + --user="$this_user" \ + --addamb=cap_net_admin \ + -- "$entrypoint" "$@" diff --git a/tests/00-version.sh b/tests/cases/00-version.sh similarity index 100% rename from tests/00-version.sh rename to tests/cases/00-version.sh diff --git a/tests/01-create-network.sh b/tests/cases/01-create-network.sh similarity index 100% rename from tests/01-create-network.sh rename to tests/cases/01-create-network.sh diff --git a/tests/entrypoint.sh b/tests/entrypoint.sh old mode 100644 new mode 100755 index c5a007e..e4ea2e2 --- a/tests/entrypoint.sh +++ b/tests/entrypoint.sh @@ -1,5 +1,9 @@ set -e +# cd into script's directory +cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null +root=$(pwd) + REGEXS=() while [[ $# -gt 0 ]]; do @@ -29,10 +33,6 @@ EOF esac done -# cd into script's directory -cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null -root=$(pwd) - TMPDIR="$(mktemp --tmpdir -d isle-tests.XXXXXX)" if [ -z "$KEEP_TMP" ]; then trap 'rm -rf $TMPDIR' EXIT; fi @@ -40,14 +40,14 @@ export TMPDIR echo "tmp dir is $TMPDIR" test_files=$( - find . -type f -name '*.sh' \ - | sed "s|^\./||" \ + find ./cases -type f -name '*.sh' \ + | sed "s|^\./cases/||" \ | grep -v entrypoint.sh \ - | sort -n\ + | sort -n ) for r in "${REGEXS[@]}"; do - test_files="$(echo "$test_files" | grep -P "$r")" + test_files="$(echo "$test_files" | grep "$r")" done echo -e "number of tests: $(echo "$test_files" | wc -l)\n" @@ -64,7 +64,7 @@ for file in $test_files; do mkdir -p "$TMPDIR" "$XDG_RUNTIME_DIR" "$XDG_DATA_HOME" cd "$TMPDIR" - if ! $SHELL -e -x "$root/$file" >"$output" 2>&1; then + if ! $SHELL -e -x "$root/cases/$file" >"$output" 2>&1; then echo "$file FAILED" if [ -z "$VERBOSE" ]; then echo "output of test is as follows" @@ -78,4 +78,3 @@ for file in $test_files; do done echo -e '\nall tests succeeded!' -