Skip to content

Commit

Permalink
Merge branch 'generate'
Browse files Browse the repository at this point in the history
  • Loading branch information
saper committed Sep 23, 2015
2 parents d6eeca1 + 0508fea commit 27bb761
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
13 changes: 13 additions & 0 deletions lib/sass_spec/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def self.parse
options = {
engine_adapter: SassEngineAdapter.new("sass"),
spec_directory: "spec",
generate: [],
tap: false,
skip: false,
verbose: false,
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions lib/sass_spec/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,18 @@ 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)
cases.push SassSpec::TestCase.new(input.realpath(),
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
Expand Down
2 changes: 1 addition & 1 deletion lib/sass_spec/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion lib/sass_spec/test_case.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# 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
@status_path = status_file
@output_style = style
@clean_test = clean
@options = options
@generate = gen

# Probe filesystem once and cache the results
@should_fail = File.file?(@status_path)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 27bb761

Please # to comment.