Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Ruby warnings #213

Merged
merged 2 commits into from
Nov 10, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/simplecov.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def usable?

@usable = begin
require 'coverage'
require 'simplecov/jruby16_fix'
require 'simplecov/jruby_fix'
true
rescue LoadError
false
Expand Down
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
11 changes: 5 additions & 6 deletions lib/simplecov/jruby16_fix.rb → lib/simplecov/jruby_fix.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
if defined?(JRUBY_VERSION) && JRUBY_VERSION.to_f < 1.7
if defined?(JRUBY_VERSION)
require 'jruby'
java_import 'org.jruby.ast.NodeType'

# Coverage for JRuby < 1.7.0 does not work correctly
# Coverage for JRuby does not work correctly
#
# - does not distinguish lines that cannot be executed
# - does (partial) coverage for files loaded before `Coverage.start`.
Expand All @@ -16,6 +16,8 @@ class << self
def result
fixed = {}
__broken_result__.each do |path, executed_lines|
next unless File.file? path

covered_lines = executed_lines.dup

process = lambda do |node|
Expand All @@ -26,10 +28,7 @@ def result
node.child_nodes.each(&process)
end

begin
process[JRuby.parse(File.read(path), path)]
rescue => e
end
process[JRuby.parse(File.read(path), path)]

if (first = covered_lines.detect { |x| x }) && first > 0
fixed[File.expand_path(path)] = covered_lines
Expand Down
12 changes: 2 additions & 10 deletions lib/simplecov/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,10 @@ class Result
# Initialize a new SimpleCov::Result from given Coverage.result (a Hash of filenames each containing an array of
# coverage data)
def initialize(original_result)
@original_result = original_result.dup

# Squeeze filepaths (i.e. "/a/b/../c" becomes "/a/c")
@original_result.keys.each do |filename|
expanded_filename = File.expand_path filename
@original_result[expanded_filename] = @original_result.delete filename
end

@files = SimpleCov::FileList.new(@original_result.map do |filename, coverage|
@original_result = original_result.freeze
@files = SimpleCov::FileList.new(original_result.map do |filename, coverage|
SimpleCov::SourceFile.new(filename, coverage) if File.file?(filename)
end.compact.sort_by(&:filename))

filter!
end

Expand Down