Return a non-zero exit code if there are any stylesheet compilation errors. Closes GH-432.

This commit is contained in:
Chris Eppstein 2011-07-03 00:18:58 -07:00
parent 23d3d341de
commit b8b6af9d49
6 changed files with 33 additions and 4 deletions

View File

@ -63,6 +63,15 @@ Feature: Command Line
And I am told that I can place stylesheets in the sass subdirectory And I am told that I can place stylesheets in the sass subdirectory
And I am told how to compile my sass stylesheets And I am told how to compile my sass stylesheets
Scenario: Compiling a project with errors
Given I am using the existing project in test/fixtures/stylesheets/compass
And the project has a file named "sass/error.scss" containing:
"""
.broken {
"""
When I run: compass compile
Then the command exits with a non-zero error code
Scenario: Creating a bare project with a framework Scenario: Creating a bare project with a framework
When I create a project using: compass create bare_project --using blueprint --bare When I create a project using: compass create bare_project --using blueprint --bare
Then an error message is printed out: A bare project cannot be created when a framework is specified. Then an error message is printed out: A bare project cannot be created when a framework is specified.

View File

@ -53,6 +53,13 @@ Given /^I should clean up the directory: (\w+)$/ do |directory|
@cleanup_directories << directory @cleanup_directories << directory
end end
Given %r{^the project has a file named "([^"]*)" containing:$} do |arg1, string|
File.open(arg1, "w") do |f|
f << string
end
end
# When Actions are performed # When Actions are performed
When /^I create a project using: compass create ([^\s]+) ?(.+)?$/ do |dir, args| When /^I create a project using: compass create ([^\s]+) ?(.+)?$/ do |dir, args|
@cleanup_directories << dir @cleanup_directories << dir

View File

@ -22,6 +22,14 @@ module Compass
raise StandardError.new("Not Implemented") raise StandardError.new("Not Implemented")
end end
def successful?
!@failed
end
def failed!
@failed = true
end
protected protected
def framework def framework

View File

@ -34,7 +34,8 @@ module Compass
compiler = new_compiler_instance compiler = new_compiler_instance
check_for_sass_files!(compiler) check_for_sass_files!(compiler)
compiler.clean! if compiler.new_config? compiler.clean! if compiler.new_config?
compiler.run error_count = compiler.run
failed! if error_count > 0
end end
def check_for_sass_files!(compiler) def check_for_sass_files!(compiler)

View File

@ -82,6 +82,7 @@ module Compass
end end
def run def run
failure_count = 0
if new_config? if new_config?
# Wipe out the cache and force compilation if the configuration has changed. # Wipe out the cache and force compilation if the configuration has changed.
remove options[:cache_location] if options[:cache_location] remove options[:cache_location] if options[:cache_location]
@ -97,6 +98,7 @@ module Compass
begin begin
compile_if_required sass_filename, css_filename compile_if_required sass_filename, css_filename
rescue Sass::SyntaxError => e rescue Sass::SyntaxError => e
failure_count += 1
handle_exception(sass_filename, css_filename, e) handle_exception(sass_filename, css_filename, e)
end end
end end
@ -104,6 +106,7 @@ module Compass
if options[:time] if options[:time]
puts "Compilation took #{(result.__duration * 1000).round / 1000.0}s" puts "Compilation took #{(result.__duration * 1000).round / 1000.0}s"
end end
return failure_count
end end
def compile_if_required(sass_filename, css_filename) def compile_if_required(sass_filename, css_filename)

View File

@ -12,8 +12,7 @@ module Compass::Exec
def run! def run!
begin begin
perform! return perform!
return 0
rescue Exception => e rescue Exception => e
raise e if e.is_a? SystemExit raise e if e.is_a? SystemExit
if e.is_a?(::Compass::Error) || e.is_a?(OptionParser::ParseError) if e.is_a?(::Compass::Error) || e.is_a?(OptionParser::ParseError)
@ -40,7 +39,9 @@ module Compass::Exec
else else
command_class.parse!(args) command_class.parse!(args)
end end
command_class.new(Dir.getwd, @options).execute cmd = command_class.new(Dir.getwd, @options)
cmd.execute
cmd.successful? ? 0 : 1
rescue OptionParser::ParseError => e rescue OptionParser::ParseError => e
puts "Error: #{e.message}" puts "Error: #{e.message}"
puts command_class.usage if command_class.respond_to?(:usage) puts command_class.usage if command_class.respond_to?(:usage)