Skip to content

Commit 0aadc1d

Browse files
authored
fix: Create missing tmp dirs for test artifacts and cleanup before/after (#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.
1 parent 2c8ea52 commit 0aadc1d

9 files changed

+34
-19
lines changed

test.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
#!/bin/sh
22

3-
mkdir -p tmp/bin
4-
TESTS=$(find test/* -type f -perm -111)
3+
ctrl_c () {
4+
echo "Ctrl+c detected. Exiting..."
5+
exit 1
6+
}
7+
8+
trap ctrl_c INT
9+
10+
TESTS=$(find test/*.sh -type f -perm -111)
511
EXIT_CODE=0
612
export PATH="$PWD:$PATH"
713

@@ -17,21 +23,20 @@ for t in $TESTS; do
1723
done
1824
echo
1925

20-
2126
printf "\nRunning clib package tests\n\n"
2227
cd test/package && make clean
2328

2429
if ! make test; then
25-
EXIT_CODE=1
30+
EXIT_CODE=1
2631
fi
2732

2833
cd ../../
2934

3035
printf "\nRunning clib cache tests\n\n"
31-
cd test/cache
36+
cd test/cache && make clean
3237

3338
if ! make test; then
34-
EXIT_CODE=1
39+
EXIT_CODE=1
3540
fi
3641

3742
cd ../../

test/install-binary-dependencies.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#!/bin/sh
22

3+
mkdir -p tmp/bin
4+
trap 'rm -rf tmp' EXIT
5+
36
clib install -c -N stephenmathieson/tabs-to-spaces@1.0.0 -P tmp > /dev/null || {
47
echo >&2 "Failed to install stephenmathieson/tabs-to-spaces"
58
exit 1
69
}
10+
711
command -v tmp/bin/t2s >/dev/null 2>&1 || {
812
echo >&2 "Failed to put t2s on path"
913
exit 1

test/install-brace-expansion.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ throw() {
55
exit 1
66
}
77

8+
trap 'rm -rf tmp' EXIT
9+
810
clib install -c -N -o tmp stephenmathieson/trim.c stephenmathieson/case.c > /dev/null ||
911
throw "expecting successful exit code"
1012

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

1416
[ -d ./tmp/trim ] && [ -f ./tmp/trim/package.json ] ||
1517
throw "failed to install trim.c"
16-
17-
rm -rf ./tmp

test/install-deps-from-package-json.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ throw() {
55
exit 1
66
}
77

8-
rm -rf tmp
98
mkdir -p tmp
9+
trap 'rm -rf tmp' EXIT
10+
1011
cd tmp || exit
1112

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

2728
cd - > /dev/null || exit
28-
rm -rf ./tmp

test/install-multiple-clibs-libs.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ throw() {
55
exit 1
66
}
77

8+
trap 'rm -rf tmp' EXIT
9+
810
clib install -c -N -o tmp ms file hash > /dev/null ||
911
throw "expecting successful exit code"
1012

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

1719
[ -d ./tmp/hash ] && [ -f ./tmp/hash/package.json ] ||
1820
throw "failed to install hash"
19-
20-
rm -rf ./tmp

test/install-multiple-libs.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ throw() {
55
exit 1
66
}
77

8+
trap 'rm -rf tmp' EXIT
9+
810
clib install -c -N -o tmp \
911
stephenmathieson/case.c stephenmathieson/trim.c > /dev/null ||
1012
throw "expecting successful exit code"
@@ -14,5 +16,3 @@ clib install -c -N -o tmp \
1416

1517
[ -d ./tmp/trim ] && [ -f ./tmp/trim/package.json ] ||
1618
throw "failed to install trim.c"
17-
18-
rm -rf ./tmp

test/install-no-save.sh

100644100755
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#!/bin/sh
2-
mkdir -p tmp/test-save
2+
mkdir -p tmp/test-save/bin
3+
RUNDIR="$PWD"
4+
trap 'rm -rf "$RUNDIR/tmp"' EXIT
5+
36
cp test/data/test-save-package.json tmp/test-save/package.json
47

58
cd tmp/test-save || exit
6-
../../clib-install -c --no-save stephenmathieson/tabs-to-spaces@1.0.0 >/dev/null
9+
../../clib-install -c --no-save stephenmathieson/tabs-to-spaces@1.0.0 -P . >/dev/null
710
../../clib-install -c -N darthtrevino/str-concat@0.0.2 >/dev/null
811
../../clib-install -c --dev --no-save jwerle/fs.c@0.1.1 >/dev/null
912
../../clib-install -c -d --no-save clibs/parson@1.0.2 >/dev/null

test/install-save.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#!/bin/sh
2-
mkdir -p tmp/test-save
2+
mkdir -p tmp/test-save/bin
3+
RUNDIR="$PWD"
4+
trap 'rm -rf "$RUNDIR/tmp"' EXIT
5+
36
cp test/data/test-save-package.json tmp/test-save/package.json
47

58
cd tmp/test-save || exit
6-
../../clib-install -c stephenmathieson/tabs-to-spaces@1.0.0 >/dev/null
9+
../../clib-install -c stephenmathieson/tabs-to-spaces@1.0.0 -P . >/dev/null
710
../../clib-install -c darthtrevino/str-concat@0.0.2 >/dev/null
811
../../clib-install -c --dev jwerle/fs.c@0.1.1 >/dev/null
912
../../clib-install -c -D clibs/parson@1.0.2 >/dev/null

test/uninstall.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
2-
32
mkdir -p tmp/bin
3+
trap 'rm -rf tmp' EXIT
44

55
clib install -c -N stephenmathieson/tabs-to-spaces@1.0.0 -P tmp > /dev/null || {
66
echo >&2 "Failed to install stephenmathieson/tabs-to-spaces"

0 commit comments

Comments
 (0)