-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makesurefile
201 lines (164 loc) · 4.78 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
# vim: syntax=bash
@options timing
@define TUSH_REPO='https://github.com/adolfopa/tush'
@define GOAWK_VERSION='1.24.0'
@define GOAWK="goawk$GOAWK_VERSION"
@goal soft_folder_created @private
@reached_if [[ -d "soft" ]]
mkdir soft
@goal tush_installed @private
@depends_on soft_folder_created
@reached_if [[ -f "soft/tush/bin/tush-check" ]]
echo
echo "Fetching tush..."
echo
cd "soft"
if command -v wget >/dev/null
then
wget $TUSH_REPO/archive/master.tar.gz -O./tush.tar.gz
tar xzvf ./tush.tar.gz
rm ./tush.tar.gz
mv tush-master tush
elif command -v curl >/dev/null
then
curl -L $TUSH_REPO/archive/master.tar.gz -o ./tush.tar.gz
tar xzvf ./tush.tar.gz
rm ./tush.tar.gz
mv tush-master tush
else
git clone --depth 1 $TUSH_REPO.git
rm -r tush/.git
fi
@goal default
@depends_on tested
@goal tested
@depends_on tested_by_default_awk
@depends_on tested_by_bwk
@depends_on tested_by_gawk
@depends_on tested_by @args 'tush' 'mawk -f ./fhtagn.awk'
@depends_on tested_by @args 'fhtagn' 'mawk -f ./fhtagn.awk'
@depends_on tested_by_busybox_awk
@depends_on tested_by_goawk
@goal tested_by_bwk
@depends_on installed_bwk
@depends_on tested_by @args 'tush' './soft/bwk -f ./fhtagn.awk'
@depends_on tested_by @args 'fhtagn' './soft/bwk -f ./fhtagn.awk'
@goal tested_by_gawk
@depends_on tested_by @args 'tush' 'gawk -f ./fhtagn.awk'
@depends_on tested_by @args 'fhtagn' 'gawk -f ./fhtagn.awk'
@goal tested_by_default_awk
@depends_on tested_by @args 'tush' './fhtagn.awk'
@depends_on tested_by @args 'fhtagn' './fhtagn.awk'
@goal tested_by_busybox_awk
@depends_on installed_busybox
@depends_on tested_by @args 'tush' './soft/busybox awk -f ./fhtagn.awk'
@depends_on tested_by @args 'fhtagn' './soft/busybox awk -f ./fhtagn.awk'
@goal tested_by_goawk
@depends_on installed_goawk
@depends_on tested_by @args 'tush' './soft/goawk1.24.0 -f ./fhtagn.awk'
@depends_on tested_by @args 'fhtagn' './soft/goawk1.24.0 -f ./fhtagn.awk'
@goal tested_by @params TOOL FHTAGN
@depends_on tush_installed
f=tests/fhtagn.tush
echo "Testing with $TOOL ($FHTAGN)..."
export FHTAGN
calc_temp_files() {
local tmp_count=$(find /tmp -maxdepth 1 -type f -name 'fhtagn.*' | wc -l)
local cnt
(( cnt = tmp_count ))
if [[ -d "/dev/shm" ]]
then
local shm_count=$(find /dev/shm -maxdepth 1 -type f -name 'fhtagn.*' | wc -l)
(( cnt += shm_count ))
fi
echo $cnt
}
test_file() {
if [[ $TOOL == "tush" ]]
then
export PATH="$PATH:$MYDIR/soft/tush/bin"
DIFF="diff --strip-trailing-cr" tush-check "$f"
else
local before_count=$(calc_temp_files)
./fhtagn.awk "$f"
local after_count=$(calc_temp_files)
if (( before_count != after_count ))
then
echo >&2 "!!! temp file not deleted !!!"
exit 1
fi
fi
}
if test_file
then
echo "TESTS PASSED : $f"
else
echo >&2 "!!! TESTS FAILED !!! : $f"
exit 1
fi
@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_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)"
@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
@goal update_readme
@doc 'updates the README.md with the current output of the tool'
awk '
!Off
Examples {
if (/^\$/) { Off=1; system(substr($0,2)) }
else if (/^```$/ && Off) { Off=0; print }
}
/## Usage/ { Examples=1 }
' README.md > README.md.1
mv README.md.1 README.md
@define COVERPROFILE="/tmp/cov_fhtagn.txt"
@goal _cover_profile_deleted @private
rm -f "$COVERPROFILE"
@goal _cover_profile_prepared @private
@depends_on _cover_profile_deleted
@depends_on tested_by @args 'fhtagn' './soft/goawk1.24.0 -covermode=set -coverprofile=/tmp/cov_fhtagn.txt -coverappend -f ./fhtagn.awk'
@goal coverage
@doc 'prepares code coverage report'
@depends_on _cover_profile_prepared
go tool cover -html="$COVERPROFILE"