Skip to content

Commit

Permalink
Merge #213, use jruby fix only on < 1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
colszowka committed Nov 10, 2013
2 parents 68b1f1e + 221a74e commit 5143ee6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 30 deletions.
2 changes: 1 addition & 1 deletion lib/simplecov.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def usable?

@usable = begin
require 'coverage'
require 'simplecov/jruby16_fix'
require 'simplecov/jruby_fix'
true
rescue LoadError
false
Expand Down
28 changes: 13 additions & 15 deletions lib/simplecov/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,46 +40,44 @@
SimpleCov::CommandGuesser.original_run_command = "#{$0} #{ARGV.join(" ")}"

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)

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
else
@exit_status = 0
# Store the exit status of the test run since it goes away after calling the at_exit proc...
@exit_status = SimpleCov::ExitCodes::SUCCESS
end

SimpleCov.at_exit.call

if SimpleCov.result? # Result has been computed
covered_percent = SimpleCov.result.covered_percent.round(2)

if @exit_status == 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
7 changes: 3 additions & 4 deletions lib/simplecov/jruby16_fix.rb → lib/simplecov/jruby_fix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -23,18 +23,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

0 comments on commit 5143ee6

Please sign in to comment.