Skip to content

Commit 41a137e

Browse files
committed
Migrate tests en-masse.
1 parent 3a1f4a9 commit 41a137e

File tree

3 files changed

+92
-68
lines changed

3 files changed

+92
-68
lines changed

lib/sass_spec/cli.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ def self.parse
102102
options[:nuke] = true
103103
end
104104

105+
opts.on("--migrate", "Copy tests that fail and make them pass for the current version.") do
106+
options[:migrate] = true
107+
end
108+
105109
opts.on("--silent", "Don't show any logs") do
106110
options[:silent] = true
107111
end

lib/sass_spec/test.rb

Lines changed: 84 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,14 @@ def run_spec_test(test_case, options = {})
1414
assert File.exists?(test_case.input_path),
1515
"Input #{test_case.input_path} file does not exist"
1616

17-
_output, _clean_output, error, status = test_case.output
18-
1917
if test_case.overwrite?
2018
overwrite_test!(test_case)
2119
return
2220
end
2321

2422
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)
2725
return unless handle_output_difference!(test_case, options)
2826

2927
if test_case.warning_todo? && !options[:run_todo]
@@ -34,6 +32,8 @@ def run_spec_test(test_case, options = {})
3432
end
3533
end
3634

35+
# if the test case is interactive it will do the interaction and return
36+
# the choice. Otherwise, it returns the default.
3737
def interact(test_case, default, &block)
3838
if test_case.interactive?
3939
return SassSpec::Interactor.interact(&block)
@@ -148,6 +148,11 @@ def handle_output_difference!(test_case, options)
148148

149149
return true if test_case.expected == clean_output
150150

151+
if test_case.migrate? && !test_case.interactive?
152+
migrate_test!(test_case, options)
153+
return false
154+
end
155+
151156
interact(test_case, :fail) do |i|
152157
i.prompt "output does not match expectation"
153158

@@ -231,96 +236,107 @@ def handle_missing_output!(test_case)
231236
return true
232237
end
233238

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?
245243

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
250248

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
255256

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
259261

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
263266

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
265270

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
269279
end
270-
return false unless choice == :fail
271280
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
274282
end
283+
# XXX Ruby returns 65 etc. SassC returns 1
284+
refute_equal status, 0, "Test case should fail, but it did not"
275285
return true
276286
end
277287

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?
289292

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
294297

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
299305

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
303310

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
307315

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
309319

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
313328
end
314-
return false unless choice == :fail
315329
end
316-
assert_equal 0, status, "Command `#{options[:engine_adapter]}` did not complete:\n\n#{error}"
330+
return false unless choice == :fail
317331
end
332+
assert_equal 0, status,
333+
"Command `#{options[:engine_adapter]}` did not complete:\n\n#{error}"
318334
return true
319335
end
320336

321337
def delete_test!(test_case)
322338
files = Dir.glob(File.join(test_case.folder, "**", "*"))
323-
result = SassSpec::Interactor.interact do |i|
339+
result = interact(test_case, :proceed) do |i|
324340
i.prompt("The following files will be removed:\n * " + files.join("\n * "))
325341
i.choice(:proceed, "Delete them.") do
326342
FileUtils.rm_rf(test_case.folder)

lib/sass_spec/test_case.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ def interactive?
7575
@options[:interactive]
7676
end
7777

78+
def migrate?
79+
@options[:migrate]
80+
end
81+
7882
def should_fail?
7983
@should_fail
8084
end

0 commit comments

Comments
 (0)