-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcheck_samples_in_README.awk
70 lines (66 loc) · 1.69 KB
/
check_samples_in_README.awk
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
/^```/ {
if (InSample = !InSample) { # open
Sample = ""
} else { # closed
checkSample()
}
next
}
InSample {
if (!skipLine()) {
fixLine()
Sample = Sample $0 "\n"
}
next
}
function skipLine() {
return /makesure won't accept/
}
function fixLine() {
sub(/\[ @private \]/,"@private")
sub(/\[ goal_name \]/,"goal_name")
sub(/\[ lib_name \]/,"lib_name")
sub("<glob pattern>","'*.*'")
sub("<condition>","true")
sub(/\[ goal2 \[ goal3.+]/,"goal2 goal3\n")
}
function checkSample( tmp,out) {
# print "\n-------- checking: " Sample
if (isMakesureSample()) {
Samples++
fixSample()
# print "\n------- Makesurefile: " Sample
print Sample > (tmp = "/tmp/makesuresample1.txt")
close(tmp)
if (system("./makesure_dev -f " tmp " -l >" (out="/tmp/makesuresample1_out.txt") " 2>&1") > 0 && !isExpectedError(out)) {
ErrorsCnt++
print "\n===== PROBLEM WITH SAMPLE:"
print Sample
print "----- ERROR: "
system("cat " out)
}
}
}
function isExpectedError(out, s,l) {
(s = ("cat " out)) | getline l
close(s)
return l == "There is a loop in goal dependencies via a -> c"
}
function fixSample() {
if (Sample ~ /@reached_if/) {
Sample = "@goal g\n" Sample
} else if (Sample ~ /@depends_on goal_name @args/) {
Sample = "@goal goal_name @params A B C\n" Sample
} else if (Sample ~ /@depends_on goal1 goal2 goal3/) {
Sample = "@goal goal1\n@goal goal2\n@goal goal3\n@goal goal\n" Sample
}
}
function isMakesureSample() {
return Sample ~ /(^|\n)@[a-z]+/
}
BEGIN { system("touch '/tmp/file with spaces1.txt'") }
END {
print "\nTotal samples: " (+Samples)
print "Total errors : " (+ErrorsCnt)
exit ErrorsCnt > 0
}