Skip to content

Commit

Permalink
Remove Ruby warning
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
infertux committed Mar 25, 2013
1 parent b9e3617 commit 221a74e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
25 changes: 12 additions & 13 deletions lib/simplecov/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -54,31 +56,28 @@
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
if diff > SimpleCov.maximum_coverage_drop
$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
Expand Down
1 change: 1 addition & 0 deletions lib/simplecov/exit_codes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module SimpleCov::ExitCodes
SUCCESS = 0
EXCEPTION = 1
MINIMUM_COVERAGE = 2
MAXIMUM_COVERAGE_DROP = 3
Expand Down

0 comments on commit 221a74e

Please sign in to comment.