-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakesurefile
408 lines (324 loc) · 9.67 KB
/
Makesurefile
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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
# vim: syntax=bash
@options timing
@define FHTAGN_VERSION 'v0.1.1'
@define FHTAGN_URL "https://github.com/xonixx/fhtagn/raw/$FHTAGN_VERSION/fhtagn.awk"
@define JSONTestSuite_REPO 'https://github.com/nst/JSONTestSuite'
@define GOAWK_VERSION '1.25.0'
@define GOAWK "goawk$GOAWK_VERSION"
@define AWK 'awk'
@goal soft_folder_created @private
@reached_if [[ -d "soft" ]]
mkdir soft
@define FHTAGN "soft/fhtagn.awk"
@goal fhtagn_installed @private
@depends_on soft_folder_created
@reached_if [[ -x "$FHTAGN" ]]
if command -v wget >/dev/null
then
wget "$FHTAGN_URL" -O"$FHTAGN"
elif command -v curl >/dev/null
then
curl -L "$FHTAGN_URL" -o "$FHTAGN"
else
echo "can't dl fhtagn"
exit 2
fi
chmod +x "$FHTAGN"
@goal JSONTestSuite_installed @private
@depends_on soft_folder_created
@reached_if [[ -d "soft/JSONTestSuite" ]]
echo
echo "Fetching JSONTestSuite..."
echo
cd "soft"
wget $JSONTestSuite_REPO/archive/master.tar.gz -O- \
| tar xzvf - JSONTestSuite-master/test_parsing JSONTestSuite-master/test_transform
mv JSONTestSuite-master JSONTestSuite
@goal test_suite_mawk134
@depends_on installed_mawk134
@depends_on test_suite @args './soft/mawk134'
@goal test_suite_bwk
@depends_on installed_bwk
@depends_on test_suite @args './soft/bwk'
#@goal test_suite_busybox
#@depends_on installed_busybox
#@depends_on test_suite @args './soft/busybox awk'
@goal test_suite_goawk
@depends_on installed_goawk
@depends_on test_suite @args "./soft/$GOAWK"
@goal test_suite @params AWK @private
@doc 'runs json suite'
@depends_on JSONTestSuite_installed
export AWK
./run_json_test_suit.awk
@goal cleaned_soft @private
@reached_if [[ ! -d "soft" ]]
rm -r "soft"
@goal cleaned @private
@depends_on cleaned_soft
@goal debug @private
case "$AWK" in
*busybox*) $AWK --help 2>&1 | head -n 1
;;
*mawk*) $AWK -W version 2>&1 | head -n 1
;;
*) $AWK --version | head -n 1
;;
esac
bash --version| head -n 1
@goal debug_pg @params AWK @private
printf '%s: ' "$AWK"
case "$AWK" in
*busybox*) $AWK --help 2>&1 | head -n 1
;;
*mawk*) $AWK -W version 2>&1 | head -n 1
;;
*) $AWK --version | head -n 1
;;
esac
@goal prepared4tests @private
@depends_on fhtagn_installed debug
@lib
run_test_file() {
local f="$1"
if "./$FHTAGN" "$f"
then
echo "TESTS PASSED : $f"
else
echo >&2 "!!! TESTS FAILED !!! : $f"
exit 1
fi
}
@goal @glob '*.tush' @params AWK @private
@depends_on fhtagn_installed
@depends_on debug_pg @args AWK
@use_lib
run_test_file "$ITEM"
@goal tested_json_suite
@doc 'tests json suite'
@depends_on prepared4tests
@depends_on JSONTestSuite_installed
@depends_on installed_mawk134
@use_lib
AWK="$(pwd)/soft/mawk134" run_test_file "run_json_test_suit.tush.txt"
@goal tested_json_suite_coverage @private
@doc 'tests json suite for coverage'
@depends_on prepared4tests
@depends_on JSONTestSuite_installed
@use_lib
run_test_file "run_json_test_suit_coverage.tush.txt"
@goal tested
@doc 'run tests'
@depends_on '*.tush' @args 'awk'
@define COVERPROFILE "/tmp/cov.txt"
@goal coverage
@doc 'run tests with coverage'
@depends_on _cover_profile_prepared
go tool cover -html="$COVERPROFILE"
@goal _cover_profile_deleted @private
rm -f "$COVERPROFILE"
@goal _cover_profile_prepared @private
@depends_on installed_goawk
@depends_on _cover_profile_deleted
./makesure tested tested_json_suite_coverage -D AWK="$(pwd)/soft/$GOAWK -covermode=set -coverappend -coverprofile=$COVERPROFILE"
@goal coverage_badge_updated
@doc 'updates code coverage badge'
@depends_on _cover_profile_prepared
html='/tmp/cov.html'
go tool cover -html="$COVERPROFILE" -o "$html"
coverage="$(awk '/gron\.awk/ { if (match($0,/\(.+\)/)) print substr($0,RSTART+1,RLENGTH-2) }' "$html")"
echo "coverage: $coverage"
awk -v coverage="$coverage" '{ gsub(/\$COVERAGE/,coverage) } 1' coverage.tpl.svg > coverage.svg
rm "$html"
@goal default
@doc 'same as tested'
@depends_on tested
@goal notrace @glob '*.awk'
awk '$1 !~ /^trace\(/' "$ITEM"
#-------------------------------
@goal tested_awks
@doc tests with all awks
@depends_on tested
@depends_on tested_bwk
@depends_on tested_mawk133
@depends_on tested_mawk134
@depends_on tested_gawk @args '5.3.0' 'gawk530'
@depends_on tested_goawk
#@depends_on tested_goawk_branch
@depends_on tested_busybox
@goal tested_bwk @private
@depends_on installed_bwk
@depends_on '*.tush' @args './soft/bwk'
@goal tested_mawk133 @private
@depends_on installed_mawk133
@depends_on '*.tush' @args './soft/mawk133'
@goal tested_mawk134 @private
@depends_on installed_mawk134
@depends_on '*.tush' @args './soft/mawk134'
@goal tested_gawk @params VERSION EXE_NAME @private
@depends_on installed_gawk @args VERSION EXE_NAME
@depends_on '*.tush' @args "./soft/$EXE_NAME" # TODO GRON_AWKLIBPATH
# ./makesure -D AWK="$(pwd)/soft/${EXE_NAME}" -D GRON_AWKLIBPATH="$(pwd)/soft/${EXE_NAME}_libs" tested
@goal tested_goawk @private
@depends_on installed_goawk
@depends_on '*.tush' @args "./soft/$GOAWK"
@goal tested_goawk_branch @private
@depends_on installed_goawk_branch
@depends_on '*.tush' @args "./soft/$GOAWK_BRANCH_EXE"
@goal tested_busybox @private
@reached_if [[ "$OSTYPE" != "linux-gnu"* ]] # only test busybox awk on linux
@depends_on installed_busybox
@depends_on '*.tush' @args "./soft/busybox awk"
@goal tested_jawk @private
@depends_on installed_jawk
@depends_on '*.tush' @args "java -jar ./soft/$JAWK_JAR"
#-------------------------------
@goal installed_awks
@doc 'installs all awks into ./soft'
@depends_on installed_bwk
@depends_on tested_gawk @args '5.2.2' 'gawk522'
@depends_on installed_mawk134
@depends_on installed_goawk
@goal installed_bwk @private
@reached_if [[ -f soft/bwk ]]
@depends_on soft_folder_created
echo
echo "Fetching BWK..."
echo
cd "soft"
wget https://github.com/onetrueawk/awk/archive/refs/heads/master.tar.gz -Obwk.tar.gz
tar xzvf bwk.tar.gz
rm bwk.tar.gz
echo
echo "Compile BWK..."
echo
cd "awk-master"
make
mv a.out ../bwk
cd ..
./bwk --version
rm -r awk-master
@goal installed_gawk @params VERSION EXE_NAME @private
@reached_if [[ -f soft/"$EXE_NAME" ]]
@depends_on soft_folder_created
echo
echo "Fetching Gawk-$VERSION..."
echo
cd "soft"
G=gawk-$VERSION.tar.gz
dlUrl="http://git.savannah.gnu.org/cgit/gawk.git/snapshot/$G"
dlFolder="gawk-$VERSION"
wget "$dlUrl"
tar "${tarOpts:-xzvf}" "$G"
rm "$G"
echo
echo "Compile Gawk-$VERSION..."
echo
cd "$dlFolder"
./configure
make
# make check
mv gawk ../$EXE_NAME
mkdir ../${EXE_NAME}_libs
mv extension/.libs/*.so ../"${EXE_NAME}"_libs # for AWKLIBPATH
cd ..
./$EXE_NAME --version
rm -r "$dlFolder"
@lib mawk
install_mawk() {
local version="$1"
local tgz="$2"
local exeName="mawk${version//./}"
echo
echo "Fetching Mawk $version..."
echo
cd "soft"
wget "https://invisible-island.net/archives/mawk/$tgz"
tar xzvf "$tgz"
rm "$tgz"
echo
echo "Compile Mawk $version..."
echo
cd mawk-"$version"-*
./configure && make
mv mawk ../$exeName
cd ..
./$exeName -W version
rm -r mawk-"$version"-*
}
@goal installed_mawk133 @private
@reached_if [[ -f soft/mawk133 ]]
@depends_on soft_folder_created
@use_lib mawk
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
install_mawk 1.3.3 'mawk-1.3.3-20080909.tgz' # this one doesn't compile on macos
elif [[ "$OSTYPE" == "darwin"* ]]; then
install_mawk 1.3.3 'mawk-1.3.3-20090920.tgz'
else
>&2 echo "Unknown OS"
exit 1
fi
@goal installed_mawk134 @private
@reached_if [[ -f soft/mawk134 ]]
@depends_on soft_folder_created
@use_lib mawk
install_mawk 1.3.4 'mawk-1.3.4-20200120.tgz'
@goal installed_busybox @private
@reached_if [[ -x ./soft/busybox ]]
wget 'https://busybox.net/downloads/binaries/1.31.0-i686-uclibc/busybox' -O ./soft/busybox
chmod +x ./soft/busybox
echo "Installed: $(./soft/busybox | head -n 1)"
@define JAWK_VER '3.1.00'
@define JAWK_JAR "jawk-$JAWK_VER-standalone.jar"
@goal installed_jawk @private
@reached_if [[ -e ./soft/"$JAWK_JAR" ]]
wget "https://github.com/sentrysoftware/Jawk/releases/download/v$JAWK_VER/$JAWK_JAR" -O ./soft/"$JAWK_JAR"
@goal installed_goawk @private
@reached_if [[ -f soft/$GOAWK ]]
@depends_on soft_folder_created
echo
echo "Fetching GoAWK $GOAWK_VERSION ..."
echo
cd "soft"
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
os="linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then
os="darwin"
else
>&2 echo "Unknown OS"
exit 1
fi
F=goawk_v${GOAWK_VERSION}_${os}_amd64.tar.gz
wget "https://github.com/benhoyt/goawk/releases/download/v$GOAWK_VERSION/$F"
tar xzvf "$F" goawk
rm "$F"
mv goawk $GOAWK
"./$GOAWK" --version
@define GOAWK_BRANCH 'bytecode'
@define GOAWK_BRANCH_EXE "goawk_$GOAWK_BRANCH"
@goal installed_goawk_branch @private
@reached_if [[ -f soft/$GOAWK_BRANCH_EXE ]]
@depends_on soft_folder_created
echo
echo "Installing GoAWK branch=$GOAWK_BRANCH ..."
echo
cd "soft"
zip="https://github.com/benhoyt/goawk/archive/refs/heads/$GOAWK_BRANCH.zip"
curl -L "$zip" -o "$GOAWK_BRANCH.zip"
yes | unzip "$GOAWK_BRANCH.zip"
cd "goawk-$GOAWK_BRANCH"
~/soft/go1.17/bin/go build # TODO go path
mv goawk ../"$GOAWK_BRANCH_EXE"
cd ..
./"$GOAWK_BRANCH_EXE" --version
rm -r "goawk-$GOAWK_BRANCH" "$GOAWK_BRANCH.zip"
@goal timeit
@depends_on installed_awks
for AWK in gawk51 mawk134 "$GOAWK -b" "$GOAWK_BRANCH_EXE -b" bwk
do
echo
echo "====================="
echo "Benchmarking $AWK ..."
# time ./soft/$AWK -f gron.awk test_data/big.json | ./soft/$AWK -f gron.awk - -u > /dev/null
time ./soft/$AWK -f gron.awk test_data/big.json | wc -l
done