-
Notifications
You must be signed in to change notification settings - Fork 0
/
test
executable file
·161 lines (138 loc) · 4.33 KB
/
test
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
# 全ケースを実行する:
# USAGE: ./test
# 1ケースだけ実行する:
# USAGE: ./test empty
# コンパイラの標準入出力は test_stdout.md/test_stderr.md に出力される。
set -eu
f() {
NAME="$1"
CATEGORY="${2:-}"
if test "$CATEGORY" = ""
then
SRC="tests/$NAME/$NAME.jacco"
TXT="tests/$NAME/$NAME.txt"
else
SRC="tests/$CATEGORY/$NAME/$NAME.jacco"
TXT="tests/$CATEGORY/$NAME/$NAME.txt"
fi
echo 'test: '$SRC
echo -e '\n## test: '$SRC'\n\n```' | tee -a test_stderr.md >>test_stdout.md
RUST_BACKTRACE=1 RUST_LOG='trace' cargo run --bin jacco build "$SRC" \
1>"$TXT" \
2> >(tee -a test_stderr.md | grep -E 'Compiling|panicked|error|ERROR|\.rs\:' 1>&2)
echo '```' | tee -a test_stderr.md >>test_stdout.md
}
# V2
expect_compile_ok() {
NAME="$1"
CATEGORY="${2:-}"
if test "$CATEGORY" = ""
then
SRC="tests/$NAME/$NAME.jacco"
TXT="tests/$NAME/$NAME.txt"
else
SRC="tests/$CATEGORY/$NAME/$NAME.jacco"
TXT="tests/$CATEGORY/$NAME/$NAME.txt"
fi
echo 'test: '$SRC
echo -e '\n## test: '$SRC'\n\n```' | tee -a test_stderr.md >>test_stdout.md
RUST_BACKTRACE=1 RUST_LOG='trace' cargo run --bin jacco build --v2 "$SRC" \
1>"$TXT" \
2> >(tee -a test_stderr.md | grep -E 'Compiling|panicked|error|ERROR|\.rs\:' 1>&2)
echo '```' | tee -a test_stderr.md >>test_stdout.md
}
expect_compile_err() {
NAME="$1"
CATEGORY="${2:-}"
if test "$CATEGORY" = ""
then
SRC="tests/$NAME/$NAME.jacco"
ERR="tests/$NAME/${NAME}_stderr.log"
else
SRC="tests/$CATEGORY/$NAME/$NAME.jacco"
ERR="tests/$CATEGORY/$NAME/${NAME}_stderr.log"
fi
echo 'test: '$SRC
echo -e '\n## test: '$SRC'\n\n```' | tee -a test_stderr.md >>test_stdout.md
RUST_BACKTRACE=1 RUST_LOG='info' RUST_LOG_TIMESTAMP='off' \
cargo --quiet run --bin jacco build "$SRC" \
1> >(tee -a test_stdout.md >&2) \
2> >(tee "$ERR" | grep -E 'Compiling|panicked' 1>&2) \
|| :
# FIXME: コンパイルエラーが報告されなければテストは失敗とみなす。
echo '```' | tee -a test_stderr.md >>test_stdout.md
}
expect_run() {
NAME="$1"
CATEGORY="${2:-''}"
if test "$CATEGORY" = ""
then
SRC="tests/$NAME/$NAME.jacco"
CLANG="tests/$NAME/$NAME.g.c"
OUT="tests/$NAME/$NAME.out"
else
SRC="tests/$CATEGORY/$NAME/$NAME.jacco"
CLANG="tests/$CATEGORY/$NAME/$NAME.g.c"
OUT="tests/$CATEGORY/$NAME/$NAME.out"
fi
RUST_BACKTRACE=1 RUST_LOG=info cargo run --bin jacco build "$SRC">"$CLANG" \
&& gcc -std=c11 -g -Wall -Wno-unused-variable "$PWD/libtest/test.c" "$CLANG" -o "$OUT" \
&& "$OUT" \
|| echo "$NAME failed"
}
f_all() {
expect_compile_ok empty
expect_compile_ok exit_with_42
expect_compile_ok extern_fn
expect_compile_ok add
expect_compile_ok arithmetic
expect_compile_ok if
expect_compile_ok let
expect_compile_ok operators
expect_compile_ok complex
expect_compile_ok while
expect_compile_ok loop
expect_compile_ok break
expect_compile_ok continue
expect_compile_ok call_direct
expect_compile_ok return
expect_compile_ok assign
expect_compile_ok unit_like_struct
expect_compile_ok record_struct
expect_compile_ok char
expect_compile_ok bool
expect_compile_ok cast
expect_compile_ok int_types
expect_compile_ok str
expect_compile_ok ptr
expect_compile_ok const
expect_compile_ok call_with_pipe
expect_compile_ok float
expect_compile_ok static_var
expect_compile_ok match
expect_compile_ok enum_consts
expect_compile_ok enum_records
expect_compile_ok label_containing_nested_fn_issue issues
expect_compile_ok label_order_issue issues
expect_compile_ok block
expect_compile_ok use
}
ONLY=${1:-''}
: >test_stdout.md
: >test_stderr.md
if ! test -z $ONLY
then
expect_compile_ok $ONLY
else
f_all
# その他のテスト
expect_compile_err syntax_error
expect_compile_err undefined_local_var name_resolution
expect_run generic_hash_map integration
expect_run generic_swap_fn integration
cargo test
fi
# 差分の量を表示する。
git --no-pager diff --stat --relative -- 'tests/*/*.log' 'tests/*/*.txt'
echo 'FINISH'