-
Notifications
You must be signed in to change notification settings - Fork 15
/
runtests
executable file
·46 lines (40 loc) · 1.13 KB
/
runtests
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
# usage: plash test [TEST-PREFIX]
# Run unit tests.
# You can filter tests to run by a prefix passed as first argument
set -eu
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROJECT_DIR="$DIR"
log=$(mktemp)
program_exit=0
cd $PROJECT_DIR/tests
testfiles=$(find . -type f -executable -ipath "./${1:-}*" | sort)
for script in $testfiles ; do
# setup test env
tmp=$(mktemp -d /tmp/plashtest-XXXXXXXX)
export PLASH_DATA=$tmp
plash init
machine="$(uname --machine)"
plash import-tar $PROJECT_DIR/data/test-rootfs-"$machine".tar > /dev/null
printf "% -20s" tests/${script:2} # magic 2 is the length of "./"
env "$script" > $log 2>&1 &
if wait $!; then
echo ' PASS'
else
skip_marker=$(tail -n2 $log | head -n1)
if test "$skip_marker" = 'SKIP MARKER'; then
echo ' SKIP'
continue
fi
echo ' FAIL'
program_exit=1
test_mark_line=$(grep -n '^+ : ' $log | tail -n1 | cut -d: -f1)
if [[ $test_mark_line =~ ^-?[0-9]+$ ]]; then
tail -n +$test_mark_line $log | sed 's/^/ | /' >&2
else
cat $log | sed 's/^/ | /' >&2
fi
echo
fi
done
exit $program_exit