Skip to content
This repository was archived by the owner on Feb 3, 2024. It is now read-only.

Commit 960b157

Browse files
committed
add getopt to makeTestdataAll and improve feedback during reduce
1 parent 35190b4 commit 960b157

File tree

3 files changed

+81
-27
lines changed

3 files changed

+81
-27
lines changed

DONE

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@ DONE
2222

2323
- simplefy com.tr regex from multiple . to \.+, and add note on the trailing dot behind the date
2424
add meta.com.tr to regular testdata
25+
26+
- fix test2.py cleanpostabmble for e.g com.sg which has lines at the top with ------------
27+
- add getops to makeTestDataAll.sh
28+
- allow maketestDataAll.sh -v -f -d com.sg to show the reduced input.out and the produced output of test2.py
29+
- add '[WHITESPACE AT END]' in input.out during input reduction test
30+

makeTestdataAll.sh

Lines changed: 70 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
TMPDIR="./tmp" # the default work directory is a local tmp (exclude by .gitignore )
44

5-
FORCE=0 # force whois loogup by not using cached data
6-
VERBOSE=0 # along the way inform us on progress and results
5+
FORCE=0 # force whois loogup by not using cached data
6+
VERBOSE=0 # along the way inform us on progress and results
7+
ALL=0 # process all supported tld's
78

89
prepTempDir()
910
{
10-
# make the work dir if it does nt exist
11+
# make the work dir if it does not exist
1112
mkdir -p "$TMPDIR" || {
1213
echo "FATAL: cannot make test dir: $TMPDIR" >&2
1314
exit 101
@@ -27,23 +28,27 @@ testNameserverExistsInInputAndOutput()
2728
local dns="$d/__dns-ns"
2829

2930
[ -s "$dns" ] || return # dont bother at all if we have no dns file
31+
[ -s "$d/input" ] || return # dont bother if we have no input file
3032

3133
rm -f "$d/error.ns"
3234

3335
cat "$dns" |
3436
awk '{ print $NF }' |
3537
while read ns
3638
do
37-
[ -s "$d/input" ] || return # dont bother if we have no input file
38-
39+
[ "$VERBOSE" = "1" ] && echo "test $ns in input"
3940
grep -q -i "$ns" "$d/input" && {
4041
# only test in the output if it is present in the input
42+
43+
[ "$VERBOSE" = "1" ] && echo "test $ns in output"
4144
grep -q -i "$ns" "$d/output" || {
4245
echo "ERROR: output; missing nameserver '$ns' for tld: $tld" |
4346
tee -a "$d/error.ns"
47+
return 1
4448
}
4549
}
4650
done
51+
return 0
4752
}
4853

4954
cleanupTldTestDirectory()
@@ -153,15 +158,10 @@ makeTestDataOriginalOneTldDomain()
153158

154159
getDnsSoaRecordAndLeaveEvidenceTldDomain "$tld" "$domain" || return 1
155160

156-
# what domain did we test
157-
touch "$d/__domain__$zz"
158-
159-
# store the nameservers from dns
160-
host -t ns "$zz" > "$d/__dns-ns__$zz"
161-
161+
touch "$d/__domain__$zz" # what domain did we test
162+
host -t ns "$zz" > "$d/__dns-ns__$zz" # store the nameservers from dns
162163
getTestDataInputForTldAndDomain "$tld" "$domain" || return 1
163-
164-
getTestDataOutputForTldAndDomain "$tld" "$domain"
164+
getTestDataOutputForTldAndDomain "$tld" "$domain" || return 1
165165
return 0
166166
}
167167

@@ -188,13 +188,24 @@ makeTestDataTldFromDomains()
188188
do
189189
[ "$VERBOSE" = "1" ] && echo "try: $domain.$tld"
190190

191-
makeTestDataOriginalOneTldDomain "$tld" "$domain"
192-
193-
[ -s "$TMPDIR/$tld/input" ] && {
194-
[ "$VERBOSE" = "1" ] && ls -l "$TMPDIR/$tld/"
195-
testNameserverExistsInInputAndOutput "$tld" && break
191+
makeTestDataOriginalOneTldDomain "$tld" "$domain" && {
192+
[ -s "$TMPDIR/$tld/input" ] && {
193+
[ "$VERBOSE" = "1" ] && {
194+
ls -l "$TMPDIR/$tld/"
195+
}
196+
}
197+
break
196198
}
197199
done
200+
201+
[ "$VERBOSE" = "1" ] && {
202+
# show the rediced input and the output
203+
cat "$TMPDIR/$tld/input.out" "$TMPDIR/$tld/output"
204+
}
205+
206+
testNameserverExistsInInputAndOutput "$tld" && {
207+
return
208+
}
198209
}
199210

200211
makeRulesFromTldIfExist()
@@ -227,19 +238,55 @@ makeTestDataOriginalAllTldSupported()
227238
done
228239
}
229240

241+
usage()
242+
{
243+
cat <<!
244+
$0 usage:
245+
-h show the help text
246+
-v switch on verbose (will show progress)
247+
-f switch on force (will re analyze all)
248+
-d <domain> specify a domain to analize if domain == ALL andlize all tld;s
249+
!
250+
exit 0;
251+
}
252+
230253
main()
231254
{
255+
[ $# -eq 0 ] && usage
256+
257+
VERBOSE=0
258+
FORCE=0
259+
ALL=0
260+
261+
while getopts "havfd:" arg;
262+
do
263+
case $arg in
264+
265+
v) VERBOSE=1
266+
;;
267+
268+
f) FORCE=1
269+
;;
270+
271+
a) ALL=1
272+
;;
273+
274+
d) domain=${OPTARG}
275+
;;
276+
277+
h | *) usage
278+
;;
279+
esac
280+
done
281+
232282
prepTempDir
233283

234-
[ "$#" = "0" ] && {
284+
[ "$ALL" = "1" ] && {
235285
makeTestDataOriginalAllTldSupported
236286
return
237287
}
238288

239-
for tld in $*
240-
do
241-
makeTestDataOriginalOneTld "$tld"
242-
done
289+
makeTestDataOriginalOneTld "$domain"
243290
}
244291

245292
main $* 2>&1 |

test2.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def cleanupWhoisResponse(
120120
percentSeen = True
121121

122122
if postambleSeen is False:
123-
if line.startswith("--") or line.startswith(">>> ") or line.startswith("Copyright notice"):
123+
if line.startswith("-- ") or line.startswith(">>> ") or line.startswith("Copyright notice"):
124124
postambleSeen = True
125125

126126
if postambleSeen is True:
@@ -155,9 +155,10 @@ def printMe(self):
155155
if len(self.rDict[k]):
156156
n = 0
157157
for lines in self.rDict[k]:
158-
tab = " [TAB] " if "\t" in lines else "-------" # tabs are present in this section
159-
cr = " [CR] " if "\r" in lines else "------" # \r is present in this section
160-
print(f"# ------------- {k} Section: {n} {cr}{tab}---------")
158+
ws = " [WHITESPACE AT END] " if re.search(r'[ \t]+\r?\n', lines) else ""
159+
tab = " [TAB] " if "\t" in lines else "" # tabs are present in this section
160+
cr = " [CR] " if "\r" in lines else "" # \r is present in this section
161+
print(f"# --- {k} Section: {n} {cr}{tab}{ws}")
161162
n += 1
162163
print(lines)
163164

0 commit comments

Comments
 (0)