-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathrun-all-parsers
executable file
·157 lines (129 loc) · 3.13 KB
/
run-all-parsers
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
#!/usr/bin/env bash
#------------------------------------------------------------------------------
#
# This program runs inside a Docker container that contains every known YAML
# parser that supports the parse event DSL output.
#
# It is used to run every test in the suite against each YAML parser.
#
#------------------------------------------------------------------------------
set -e -u -o pipefail
main() (
id=$ID
tmp=/tmp/test/$id
set -- $RUNNERS
run-all-parsers "$@"
write-tsv-line "$@"
)
run-all-parsers() (
cat > "$tmp-input.yaml"
for parser; do
(
timeout 5 \
"$parser" \
< "$tmp-input.yaml" \
> "$tmp-$parser.stdout" \
2> "$tmp-$parser.stderr" || (
echo $? > "$tmp-$parser.err"
)
) &
done
wait
)
write-tsv-line() (
refparser=$1
shift
if [[ -e $tmp-$refparser.err ]]; then
got_ref=''
else
got_ref=$(< "$tmp-$refparser.stdout")
fi
out=''
for parser; do
want=$got_ref
if [[ -e $tmp-$parser.err ]]; then
got=''
elif [[
-s $tmp-$parser.stderr &&
$(< "$tmp-$parser.stdout") != *-STR
]]; then
got=''
else
got=$(grep -v '=COMMENT' < "$tmp-$parser.stdout" || true)
fi
if [[ $parser == *-rustyaml ]]; then
got=$(adjust-got-for-rust <<<"$got")
want=$(adjust-want-for-rust <<<"$want")
fi
if [[ $parser == *-rapid ]]; then
got=$(adjust-got-for-rapid <<<"$got")
want=$(adjust-want-for-rapid <<<"$want")
fi
if [[ $parser == *-refhs ]]; then
[[ $got =~ (=ERR|=REST) ]] && got=''
if [[ $got && $want ]]; then
out+=$'\t'
elif [[ ! $got && ! $want ]]; then
out+=$'\t'
else
out+=$'\tx'
fi
else
[[ $got =~ $'\n'-STR$ ]] || got=''
if [[ $got == "$want" ]]; then
out+=$'\t'
else
got=${got//+MAP\ \{\}/+MAP}
got=${got//+SEQ\ \[\]/+SEQ}
want2=${want//+MAP\ \{\}/+MAP}
want2=${want2//+SEQ\ \[\]/+SEQ}
# Ignore Go parser bug:
got=${got//+DOC\ ---/+DOC}
want2=${want2//+DOC\ ---/+DOC}
if [[ $got == "$want2" ]]; then
out+=$'\t'
else
out+=$'\tx'
fi
fi
fi
done
printf '%s' "$out"
)
adjust-got-for-rust() {
perl -p0e '
s/<Tag\("!!",\ "(.*?)"\)>/<tag:yaml.org,2002:$1>/g;
s/<Tag\("!",\ "(.*?)"\)>/<!$1>/g;
s/<Tag\("",\ "!"\)>/<!>/g;
s/<Tag\("",\ "(tag:.*?)"\)>/<$1>/g;
s/<Tag\("",\ "(!.*?)"\)>/<$1>/g;
'
}
adjust-want-for-rust() {
perl -p0e '
s/^\+DOC ---$/+DOC/gm;
s/^-DOC \.\.\.$/-DOC/gm;
s/^=VAL :$/=VAL :~/gm;
s/^\+MAP\ \{\}(\ ?)/+MAP$1/gm;
s/^\+SEQ\ \[\](\ ?)/+SEQ$1/gm;
my ($c, %a) = (1);
s{^(\+MAP|\+SEQ|=VAL|=ALI) (&|\*)(\S+)(.*)}
{"$1 $2".($2 eq "&" ? ($a{$3} = $c++) : $a{$3}).$4}gem;
'
}
adjust-got-for-rapid() {
perl -p0e '
s/^\+DOC ---/+DOC/gm;
'
}
adjust-want-for-rapid() {
perl -p0e '
s/^=VAL ((?:&\S+ |<\S*> )*)[">|]/=VAL $1'"'"'/gm;
s/^\+DOC ---/+DOC/gm;
s/^-DOC \.\.\./-DOC/gm;
'
}
warn() ( echo "$*" >&2 )
die() ( echo "$*" >&2; exit 1 )
[[ -f /.dockerenv ]] || die "Not in docker"
main "$@"