diff --git a/lib/sass_spec/cli.rb b/lib/sass_spec/cli.rb index d861e9f7bb..02f7c8aca8 100644 --- a/lib/sass_spec/cli.rb +++ b/lib/sass_spec/cli.rb @@ -7,6 +7,7 @@ def self.parse options = { engine_adapter: SassEngineAdapter.new("sass"), spec_directory: "spec", + generate: [], tap: false, skip: false, verbose: false, @@ -56,6 +57,18 @@ def self.parse options[:engine_adapter] = ExecutableEngineAdapater.new(v) end + opts.on("-g", "--generate format", "Run test and generate output files for the specified format or \"all\"") do |v| + if v == "all" + options[:generate].replace(options[:output_styles]) + else + if options[:output_styles].include?(v) + options[:generate] << v + else + raise "--generate needs a valid output format #{options[:output_styles]} or \"all\"" + end + end + end + opts.on("--ignore-todo", "Skip any folder named 'todo'") do options[:skip_todo] = true end diff --git a/lib/sass_spec/runner.rb b/lib/sass_spec/runner.rb index ba3eeee47b..9e01464434 100644 --- a/lib/sass_spec/runner.rb +++ b/lib/sass_spec/runner.rb @@ -46,7 +46,8 @@ def _get_cases output_file_name = @options["#{output_style}_output_file".to_sym] expected_stdout_file_path = File.join(folder, output_file_name + ".css") clean_file_name = File.join(folder, output_file_name + ".clean") - if ( File.file?(expected_stdout_file_path) ) && + if ( File.file?(expected_stdout_file_path) || + @options[:generate].include?(output_style) ) && !File.file?(expected_stdout_file_path.sub(/\.css$/, ".skip")) && filename.include?(@options[:filter]) clean = File.file?(clean_file_name) @@ -54,7 +55,9 @@ def _get_cases expected_stdout_file_path, expected_stderr_file_path, expected_status_file_path, - output_style, clean, @options) + output_style, clean, + @options[:generate].include?(output_style), + @options) end end end diff --git a/lib/sass_spec/test.rb b/lib/sass_spec/test.rb index 2e17ef69f8..c281e71d08 100644 --- a/lib/sass_spec/test.rb +++ b/lib/sass_spec/test.rb @@ -9,7 +9,7 @@ def run_spec_test(test_case, options = {}) output, clean_output, error, status = test_case.output - if options[:nuke] + if test_case.overwrite? if status != 0 File.open(test_case.status_path, "w+") do |f| f.write(status) diff --git a/lib/sass_spec/test_case.rb b/lib/sass_spec/test_case.rb index 71418d0083..76e81ba856 100644 --- a/lib/sass_spec/test_case.rb +++ b/lib/sass_spec/test_case.rb @@ -1,6 +1,6 @@ # This represents a specific test case. class SassSpec::TestCase - def initialize(input_scss, expected_css, error_file, status_file, style, clean, options = {}) + def initialize(input_scss, expected_css, error_file, status_file, style, clean, gen, options = {}) @input_path = input_scss @expected_path = expected_css @error_path = error_file @@ -8,6 +8,7 @@ def initialize(input_scss, expected_css, error_file, status_file, style, clean, @output_style = style @clean_test = clean @options = options + @generate = gen # Probe filesystem once and cache the results @should_fail = File.file?(@status_path) @@ -54,6 +55,10 @@ def todo? @input_path.to_s.include? "todo" end + def overwrite? + @generate || @options[:nuke] + end + def output if @output return @output