Compare commits

..

2 Commits

Author SHA1 Message Date
Brian Picciano
2876b56afb Fix how revision is embedded so that AppImage isn't always recompiled 2023-08-30 18:24:09 +02:00
Brian Picciano
e66f67da4a Super basic testing framework 2023-08-30 18:16:19 +02:00
6 changed files with 44 additions and 8 deletions

View File

@ -4,7 +4,7 @@
hostSystem ? buildSystem,
pkgsNix ? (import ./nix/pkgs.nix),
revision ? "",
revision ? "dev",
releaseName ? "dev",
bootstrap ? null,
@ -28,7 +28,6 @@ in rec {
name = "isle-version";
inherit buildSystem hostSystem revision releaseName;
repoSrc = ./.;
nativeBuildInputs = [ pkgsNative.git ];
@ -41,11 +40,6 @@ in rec {
versionFile=version
if [ "$revision" = "" ]; then
cp -r "$repoSrc" repoSrcCp
revision="$(cd repoSrcCp && git rev-parse HEAD)"
fi
echo "Release: $releaseName" >> "$versionFile"
echo "Platform: $hostSystem" >> "$versionFile"
echo "Git Revision: $revision" >> "$versionFile"
@ -169,4 +163,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
'';
}

View File

@ -1,5 +1,6 @@
{
releaseName,
revision,
buildSystem ? builtins.currentSystem,
pkgsNix ? (import ./nix/pkgs.nix),
@ -12,7 +13,7 @@
mkRelease = hostSystem: let
appImage = ((import ./default.nix) {
inherit buildSystem hostSystem releaseName;
inherit buildSystem hostSystem releaseName revision;
}).appImage;
in pkgs.stdenv.mkDerivation {

View File

@ -19,7 +19,10 @@ if [ -e "$out" ]; then
exit 1
fi
revision=$(git rev-parse HEAD)
result=$(nix-build \
--argstr revision "$revision" \
--argstr releaseName "$releaseName" \
--no-out-link \
release.nix \

3
test.sh Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env sh
$(nix-build --no-out-link -A tests)

2
tests/00-version.sh Normal file
View File

@ -0,0 +1,2 @@
version="$(isle version)"
test "$(echo "$version" | wc -l)" -gt 0

27
tests/entrypoint.sh Normal file
View File

@ -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!'