Skip to content

Commit

Permalink
fix: Create missing tmp dirs for test artifacts and cleanup before/af…
Browse files Browse the repository at this point in the history
…ter (#301)

fix: Only run cache tests once

This fix ensures the test script only runs the cache tests once, as intended. Prior, the cache test binary would get picked up by the `find` in test.sh and execute.

Because we don't explicitly run `make clean` here, subsequent test runs always fail.
  • Loading branch information
exbotanical authored Jun 18, 2024
1 parent 2c8ea52 commit 0aadc1d
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 19 deletions.
17 changes: 11 additions & 6 deletions test.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#!/bin/sh

mkdir -p tmp/bin
TESTS=$(find test/* -type f -perm -111)
ctrl_c () {
echo "Ctrl+c detected. Exiting..."
exit 1
}

trap ctrl_c INT

TESTS=$(find test/*.sh -type f -perm -111)
EXIT_CODE=0
export PATH="$PWD:$PATH"

Expand All @@ -17,21 +23,20 @@ for t in $TESTS; do
done
echo


printf "\nRunning clib package tests\n\n"
cd test/package && make clean

if ! make test; then
EXIT_CODE=1
EXIT_CODE=1
fi

cd ../../

printf "\nRunning clib cache tests\n\n"
cd test/cache
cd test/cache && make clean

if ! make test; then
EXIT_CODE=1
EXIT_CODE=1
fi

cd ../../
Expand Down
4 changes: 4 additions & 0 deletions test/install-binary-dependencies.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#!/bin/sh

mkdir -p tmp/bin
trap 'rm -rf tmp' EXIT

clib install -c -N stephenmathieson/[email protected] -P tmp > /dev/null || {
echo >&2 "Failed to install stephenmathieson/tabs-to-spaces"
exit 1
}

command -v tmp/bin/t2s >/dev/null 2>&1 || {
echo >&2 "Failed to put t2s on path"
exit 1
Expand Down
4 changes: 2 additions & 2 deletions test/install-brace-expansion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ throw() {
exit 1
}

trap 'rm -rf tmp' EXIT

clib install -c -N -o tmp stephenmathieson/trim.c stephenmathieson/case.c > /dev/null ||
throw "expecting successful exit code"

Expand All @@ -13,5 +15,3 @@ clib install -c -N -o tmp stephenmathieson/trim.c stephenmathieson/case.c > /dev

[ -d ./tmp/trim ] && [ -f ./tmp/trim/package.json ] ||
throw "failed to install trim.c"

rm -rf ./tmp
4 changes: 2 additions & 2 deletions test/install-deps-from-package-json.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ throw() {
exit 1
}

rm -rf tmp
mkdir -p tmp
trap 'rm -rf tmp' EXIT

cd tmp || exit

# see https://github.com/clibs/clib/issues/45
Expand All @@ -25,4 +26,3 @@ clib install > /dev/null 2>&1
[ $? -eq 1 ] || throw "expecting exit code of 1";

cd - > /dev/null || exit
rm -rf ./tmp
4 changes: 2 additions & 2 deletions test/install-multiple-clibs-libs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ throw() {
exit 1
}

trap 'rm -rf tmp' EXIT

clib install -c -N -o tmp ms file hash > /dev/null ||
throw "expecting successful exit code"

Expand All @@ -16,5 +18,3 @@ clib install -c -N -o tmp ms file hash > /dev/null ||

[ -d ./tmp/hash ] && [ -f ./tmp/hash/package.json ] ||
throw "failed to install hash"

rm -rf ./tmp
4 changes: 2 additions & 2 deletions test/install-multiple-libs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ throw() {
exit 1
}

trap 'rm -rf tmp' EXIT

clib install -c -N -o tmp \
stephenmathieson/case.c stephenmathieson/trim.c > /dev/null ||
throw "expecting successful exit code"
Expand All @@ -14,5 +16,3 @@ clib install -c -N -o tmp \

[ -d ./tmp/trim ] && [ -f ./tmp/trim/package.json ] ||
throw "failed to install trim.c"

rm -rf ./tmp
7 changes: 5 additions & 2 deletions test/install-no-save.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/bin/sh
mkdir -p tmp/test-save
mkdir -p tmp/test-save/bin
RUNDIR="$PWD"
trap 'rm -rf "$RUNDIR/tmp"' EXIT

cp test/data/test-save-package.json tmp/test-save/package.json

cd tmp/test-save || exit
../../clib-install -c --no-save stephenmathieson/[email protected] >/dev/null
../../clib-install -c --no-save stephenmathieson/[email protected] -P . >/dev/null
../../clib-install -c -N darthtrevino/[email protected] >/dev/null
../../clib-install -c --dev --no-save jwerle/[email protected] >/dev/null
../../clib-install -c -d --no-save clibs/[email protected] >/dev/null
Expand Down
7 changes: 5 additions & 2 deletions test/install-save.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/bin/sh
mkdir -p tmp/test-save
mkdir -p tmp/test-save/bin
RUNDIR="$PWD"
trap 'rm -rf "$RUNDIR/tmp"' EXIT

cp test/data/test-save-package.json tmp/test-save/package.json

cd tmp/test-save || exit
../../clib-install -c stephenmathieson/[email protected] >/dev/null
../../clib-install -c stephenmathieson/[email protected] -P . >/dev/null
../../clib-install -c darthtrevino/[email protected] >/dev/null
../../clib-install -c --dev jwerle/[email protected] >/dev/null
../../clib-install -c -D clibs/[email protected] >/dev/null
Expand Down
2 changes: 1 addition & 1 deletion test/uninstall.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

mkdir -p tmp/bin
trap 'rm -rf tmp' EXIT

clib install -c -N stephenmathieson/[email protected] -P tmp > /dev/null || {
echo >&2 "Failed to install stephenmathieson/tabs-to-spaces"
Expand Down

0 comments on commit 0aadc1d

Please sign in to comment.