-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·112 lines (92 loc) · 2.75 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·112 lines (92 loc) · 2.75 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/dash
# Simple test harness infrastructure
# Copyright 2005 by Rob Landley
# The following environment varAiables enable optional behavior in "testc":
# DEBUG - Show every command run by test script.
# VERBOSE - "all" continue after failed test
# "fail" show diff and stop at first failed test
# "nopass" don't show successful tests
# "quiet" don't show diff -u for failures
# "spam" show passing test command lines
#
# "testc" takes three arguments:
# $1) Description to display when running command
# $2) Command line arguments to command
# $3) Expected result (on stdout)
#
: "${SHOWPASS:=PASS}" "${SHOWFAIL:=FAIL}" "${SHOWSKIP:=SKIP}" "${TESTDIR:=$(mktemp -d)}"
[ "${TESTDIR#*tmp.}" != "${TESTDIR}" ] && trap "rm -rf $TESTDIR" 0
if tty -s <&1
then
SHOWPASS="$(printf "\033[1;32m%s\033[0m" "$SHOWPASS")"
SHOWFAIL="$(printf "\033[1;31m%s\033[0m" "$SHOWFAIL")"
SHOWSKIP="$(printf "\033[1;33m%s\033[0m" "$SHOWSKIP")"
fi
verbose_has() {
[ "${VERBOSE#*"$1"}" != "$VERBOSE" ]
}
do_pass() {
verbose_has nopass || printf "%s\n" "$SHOWPASS: $NAME"
}
do_fail() {
printf "%s\n" "$SHOWFAIL: $NAME"
if [ -n "$CASE" ]
then
echo "Expected '$CASE'"
echo "Got '$A'"
fi
! verbose_has all && exit 1
}
# testing: "name" "args" "result"
testc() {
[ -z "$1" ] && NAME="$2" || NAME="$1"
[ "${NAME#"$CMDNAME "}" = "$NAME" ] && NAME="$CMDNAME $1"
[ -n "$DEBUG" ] && set -x
if [ -n "$SKIP" ]
then
verbose_has quiet || printf "%s\n" "$SHOWSKIP: $NAME"
return 0
fi
echo -n "$3" > "$TESTDIR"/expected
${EVAL:-eval} "$PROG $2" > "$TESTDIR"/actual
RETVAL=$?
# Catch segfaults
[ "$RETVAL" -ne "0" ] &&
echo "exited with signal (or returned $RETVAL)" >> "$TESTDIR"/actual
DIFF="$(diff --color=always -au${NOSPACE:+w} $TESTDIR/expected $TESTDIR/actual 2>&1)"
[ -z "$DIFF" ] && do_pass || VERBOSE=all do_fail
if ! verbose_has quiet && { [ -n "$DIFF" ] || verbose_has spam; }
then
printf "%s\n" "$EVAL $PROG $2"
[ -n "$DIFF" ] && printf "%s\n" "$DIFF"
fi
[ -n "$DIFF" ] && ! verbose_has all && exit 1
rm -f "$TESTDIR"/input "$TESTDIR/"expected "$TESTDIR"/actual
return 0
}
LONGSTRING="$(printf -- "a%150s" potato)"
PROGRAM () {
echo "PROGRAM: $1"
$CC $CFLAGS test/$1.c lib/libnewtime.a -o test/tprogs/$1
PROG=test/tprogs/$1
}
test_group () {
PROGRAM $1
testc "GROUP $1" "$2" "$(cat test/files/${1}-desired)\n"
}
test_group_dates () {
test_group "$1" "$(cat test/files/dates)"
}
PROGRAM date
testc "date()" "" ""
test_group_dates "wdayof"
test_group_dates "seconds"
test_group_dates "mins"
test_group_dates "hour"
test_group_dates "year"
test_group_dates "month"
test_group "fromcal"
test_group "datestr"
test_group_dates "tz"
PROGRAM sleep
testc "sleepf()" "" ""