-
Notifications
You must be signed in to change notification settings - Fork 1
/
test-p-bad.sh
64 lines (58 loc) · 980 Bytes
/
test-p-bad.sh
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
#! /bin/sh
# UCLA CS 111 Lab 1 - Test that syntax errors are caught.
tmp=$0-$$.tmp
mkdir "$tmp" || exit
(
cd "$tmp" || exit
status=
# Sanity check, to make sure it works with at least one good example.
echo x >test0.sh || exit
../timetrash -p test0.sh >test0.out 2>test0.err || exit
echo '# 1
x' >test0.exp || exit
diff -u test0.exp test0.out || exit
test ! -s test0.err || {
cat test0.err
exit 1
}
n=1
for bad in \
'`' \
'>' \
'<' \
'a >b <' \
';' \
'; a' \
'a ||' \
'a
|| b' \
'a
| b' \
'a
; b' \
'a;;b' \
'a&&&b' \
'a|||b' \
'|a' \
'< a' \
'&& a' \
'||a' \
'(a|b' \
'a;b)' \
'( (a)' \
'a>>>b'
do
echo "$bad" >test$n.sh || exit
../timetrash -p test$n.sh >test$n.out 2>test$n.err && {
echo >&2 "test$n: unexpectedly succeeded for: $bad"
status=1
}
test -s test$n.err || {
echo >&2 "test$n: no error message for: $bad"
status=1
}
n=$((n+1))
done
exit $status
) || exit
rm -fr "$tmp"