From b8b6af9d498cea6269be56fe77a8c1ee413af5d3 Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Sun, 3 Jul 2011 00:18:58 -0700 Subject: [PATCH] Return a non-zero exit code if there are any stylesheet compilation errors. Closes GH-432. --- features/command_line.feature | 9 +++++++++ features/step_definitions/command_line_steps.rb | 7 +++++++ lib/compass/commands/base.rb | 8 ++++++++ lib/compass/commands/update_project.rb | 3 ++- lib/compass/compiler.rb | 3 +++ lib/compass/exec/sub_command_ui.rb | 7 ++++--- 6 files changed, 33 insertions(+), 4 deletions(-) diff --git a/features/command_line.feature b/features/command_line.feature index 06e0060c..dd529977 100644 --- a/features/command_line.feature +++ b/features/command_line.feature @@ -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. diff --git a/features/step_definitions/command_line_steps.rb b/features/step_definitions/command_line_steps.rb index 5bddd7a7..fd45fdc9 100644 --- a/features/step_definitions/command_line_steps.rb +++ b/features/step_definitions/command_line_steps.rb @@ -53,6 +53,13 @@ Given /^I should clean up the directory: (\w+)$/ do |directory| @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 diff --git a/lib/compass/commands/base.rb b/lib/compass/commands/base.rb index 046fedb6..d0149752 100644 --- a/lib/compass/commands/base.rb +++ b/lib/compass/commands/base.rb @@ -22,6 +22,14 @@ module Compass raise StandardError.new("Not Implemented") end + def successful? + !@failed + end + + def failed! + @failed = true + end + protected def framework diff --git a/lib/compass/commands/update_project.rb b/lib/compass/commands/update_project.rb index 30e2654f..3edd6074 100644 --- a/lib/compass/commands/update_project.rb +++ b/lib/compass/commands/update_project.rb @@ -34,7 +34,8 @@ module Compass 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) diff --git a/lib/compass/compiler.rb b/lib/compass/compiler.rb index 76f59b89..19b26415 100644 --- a/lib/compass/compiler.rb +++ b/lib/compass/compiler.rb @@ -82,6 +82,7 @@ module Compass 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] @@ -97,6 +98,7 @@ module Compass begin compile_if_required sass_filename, css_filename rescue Sass::SyntaxError => e + failure_count += 1 handle_exception(sass_filename, css_filename, e) end end @@ -104,6 +106,7 @@ module Compass 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) diff --git a/lib/compass/exec/sub_command_ui.rb b/lib/compass/exec/sub_command_ui.rb index 43a5a308..f348298f 100644 --- a/lib/compass/exec/sub_command_ui.rb +++ b/lib/compass/exec/sub_command_ui.rb @@ -12,8 +12,7 @@ module Compass::Exec 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) @@ -40,7 +39,9 @@ module Compass::Exec 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)