@@ -14,16 +14,14 @@ def run_spec_test(test_case, options = {})
14
14
assert File . exists? ( test_case . input_path ) ,
15
15
"Input #{ test_case . input_path } file does not exist"
16
16
17
- _output , _clean_output , error , status = test_case . output
18
-
19
17
if test_case . overwrite?
20
18
overwrite_test! ( test_case )
21
19
return
22
20
end
23
21
24
22
return unless handle_missing_output! ( test_case )
25
- return unless handle_unexpected_error! ( test_case , status , error , options )
26
- return unless handle_unexpected_pass! ( test_case , status , error , options )
23
+ return unless handle_unexpected_error! ( test_case , options )
24
+ return unless handle_unexpected_pass! ( test_case , options )
27
25
return unless handle_output_difference! ( test_case , options )
28
26
29
27
if test_case . warning_todo? && !options [ :run_todo ]
@@ -34,6 +32,8 @@ def run_spec_test(test_case, options = {})
34
32
end
35
33
end
36
34
35
+ # if the test case is interactive it will do the interaction and return
36
+ # the choice. Otherwise, it returns the default.
37
37
def interact ( test_case , default , &block )
38
38
if test_case . interactive?
39
39
return SassSpec ::Interactor . interact ( &block )
@@ -148,6 +148,11 @@ def handle_output_difference!(test_case, options)
148
148
149
149
return true if test_case . expected == clean_output
150
150
151
+ if test_case . migrate? && !test_case . interactive?
152
+ migrate_test! ( test_case , options )
153
+ return false
154
+ end
155
+
151
156
interact ( test_case , :fail ) do |i |
152
157
i . prompt "output does not match expectation"
153
158
@@ -231,96 +236,107 @@ def handle_missing_output!(test_case)
231
236
return true
232
237
end
233
238
234
- def handle_unexpected_pass! ( test_case , status , error , options )
235
- if test_case . should_fail?
236
- output , _ , error , status = test_case . output
237
- if status == 0 && test_case . interactive?
238
- choice = SassSpec ::Interactor . interact do |i |
239
- i . prompt "In #{ test_case . name } \n " +
240
- "A failure was expected but it compiled instead."
241
- i . choice ( :show_source , "Show me the input." ) do
242
- display_text_block ( File . read ( test_case . input_path ) )
243
- i . restart!
244
- end
239
+ def handle_unexpected_pass! ( test_case , options )
240
+ output , _clean_output , error , status = test_case . output
241
+ if status == 0
242
+ return true if !test_case . should_fail?
245
243
246
- i . choice ( :show_expected_error , "Show me the expected error." ) do
247
- display_text_block ( File . read ( test_case . error_path ) )
248
- i . restart!
249
- end
244
+ if test_case . migrate? && ! test_case . interactive?
245
+ migrate_test! ( test_case , options )
246
+ return false
247
+ end
250
248
251
- i . choice ( :show_output , "Show me the output." ) do
252
- display_text_block ( output )
253
- i . restart!
254
- end
249
+ choice = interact ( test_case , :fail ) do |i |
250
+ i . prompt "In #{ test_case . name } \n " +
251
+ "A failure was expected but it compiled instead."
252
+ i . choice ( :show_source , "Show me the input." ) do
253
+ display_text_block ( File . read ( test_case . input_path ) )
254
+ i . restart!
255
+ end
255
256
256
- i . choice ( :fix , "Update test and mark it passing." ) do
257
- overwrite_test! ( test_case )
258
- end
257
+ i . choice ( :show_expected_error , "Show me the expected error." ) do
258
+ display_text_block ( File . read ( test_case . error_path ) )
259
+ i . restart!
260
+ end
259
261
260
- i . choice ( :migrate , "Migrate copy of test to pass current version." ) do
261
- migrate_test! ( test_case , options ) || i . restart!
262
- end
262
+ i . choice ( :show_output , "Show me the output." ) do
263
+ display_text_block ( output )
264
+ i . restart!
265
+ end
263
266
264
- i . choice ( :fail , "Fail test and continue." )
267
+ i . choice ( :fix , "Update test and mark it passing." ) do
268
+ overwrite_test! ( test_case )
269
+ end
265
270
266
- i . choice ( :exit , "Exit testing." ) do
267
- raise Interrupt
268
- end
271
+ i . choice ( :migrate , "Migrate copy of test to pass current version." ) do
272
+ migrate_test! ( test_case , options ) || i . restart!
273
+ end
274
+
275
+ i . choice ( :fail , "Fail test and continue." )
276
+
277
+ i . choice ( :exit , "Exit testing." ) do
278
+ raise Interrupt
269
279
end
270
- return false unless choice == :fail
271
280
end
272
- # XXX Ruby returns 65 etc. SassC returns 1
273
- refute_equal status , 0 , "Test case should fail, but it did not"
281
+ return false unless choice == :fail
274
282
end
283
+ # XXX Ruby returns 65 etc. SassC returns 1
284
+ refute_equal status , 0 , "Test case should fail, but it did not"
275
285
return true
276
286
end
277
287
278
- def handle_unexpected_error! ( test_case , status , error , options )
279
- unless test_case . should_fail?
280
- _output , _clean_output , error , status = test_case . output
281
- if status != 0 && test_case . interactive?
282
- choice = SassSpec ::Interactor . interact do |i |
283
- i . prompt "In #{ test_case . name } \n " +
284
- "An unexpected compiler error was encountered."
285
- i . choice ( :show_source , "Show me the input." ) do
286
- display_text_block ( File . read ( test_case . input_path ) )
287
- i . restart!
288
- end
288
+ def handle_unexpected_error! ( test_case , options )
289
+ _output , _clean_output , error , status = test_case . output
290
+ if status != 0
291
+ return true if test_case . should_fail?
289
292
290
- i . choice ( :show_expected_error , "Show me the error." ) do
291
- display_text_block ( error )
292
- i . restart!
293
- end
293
+ if test_case . migrate? && ! test_case . interactive?
294
+ migrate_test! ( test_case , options )
295
+ return false
296
+ end
294
297
295
- i . choice ( :show_output , "Show me the expected output." ) do
296
- display_text_block ( test_case . expected )
297
- i . restart!
298
- end
298
+ choice = interact ( test_case , :fail ) do |i |
299
+ i . prompt "In #{ test_case . name } \n " +
300
+ "An unexpected compiler error was encountered."
301
+ i . choice ( :show_source , "Show me the input." ) do
302
+ display_text_block ( File . read ( test_case . input_path ) )
303
+ i . restart!
304
+ end
299
305
300
- i . choice ( :fix , "Update test to expect this failure." ) do
301
- overwrite_test! ( test_case )
302
- end
306
+ i . choice ( :show_expected_error , "Show me the error." ) do
307
+ display_text_block ( error )
308
+ i . restart!
309
+ end
303
310
304
- i . choice ( :migrate , "Migrate copy of test to pass current version." ) do
305
- migrate_test! ( test_case , options ) || i . restart!
306
- end
311
+ i . choice ( :show_output , "Show me the expected output." ) do
312
+ display_text_block ( test_case . expected )
313
+ i . restart!
314
+ end
307
315
308
- i . choice ( :fail , "Fail test and continue." )
316
+ i . choice ( :fix , "Update test to expect this failure." ) do
317
+ overwrite_test! ( test_case )
318
+ end
309
319
310
- i . choice ( :exit , "Exit testing." ) do
311
- raise Interrupt
312
- end
320
+ i . choice ( :migrate , "Migrate copy of test to pass current version." ) do
321
+ migrate_test! ( test_case , options ) || i . restart!
322
+ end
323
+
324
+ i . choice ( :fail , "Fail test and continue." )
325
+
326
+ i . choice ( :exit , "Exit testing." ) do
327
+ raise Interrupt
313
328
end
314
- return false unless choice == :fail
315
329
end
316
- assert_equal 0 , status , "Command ` #{ options [ :engine_adapter ] } ` did not complete: \n \n #{ error } "
330
+ return false unless choice == :fail
317
331
end
332
+ assert_equal 0 , status ,
333
+ "Command `#{ options [ :engine_adapter ] } ` did not complete:\n \n #{ error } "
318
334
return true
319
335
end
320
336
321
337
def delete_test! ( test_case )
322
338
files = Dir . glob ( File . join ( test_case . folder , "**" , "*" ) )
323
- result = SassSpec :: Interactor . interact do |i |
339
+ result = interact ( test_case , :proceed ) do |i |
324
340
i . prompt ( "The following files will be removed:\n * " + files . join ( "\n * " ) )
325
341
i . choice ( :proceed , "Delete them." ) do
326
342
FileUtils . rm_rf ( test_case . folder )
0 commit comments