-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·55 lines (46 loc) · 945 Bytes
/
test.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
#!/bin/bash
assert() {
expected="$1"
input="$2"
./9cc "$input" > tmp.s
cc -Wl,-z,noexecstack -o tmp tmp.s
./tmp
actual="$?"
if [ "$actual" = "$expected" ]; then
echo "'$input' => $actual"
else
echo "'$input' => $expected expected, but got $actual"
exit 1
fi
}
assert 0 "0;"
assert 42 "42;"
assert 21 "5+20-4;"
assert 41 " 12 + 34 - 5 ;"
assert 47 "5+6*7;"
assert 15 "5*(9-6);"
assert 4 "(3+5)/2;"
assert 10 "-10+20;"
assert 0 "0==1;"
assert 1 "42==42;"
assert 1 "0!=1;"
assert 0 "42!=42;"
assert 1 "0<1;"
assert 0 "1<1;"
assert 0 "2<1;"
assert 1 "0<=1;"
assert 1 "1<=1;"
assert 0 "2<=1;"
assert 1 "1>0;"
assert 0 "1>1;"
assert 0 "1>2;"
assert 1 "1>=0;"
assert 1 "1>=1;"
assert 0 "1>=2;"
assert 11 "a = 11; b = 32; a;"
assert 32 "a = 11; b = 32; b;"
assert 43 "a = 11; b = 32; a+b;"
assert 3 "a = 11; b = a = 3; a;"
assert 5 "abc = 2; foo_2 = 4; abc + 3;"
assert 10 "abc = 2; foo_2 = 4; foo_2 + 6;"
echo OK