From 221a74ebcbd99d1dab0fe4c73b2835003eeeb560 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20F=C3=A9lizard?= Date: Mon, 25 Mar 2013 20:52:09 +0100 Subject: [PATCH] Remove Ruby warning `lib/simplecov/defaults:57: warning: instance variable @exit_status not initialized` We now ensure that @exit_status is always initialized. Also did some cosmetic arrangements with no functional changes. --- lib/simplecov/defaults.rb | 25 ++++++++++++------------- lib/simplecov/exit_codes.rb | 1 + 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/simplecov/defaults.rb b/lib/simplecov/defaults.rb index 5b85de20..bec4e194 100644 --- a/lib/simplecov/defaults.rb +++ b/lib/simplecov/defaults.rb @@ -42,10 +42,12 @@ at_exit do # Store the exit status of the test run since it goes away after calling the at_exit proc... - if $! #was an exception thrown? - #if it was a SystemExit, use the accompanying status - #otherwise set a non-zero status representing termination by some other exception - #(see github issue 41) + @exit_status = SimpleCov::ExitCodes::SUCCESS + + if $! # was an exception thrown? + # if it was a SystemExit, use the accompanying status + # otherwise set a non-zero status representing termination by some other exception + # (see github issue 41) @exit_status = $!.is_a?(SystemExit) ? $!.status : SimpleCov::ExitCodes::EXCEPTION end @@ -54,12 +56,12 @@ if SimpleCov.result? # Result has been computed covered_percent = SimpleCov.result.covered_percent.round(2) - if @exit_status.to_i == 0 # No other errors - @exit_status = if covered_percent < SimpleCov.minimum_coverage + if @exit_status == SimpleCov::ExitCodes::SUCCESS # No other errors + if covered_percent < SimpleCov.minimum_coverage $stderr.puts "Coverage (%.2f%%) is below the expected minimum coverage (%.2f%%)." % \ [covered_percent, SimpleCov.minimum_coverage] - SimpleCov::ExitCodes::MINIMUM_COVERAGE + @exit_status = SimpleCov::ExitCodes::MINIMUM_COVERAGE elsif (last_run = SimpleCov::LastRun.read) diff = last_run['result']['covered_percent'] - covered_percent @@ -67,18 +69,15 @@ $stderr.puts "Coverage has dropped by %.2f%% since the last time (maximum allowed: %.2f%%)." % \ [diff, SimpleCov.maximum_coverage_drop] - SimpleCov::ExitCodes::MAXIMUM_COVERAGE_DROP + @exit_status = SimpleCov::ExitCodes::MAXIMUM_COVERAGE_DROP end end end - metrics = { - :result => { :covered_percent => covered_percent } - } - SimpleCov::LastRun.write(metrics) + SimpleCov::LastRun.write(:result => {:covered_percent => covered_percent}) end - exit @exit_status if @exit_status # Force exit with stored status (see github issue #5) + exit @exit_status # Force exit with stored status (see github issue #5) end # Autoload config from ~/.simplecov if present diff --git a/lib/simplecov/exit_codes.rb b/lib/simplecov/exit_codes.rb index 04f3ab81..670e2deb 100644 --- a/lib/simplecov/exit_codes.rb +++ b/lib/simplecov/exit_codes.rb @@ -1,4 +1,5 @@ module SimpleCov::ExitCodes + SUCCESS = 0 EXCEPTION = 1 MINIMUM_COVERAGE = 2 MAXIMUM_COVERAGE_DROP = 3