Skip to content

Commit

Permalink
Return a non-zero exit code if there are any stylesheet compilation e…
Browse files Browse the repository at this point in the history
…rrors. Closes CompassGH-432.
  • Loading branch information
chriseppstein committed Jul 3, 2011
1 parent 23d3d34 commit b8b6af9
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 4 deletions.
9 changes: 9 additions & 0 deletions features/command_line.feature
Expand Up @@ -63,6 +63,15 @@ Feature: Command Line
And I am told that I can place stylesheets in the sass subdirectory
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
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.
Expand Down
7 changes: 7 additions & 0 deletions features/step_definitions/command_line_steps.rb
Expand Up @@ -53,6 +53,13 @@
@cleanup_directories << directory
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 /^I create a project using: compass create ([^\s]+) ?(.+)?$/ do |dir, args|
@cleanup_directories << dir
Expand Down
8 changes: 8 additions & 0 deletions lib/compass/commands/base.rb
Expand Up @@ -22,6 +22,14 @@ def perform
raise StandardError.new("Not Implemented")
end

def successful?
!@failed
end

def failed!
@failed = true
end

protected

def framework
Expand Down
3 changes: 2 additions & 1 deletion lib/compass/commands/update_project.rb
Expand Up @@ -34,7 +34,8 @@ def perform
compiler = new_compiler_instance
check_for_sass_files!(compiler)
compiler.clean! if compiler.new_config?
compiler.run
error_count = compiler.run
failed! if error_count > 0
end

def check_for_sass_files!(compiler)
Expand Down
3 changes: 3 additions & 0 deletions lib/compass/compiler.rb
Expand Up @@ -82,6 +82,7 @@ def clean!
end

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

def compile_if_required(sass_filename, css_filename)
Expand Down
7 changes: 4 additions & 3 deletions lib/compass/exec/sub_command_ui.rb
Expand Up @@ -12,8 +12,7 @@ def initialize(args)

def run!
begin
perform!
return 0
return perform!
rescue Exception => e
raise e if e.is_a? SystemExit
if e.is_a?(::Compass::Error) || e.is_a?(OptionParser::ParseError)
Expand All @@ -40,7 +39,9 @@ def perform!
else
command_class.parse!(args)
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
puts "Error: #{e.message}"
puts command_class.usage if command_class.respond_to?(:usage)
Expand Down

0 comments on commit b8b6af9

Please sign in to comment.