Skip to content

Commit 24f34e7

Browse files
testlib: escape bashslash and name (#31)
* testlib: escape bashslash and name Without this change, tests with \ or with quoted letters in test names are not producing valid JSON. In bin/run.sh, we now extract everything before /* Unit tests */ and we have refactored the extraction of function calls. * feedback
1 parent 174e528 commit 24f34e7

33 files changed

Lines changed: 777 additions & 96 deletions

bin/run.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ syntax_check_slug() {
3232
return 1
3333
fi
3434
# Check that functions invoked in the test harness exist in the exercise file
35-
sed '/check/!d' ${slug}-check.rexx | sed -E "s/.*\s+'(.*)',,/\1/g" | sed -E 's/^(.*)\(.*/\1/g' | sed -E '/\(/d' | uniq > tmpfile
35+
sed -n "s/^\s\s*'\(.*\)',,.*$/\1/p" "${slug}-check.rexx" | sed -E 's/^(.*)\(.*/\1/g; /\(/d' | uniq > tmpfile
3636
while read func ; do
3737
if ! grep -q "${func}\s*:" ${slug}.rexx ; then
3838
message="Function ${func} does not exist in exercise file"
@@ -46,11 +46,11 @@ syntax_check_slug() {
4646
jq -n --arg message "${message}" '{version: 3, status: "error", message: $message}' > ${results_file}
4747
return 1
4848
fi
49-
# Extract test variables
50-
sed -n '/\/\* Test Variables \*\//,/\/\* Unit tests \*\//p' ${slug}-check.rexx > ${slug}-vars.rexx
49+
# Extract test preamble (options, variables, etc.)
50+
sed -n '1,/\/\* Unit tests \*\//p' "${slug}-check.rexx" | sed '/\/\* Unit tests \*\//d' > "${slug}-vars.rexx"
5151

5252
# Parse, extract, and execute each function call
53-
sed '/check/!d' ${slug}-check.rexx | sed -E "s/.*\s+'(.*)',,/\1/g" > tmpfile
53+
sed -n "s/^\s\s*'\(.*\)',,.*$/\1/p" "${slug}-check.rexx" > tmpfile
5454

5555
while read func_call ; do
5656
test_number=$(( test_number += 1 ))

tests/all-fail/expected_results.json

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,207 +8,207 @@
88
"status": "fail",
99
"message": "Expected Whatever. but got Whatever.",
1010
"output": "",
11-
"test_code": "Hey(\"Tom-ay-to, tom-aaaah-to.\") \= 'Whatever.'",
11+
"test_code": "Hey(\"Tom-ay-to, tom-aaaah-to.\") \\= 'Whatever.'",
1212
"task_id": 1
1313
},
1414
{
1515
"name": "shouting",
1616
"status": "fail",
1717
"message": "Expected Whoa, chill out! but got Whoa, chill out!",
1818
"output": "",
19-
"test_code": "Hey(\"WATCH OUT!\") \= 'Whoa, chill out!'",
19+
"test_code": "Hey(\"WATCH OUT!\") \\= 'Whoa, chill out!'",
2020
"task_id": 1
2121
},
2222
{
2323
"name": "shouting gibberish",
2424
"status": "fail",
2525
"message": "Expected Whoa, chill out! but got Whoa, chill out!",
2626
"output": "",
27-
"test_code": "Hey(\"FCECDFCAAB\") \= 'Whoa, chill out!'",
27+
"test_code": "Hey(\"FCECDFCAAB\") \\= 'Whoa, chill out!'",
2828
"task_id": 1
2929
},
3030
{
3131
"name": "asking a question",
3232
"status": "fail",
3333
"message": "Expected Sure. but got Sure.",
3434
"output": "",
35-
"test_code": "Hey(\"Does this cryogenic chamber make me look fat?\") \= 'Sure.'",
35+
"test_code": "Hey(\"Does this cryogenic chamber make me look fat?\") \\= 'Sure.'",
3636
"task_id": 1
3737
},
3838
{
3939
"name": "asking a numeric question",
4040
"status": "fail",
4141
"message": "Expected Sure. but got Sure.",
4242
"output": "",
43-
"test_code": "Hey(\"You are, what, like 15?\") \= 'Sure.'",
43+
"test_code": "Hey(\"You are, what, like 15?\") \\= 'Sure.'",
4444
"task_id": 1
4545
},
4646
{
4747
"name": "asking gibberish",
4848
"status": "fail",
4949
"message": "Expected Sure. but got Sure.",
5050
"output": "",
51-
"test_code": "Hey(\"fffbbcbeab?\") \= 'Sure.'",
51+
"test_code": "Hey(\"fffbbcbeab?\") \\= 'Sure.'",
5252
"task_id": 1
5353
},
5454
{
5555
"name": "talking forcefully",
5656
"status": "fail",
5757
"message": "Expected Whatever. but got Whatever.",
5858
"output": "",
59-
"test_code": "Hey(\"Hi there!\") \= 'Whatever.'",
59+
"test_code": "Hey(\"Hi there!\") \\= 'Whatever.'",
6060
"task_id": 1
6161
},
6262
{
6363
"name": "using acronyms in regular speech",
6464
"status": "fail",
6565
"message": "Expected Whatever. but got Whatever.",
6666
"output": "",
67-
"test_code": "Hey(\"ItS OK IF YOU DONt want to go work for NASA.\") \= 'Whatever.'",
67+
"test_code": "Hey(\"ItS OK IF YOU DONt want to go work for NASA.\") \\= 'Whatever.'",
6868
"task_id": 1
6969
},
7070
{
7171
"name": "forceful question",
7272
"status": "fail",
7373
"message": "Expected Calm down, I know what I'm doing! but got Calm down, I know what I'm doing!",
7474
"output": "",
75-
"test_code": "Hey(\"WHAT'S GOING ON?\") \= 'Calm down, I know what I'm doing!'",
75+
"test_code": "Hey(\"WHAT'S GOING ON?\") \\= 'Calm down, I know what I'm doing!'",
7676
"task_id": 1
7777
},
7878
{
7979
"name": "shouting numbers",
8080
"status": "fail",
8181
"message": "Expected Whoa, chill out! but got Whoa, chill out!",
8282
"output": "",
83-
"test_code": "Hey(\"1, 2, 3 GO!\") \= 'Whoa, chill out!'",
83+
"test_code": "Hey(\"1, 2, 3 GO!\") \\= 'Whoa, chill out!'",
8484
"task_id": 1
8585
},
8686
{
8787
"name": "no letters",
8888
"status": "fail",
8989
"message": "Expected Whatever. but got Whatever.",
9090
"output": "",
91-
"test_code": "Hey(\"1, 2, 3\") \= 'Whatever.'",
91+
"test_code": "Hey(\"1, 2, 3\") \\= 'Whatever.'",
9292
"task_id": 1
9393
},
9494
{
9595
"name": "question with no letters",
9696
"status": "fail",
9797
"message": "Expected Sure. but got Sure.",
9898
"output": "",
99-
"test_code": "Hey(\"4?\") \= 'Sure.'",
99+
"test_code": "Hey(\"4?\") \\= 'Sure.'",
100100
"task_id": 1
101101
},
102102
{
103103
"name": "shouting with special characters",
104104
"status": "fail",
105105
"message": "Expected Whoa, chill out! but got Whoa, chill out!",
106106
"output": "",
107-
"test_code": "Hey(\"ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!\") \= 'Whoa, chill out!'",
107+
"test_code": "Hey(\"ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!\") \\= 'Whoa, chill out!'",
108108
"task_id": 1
109109
},
110110
{
111111
"name": "shouting with no exclamation mark",
112112
"status": "fail",
113113
"message": "Expected Whoa, chill out! but got Whoa, chill out!",
114114
"output": "",
115-
"test_code": "Hey(\"I HATE THE DENTIST\") \= 'Whoa, chill out!'",
115+
"test_code": "Hey(\"I HATE THE DENTIST\") \\= 'Whoa, chill out!'",
116116
"task_id": 1
117117
},
118118
{
119119
"name": "statement containing question mark",
120120
"status": "fail",
121121
"message": "Expected Whatever. but got Whatever.",
122122
"output": "",
123-
"test_code": "Hey(\"Ending with ? means a question.\") \= 'Whatever.'",
123+
"test_code": "Hey(\"Ending with ? means a question.\") \\= 'Whatever.'",
124124
"task_id": 1
125125
},
126126
{
127127
"name": "non-letters with question",
128128
"status": "fail",
129129
"message": "Expected Sure. but got Sure.",
130130
"output": "",
131-
"test_code": "Hey(\":) ?\") \= 'Sure.'",
131+
"test_code": "Hey(\":) ?\") \\= 'Sure.'",
132132
"task_id": 1
133133
},
134134
{
135135
"name": "prattling on",
136136
"status": "fail",
137137
"message": "Expected Sure. but got Sure.",
138138
"output": "",
139-
"test_code": "Hey(\"Wait! Hang on. Are you going to be OK?\") \= 'Sure.'",
139+
"test_code": "Hey(\"Wait! Hang on. Are you going to be OK?\") \\= 'Sure.'",
140140
"task_id": 1
141141
},
142142
{
143143
"name": "silence",
144144
"status": "fail",
145145
"message": "Expected Fine. Be that way! but got Fine. Be that way!",
146146
"output": "",
147-
"test_code": "Hey(\"\") \= 'Fine. Be that way!'",
147+
"test_code": "Hey(\"\") \\= 'Fine. Be that way!'",
148148
"task_id": 1
149149
},
150150
{
151151
"name": "prolonged silence",
152152
"status": "fail",
153153
"message": "Expected Fine. Be that way! but got Fine. Be that way!",
154154
"output": "",
155-
"test_code": "Hey(\" \") \= 'Fine. Be that way!'",
155+
"test_code": "Hey(\" \") \\= 'Fine. Be that way!'",
156156
"task_id": 1
157157
},
158158
{
159159
"name": "alternate silence",
160160
"status": "fail",
161161
"message": "Expected Fine. Be that way! but got Fine. Be that way!",
162162
"output": "",
163-
"test_code": "Hey(COPIES(\"09\"X, 10)) \= 'Fine. Be that way!'",
163+
"test_code": "Hey(COPIES(\"09\"X, 10)) \\= 'Fine. Be that way!'",
164164
"task_id": 1
165165
},
166166
{
167167
"name": "multiple line question",
168168
"status": "fail",
169169
"message": "Expected Whatever. but got Whatever.",
170170
"output": "",
171-
"test_code": "Hey(\"0A\"X||\"Does this cryogenic chamber make me look fat?\"||\"0A\"X||\"No\") \= 'Whatever.'",
171+
"test_code": "Hey(\"0A\"X||\"Does this cryogenic chamber make me look fat?\"||\"0A\"X||\"No\") \\= 'Whatever.'",
172172
"task_id": 1
173173
},
174174
{
175175
"name": "starting with whitespace",
176176
"status": "fail",
177177
"message": "Expected Whatever. but got Whatever.",
178178
"output": "",
179-
"test_code": "Hey(\" hmmmmmmm...\") \= 'Whatever.'",
179+
"test_code": "Hey(\" hmmmmmmm...\") \\= 'Whatever.'",
180180
"task_id": 1
181181
},
182182
{
183183
"name": "ending with whitespace",
184184
"status": "fail",
185185
"message": "Expected Sure. but got Sure.",
186186
"output": "",
187-
"test_code": "Hey(\"Okay if like my spacebar quite a bit? \") \= 'Sure.'",
187+
"test_code": "Hey(\"Okay if like my spacebar quite a bit? \") \\= 'Sure.'",
188188
"task_id": 1
189189
},
190190
{
191191
"name": "other whitespace",
192192
"status": "fail",
193193
"message": "Expected Fine. Be that way! but got Fine. Be that way!",
194194
"output": "",
195-
"test_code": "Hey(\"0A\"X||\"0D\"X||\" \"||\"09\"X) \= 'Fine. Be that way!'",
195+
"test_code": "Hey(\"0A\"X||\"0D\"X||\" \"||\"09\"X) \\= 'Fine. Be that way!'",
196196
"task_id": 1
197197
},
198198
{
199199
"name": "non-question ending with whitespace",
200200
"status": "fail",
201201
"message": "Expected Whatever. but got Whatever.",
202202
"output": "",
203-
"test_code": "Hey(\"This is a statement ending with whitespace \") \= 'Whatever.'",
203+
"test_code": "Hey(\"This is a statement ending with whitespace \") \\= 'Whatever.'",
204204
"task_id": 1
205205
},
206206
{
207207
"name": "no input is silence",
208208
"status": "fail",
209209
"message": "Expected Fine. Be that way! but got Fine. Be that way!",
210210
"output": "",
211-
"test_code": "Hey() \= 'Fine. Be that way!'",
211+
"test_code": "Hey() \\= 'Fine. Be that way!'",
212212
"task_id": 1
213213
}
214214
]

0 commit comments

Comments
 (0)