@@ -42,10 +42,12 @@ class TestRunnerContext:
42
42
script_name : str
43
43
docker_pull : str
44
44
docker_run_test : str
45
+ script_type : str
45
46
script_relative_path : str
46
47
script_name_with_file_type : str
47
48
script_output_file_path : str
48
49
script_output_file_name : str
50
+ input_file_path : str
49
51
prepared_file_path : str
50
52
snippet_start_line : int
51
53
snippet_end_line : int
@@ -73,23 +75,31 @@ def __init__(self, language) -> None:
73
75
# generate the contexts
74
76
self .ctxs = []
75
77
for script_path in glob .glob (f"{ self .base_directory } /src/{ language } /*" ):
78
+ # given "src/python/sort_builtin.py" => return "sort"
79
+ script_type = script_path .split ("/" )[- 1 ].split ("_" )[0 ]
80
+
76
81
# ignore helpers, metadata files, etc
77
82
if config .get ("ignoreFiles" ) and script_path .split ("/" )[- 1 ] in config .get (
78
83
"ignoreFiles"
79
84
):
80
85
continue
86
+
81
87
# ignore directories, generally compiled code
82
88
if not os .path .isfile (script_path ):
83
89
continue
84
- # generate a context for this particular script
85
- if ctx := self .generate (language , config , script_path ):
86
- self .ctxs .append (ctx )
90
+
91
+ for input_file_path in glob .glob (
92
+ f"{ self .data_folder_path } /{ script_type } _input_*.txt"
93
+ ):
94
+ # generate a context for this particular script
95
+ if ctx := self .generate (language , config , script_path , input_file_path ):
96
+ self .ctxs .append (ctx )
87
97
88
98
@property
89
99
def data (self ):
90
100
return [ctx .data for ctx in self .ctxs ]
91
101
92
- def generate (self , language , config , script_path ):
102
+ def generate (self , language , config , script_path , input_file_path ):
93
103
# given "src/python/sort_builtin.py" => split on "/" and return "sort_builtin.py"
94
104
script_path_split_on_slash = script_path .split ("/" )
95
105
script_name_with_file_type = script_path_split_on_slash [- 1 ]
@@ -106,11 +116,14 @@ def generate(self, language, config, script_path):
106
116
107
117
# get the path of the file that's been prepared in advance
108
118
# and has the output we would be expecting from out script
109
- prepared_file_path = f"{ self .data_folder_path } /{ script_type } _output.txt"
119
+ prepared_file_path = input_file_path .replace ("input" , "output" )
120
+
121
+ # given "data/sort_input_1.txt" => return "1"
122
+ prepared_file_index = prepared_file_path .split ("_" )[- 1 ].split ("." )[0 ]
110
123
111
124
# our scripts write their output files to this path
112
125
script_output_file_name = (
113
- f"output_{ script_type } _via_ { language } _{ script_name } .txt"
126
+ f"output_{ language } _{ script_name } _ { prepared_file_index } .txt"
114
127
)
115
128
script_output_file_path = f"{ self .data_folder_path } /{ script_output_file_name } "
116
129
@@ -142,7 +155,7 @@ def generate(self, language, config, script_path):
142
155
143
156
# construct ending call args
144
157
docker_run_test_list += [
145
- f"-e=INPUT_PATH={ self . data_folder_path } / { script_type } _input.txt " ,
158
+ f"-e=INPUT_PATH={ input_file_path } " ,
146
159
f"-e=OUTPUT_PATH={ script_output_file_path } " ,
147
160
config ["dockerImage" ],
148
161
* script_invoker ,
@@ -170,14 +183,14 @@ def generate(self, language, config, script_path):
170
183
if snippet_start_line != 0 :
171
184
raise Exception (
172
185
f'Found multiple "{ self .snippet_start_text } " lines in { script_relative_path } .\n '
173
- f"The text with found on lines { snippet_start_line - snippet_start_line_offset + 1 } and { idx + 1 } ."
186
+ f"The lines were { snippet_start_line - snippet_start_line_offset + 1 } and { idx + 1 } ."
174
187
)
175
188
snippet_start_line = idx + 3
176
189
if self .snippet_end_text in line :
177
190
if snippet_end_line != 0 :
178
191
raise Exception (
179
192
f'Found multiple "{ self .snippet_end_text } " lines in { script_relative_path } .\n '
180
- f"The text with found on lines { snippet_end_line + snippet_end_line_offset + 1 } and { idx + 1 } ."
193
+ f"The lines were { snippet_end_line + snippet_end_line_offset + 1 } and { idx + 1 } ."
181
194
)
182
195
snippet_end_line = idx - snippet_end_line_offset
183
196
if snippet_start_line == 0 :
@@ -195,10 +208,12 @@ def generate(self, language, config, script_path):
195
208
script_name = script_name ,
196
209
docker_pull = docker_pull ,
197
210
docker_run_test = docker_run_test ,
211
+ script_type = script_type ,
198
212
script_relative_path = script_relative_path ,
199
213
script_name_with_file_type = script_name_with_file_type ,
200
214
script_output_file_path = script_output_file_path ,
201
215
script_output_file_name = script_output_file_name ,
216
+ input_file_path = input_file_path ,
202
217
prepared_file_path = prepared_file_path ,
203
218
snippet_start_line = snippet_start_line ,
204
219
snippet_end_line = snippet_end_line ,
@@ -244,19 +259,24 @@ def run_tests(self, input_script):
244
259
# report timing
245
260
# we round the number so humans dont over-index on small differences
246
261
print (
247
- f'\t ⏱ script "{ ctx .script_relative_path } " run for { round (end_time - start_time , 2 )} seconds'
262
+ f"\t ⏱ { ctx .script_relative_path } on { ctx .input_file_path } "
263
+ f"ran for { round (end_time - start_time , 2 )} seconds"
248
264
)
249
265
250
266
# check if the script invoke failed
251
267
if output .exited != 0 :
252
268
self .set_success_status (False )
253
- print (f'\t 🔴 script "{ ctx .script_relative_path } " failed, reason:' )
269
+ print (
270
+ f"\t 🔴 { ctx .script_relative_path } on { ctx .input_file_path } failed, reason:"
271
+ )
254
272
print (f'\t \t the exit code "{ output .exited } " was not 0' )
255
273
256
274
# check if the output file was created
257
275
if not os .path .exists (ctx .script_output_file_path ):
258
276
self .set_success_status (False )
259
- print (f'\t 🔴 script "{ ctx .script_relative_path } " failed, reason:' )
277
+ print (
278
+ f"\t 🔴 { ctx .script_relative_path } on { ctx .input_file_path } failed, reason:"
279
+ )
260
280
print (
261
281
f"\t \t the output { ctx .script_output_file_name } file was not created"
262
282
)
@@ -266,14 +286,18 @@ def run_tests(self, input_script):
266
286
ctx .prepared_file_path , ctx .script_output_file_path
267
287
):
268
288
self .set_success_status (True )
269
- print (f'\t 🟢 script "{ ctx .script_relative_path } " succeeded' )
289
+ print (
290
+ f"\t 🟢 { ctx .script_relative_path } on { ctx .input_file_path } succeeded"
291
+ )
270
292
271
293
# check if the output file does not match the prepared file
272
294
if os .path .exists (ctx .script_output_file_path ) and not filecmp .cmp (
273
295
ctx .prepared_file_path , ctx .script_output_file_path
274
296
):
275
297
self .set_success_status (False )
276
- print (f'\t 🔴 script "{ ctx .script_relative_path } " failed, reason:' )
298
+ print (
299
+ f"\t 🔴 { ctx .script_relative_path } on { ctx .input_file_path } failed, reason:"
300
+ )
277
301
print (
278
302
f"\t \t output file { ctx .script_output_file_name } has does not match the prepared file"
279
303
)
@@ -370,4 +394,4 @@ def test(ctx: invoke.Context, language, input_script):
370
394
371
395
@invoke .task
372
396
def clean (ctx : invoke .Context ):
373
- ctx .run ("git clean -fdx ./data/*" )
397
+ ctx .run ("git clean -fdx ./data/output_ *" )
0 commit comments