-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtest_dev.sh
executable file
·95 lines (84 loc) · 1.83 KB
/
test_dev.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
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
#!/bin/bash
# build the project
## PS. Now this test do not generate any file.
## keep the -o file_name just for satisfy the command line option requirement
cargo build
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m'
inc=0
crust_compile() {
echo "TEST $inc: parse [$1]"
echo "crust parse $1.c -> ast" && ./target/debug/crust $1.c
}
echo -e "[${BLUE}test begins${NC}]"
echo -e "${BLUE}crust now only try to parse those files${NC}"
srcdir=test/valid
for f in $srcdir/*.c
do
inc=$(($inc+1))
file=${f%.*}
crust_compile $file ./gen/$file
if [ "$?" -ne 0 ]; then
echo -e "[${RED}Error${NC}]"
exit 1
else
echo -e "[${BLUE}parse ok${NC}]"
fi
done
srcdir=sample_code
for f in $srcdir/*.c
do
inc=$(($inc+1))
file=${f%.*}
crust_compile $file ./gen/$file
if [ "$?" -ne 0 ]; then
echo -e "[${RED}Error${NC}]"
exit 1
else
echo -e "[${BLUE}parse ok${NC}]"
fi
done
# should cause error in parser
srcdir=test/invalid
for f in $srcdir/*.c
do
inc=$(($inc+1))
file=${f%.*}
crust_compile $file ./gen/$file
if [ "$?" -ne 1 ]; then
echo -e "[${RED}Error${NC}]"
exit 1
else
echo -e "[${BLUE}parse ok${NC}]"
fi
done
# should cause no error
srcdir=test/valid/parser
for f in $srcdir/*.c
do
inc=$(($inc+1))
file=${f%.*}
crust_compile $file ./gen/$file
if [ "$?" -ne 0 ]; then
echo -e "[${RED}Error${NC}]"
exit 1
else
echo -e "[${BLUE}parse ok${NC}]"
fi
done
# test for preprocessor
srcdir=test/valid/cpp
for f in $srcdir/*.c
do
inc=$(($inc+1))
file=${f%.*}
crust_compile $file ./gen/$file
if [ "$?" -ne 0 ]; then
echo -e "[${RED}Error${NC}]"
exit 1
else
echo -e "[${BLUE}parse ok${NC}]"
fi
done
echo -e "Now the parser can parse them all"