forked from boyter/scc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-all.sh
executable file
·368 lines (329 loc) · 12.1 KB
/
test-all.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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
#!/bin/bash
echo "Running go fmt..."
gofmt -s -w ./..
echo "Running unit tests..."
go test ./... || exit
echo "Building application..."
go build -ldflags="-s -w" || exit
echo '```' > LANGUAGES.md
./scc --languages >> LANGUAGES.md
echo '```' >> LANGUAGES.md
echo "Running integration tests..."
GREEN='\033[1;32m'
RED='\033[0;31m'
NC='\033[0m'
if ./scc --not-a-real-option > /dev/null ; then
echo -e "${RED}================================================="
echo -e "FAILED Invalid option should produce error code "
echo -e "=======================================================${NC}"
exit
else
echo -e "${GREEN}PASSED invalid option test"
fi
if ./scc "examples/language/" --format cloc-yaml -o .tmp_scc_yaml >/dev/null && python <<EOS
import yaml,sys
try:
with open('.tmp_scc_yaml','r') as f:
data = yaml.load(f.read())
if type(data) is dict and data.keys():
sys.exit(0)
else:
print('data was {}'.format(type(data)))
except Exception as e:
pass
sys.exit(1)
EOS
then
echo -e "${GREEN}PASSED cloc-yaml format test"
else
echo -e "${RED}======================================================="
echo -e "${RED}FAILED Should accept --format cloc-yaml and should generate valid output"
echo -e "=======================================================${NC}"
rm -f .tmp_scc_yaml
exit
fi
if ./scc "examples/language/" --format cloc-yml -o .tmp_scc_yaml >/dev/null && python <<EOS
import yaml,sys
try:
with open('.tmp_scc_yaml','r') as f:
data = yaml.load(f.read())
if type(data) is dict and data.keys():
sys.exit(0)
else:
print('data was {}'.format(type(data)))
except Exception as e:
pass
sys.exit(1)
EOS
then
echo -e "${GREEN}PASSED cloc-yml format test"
else
echo -e "${RED}======================================================="
echo -e "${RED}FAILED Should accept --format cloc-yml and should generate valid output"
echo -e "=======================================================${NC}"
rm -f .tmp_scc_yaml
exit
fi
if ./scc NOTAREALDIRECTORYORFILE > /dev/null ; then
echo -e "${RED}================================================="
echo -e "FAILED Invalid file/directory should produce error code "
echo -e "=======================================================${NC}"
exit
else
echo -e "${GREEN}PASSED invalid file/directory test"
fi
if ./scc > /dev/null ; then
echo -e "${GREEN}PASSED no directory specified test"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should run correctly with no directory specified"
echo -e "=======================================================${NC}"
exit
fi
if ./scc processor > /dev/null ; then
echo -e "${GREEN}PASSED directory specified test"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should run correctly with directory specified"
echo -e "=======================================================${NC}"
exit
fi
if ./scc --avg-wage 10000 --binary --by-file --no-cocomo --debug --exclude-dir .git -f tabular -i go -c -d -M something -s name -w processor > /dev/null ; then
echo -e "${GREEN}PASSED multiple options test"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should run correctly with multiple options"
echo -e "=======================================================${NC}"
exit
fi
if ./scc -i sh -M "vendor|examples|p.*" > /dev/null ; then
echo -e "${GREEN}PASSED regular expression ignore test"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should run with regular expression ignore"
echo -e "=======================================================${NC}"
exit
fi
if ./scc "examples/shared_extension/" | grep -q "Coq"; then
echo -e "${GREEN}PASSED shared extension test 1"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should be able to work with shared extension 1"
echo -e "=======================================================${NC}"
exit
fi
if ./scc "examples/shared_extension/" | grep -q "Verilog"; then
echo -e "${GREEN}PASSED shared extension test 2"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should be able to work with shared extension 2"
echo -e "=======================================================${NC}"
exit
fi
if ./scc "examples/shared_extension/" | grep -q "V "; then
echo -e "${GREEN}PASSED shared extension test 3"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should be able to work with shared extension 3"
echo -e "=======================================================${NC}"
exit
fi
if ./scc --ci | grep -q "\-\-\-\-"; then
echo -e "${GREEN}PASSED ci param test"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should be able to work with ci flag"
echo -e "=======================================================${NC}"
exit
fi
# Simple test to see if we get any concurrency issues
for i in {1..100}
do
if ./scc > /dev/null ; then
:
else
echo -e "${RED}======================================================="
echo -e "FAILED Should not have concurrency issue"
echo -e "=================================================${NC}"
exit
fi
done
echo -e "${GREEN}PASSED concurrency issue test"
if ./scc main.go > /dev/null ; then
echo -e "${GREEN}PASSED file specified test"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should run correctly with a file is specified"
echo -e "=================================================${NC}"
exit
fi
# Multiple directory or file arguments
if ./scc main.go README.md | grep -q "Go " ; then
echo -e "${GREEN}PASSED multiple file argument test 1"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should work with multiple file arguments 1"
echo -e "=======================================================${NC}"
exit
fi
if ./scc main.go README.md | grep -q "Markdown " ; then
echo -e "${GREEN}PASSED multiple file argument test 2"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should work with multiple file arguments 2"
echo -e "=======================================================${NC}"
exit
fi
if ./scc processor scripts > /dev/null ; then
echo -e "${GREEN}PASSED multiple directory specified test"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should run correctly with multiple directory specified"
echo -e "=================================================${NC}"
exit
fi
if ./scc -v . | grep -q "skipping directory due to ignore: vendor" ; then
echo -e "${GREEN}PASSED ignore file directory check"
else
echo -e "${RED}======================================================="
echo -e "FAILED ignore file directory check"
echo -e "=======================================================${NC}"
exit
fi
# Try out duplicates
for i in {1..100}
do
if ./scc -d "examples/duplicates/" | grep -e "Java" | grep -q -e " 1 "; then
:
else
echo -e "${RED}======================================================="
echo -e "FAILED Duplicates should be consistent"
echo -e "=======================================================${NC}"
exit
fi
done
echo -e "${GREEN}PASSED duplicates test"
# Ensure deterministic output
a=$(./scc .)
for i in {1..100}
do
b=$(./scc .)
if [ "$a" == "$b" ]; then
:
else
echo -e "${RED}======================================================="
echo -e "FAILED Runs should be deterministic"
echo -e "=======================================================${NC}"
exit
fi
done
echo -e "${GREEN}PASSED deterministic test"
# Check for multiple regex via https://github.com/andyfitzgerald
a=$(./scc --not-match="(.*\.hex|.*\.d|.*\.o|.*\.csv|^(./)?[0-9]{8}_.*)" . | grep Estimated | md5sum)
b=$(./scc --not-match=".*\.hex" --not-match=".*\.d" --not-match=".*\.o" --not-match=".*\.csv" --not-match="^(./)?[0-9]{8}_.*" . | grep Estimated | md5sum)
if [ "$a" == "$b" ]; then
echo -e "${GREEN}PASSED multiple regex test"
else
echo -e "${RED}======================================================="
echo -e "FAILED multiple regex test"
echo -e "=================================================${NC}"
exit
fi
# Regression issue https://github.com/boyter/scc/issues/82
a=$(./scc . | grep Total)
b=$(./scc ${PWD} | grep Total)
if [ "$a" == "$b" ]; then
echo -e "${GREEN}PASSED git filter"
else
echo -e "${RED}======================================================="
echo -e "FAILED git filter"
echo -e "=================================================${NC}"
exit
fi
# Turn off gitignore https://github.com/boyter/scc/issues/53
touch ignored.xml
a=$(./scc | grep Total)
b=$(./scc --no-gitignore | grep Total)
if [ "$a" == "$b" ]; then
echo -e "${RED}================================================="
echo -e "FAILED git ignore filter"
echo -e "=================================================${NC}"
exit
else
echo -e "${GREEN}PASSED git ignore filter"
fi
a=$(./scc | grep Total)
b=$(./scc --no-ignore | grep Total)
if [ "$a" == "$b" ]; then
echo "$a"
echo "$b"
echo -e "${RED}======================================================="
echo -e "FAILED ignore filter"
echo -e "=================================================${NC}"
exit
else
echo -e "${GREEN}PASSED ignore filter"
fi
if ./scc "examples/ignore/" | grep -q "Java "; then
echo -e "${RED}======================================================="
echo -e "FAILED multiple gitignore"
echo -e "=======================================================${NC}"
exit
else
echo -e "${GREEN}PASSED multiple gitignore"
fi
touch ./examples/ignore/ignorefile.txt
a=$(./scc --by-file | grep ignorefile)
b=$(./scc --by-file --no-ignore | grep ignorefile)
if [ "$a" == "$b" ]; then
echo "$a"
echo "$b"
echo -e "${RED}======================================================="
echo -e "FAILED ignore recursive filter"
echo -e "=================================================${NC}"
exit
else
echo -e "${GREEN}PASSED ignore recursive filter"
fi
touch ./examples/ignore/gitignorefile.txt
a=$(./scc --by-file | grep gitignorefile)
b=$(./scc --by-file --no-gitignore | grep gitignorefile)
if [ "$a" == "$b" ]; then
echo "$a"
echo "$b"
echo -e "${RED}======================================================="
echo -e "FAILED gitignore recursive filter"
echo -e "=================================================${NC}"
exit
else
echo -e "${GREEN}PASSED gitignore recursive filter"
fi
if ./scc "examples/language/" --include-ext go | grep -q "Java "; then
echo -e "${RED}======================================================="
echo -e "FAILED include-ext option"
echo -e "=======================================================${NC}"
exit
else
echo -e "${GREEN}PASSED include-ext option"
fi
# Try out specific languages
for i in 'Bosque ' 'Flow9 ' 'Bitbucket Pipeline ' 'Docker ignore ' 'Q# ' 'Futhark ' 'Alloy ' 'Wren ' 'Monkey C ' 'Alchemist ' 'Luna ' 'ignore ' 'XML Schema ' 'Web Services' 'Go ' 'Java '
do
if ./scc "examples/language/" | grep -q "$i "; then
echo -e "${GREEN}PASSED $i Language Check"
else
echo -e "${RED}======================================================="
echo -e "FAILED Should be able to find $i"
echo -e "=======================================================${NC}"
exit
fi
done
echo -e "${NC}Cleaning up..."
rm ./scc
rm ./ignored.xml
rm .tmp_scc_yaml
rm ./examples/ignore/gitignorefile.txt
rm ./examples/ignore/ignorefile.txt
echo -e "${GREEN}================================================="
echo -e "ALL TESTS PASSED"
echo -e "=================================================${NC}"