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

JRuby 1.6 support #174

Merged
merged 2 commits into from
Dec 7, 2012
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
7 changes: 7 additions & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@
end
step 'I cd to "project"'
end

# Workaround for https://github.com/cucumber/aruba/pull/125
Aruba.configure do |config|
config.before_cmd do
set_env('JRUBY_OPTS', '-X-C --1.9')
end
end
1 change: 1 addition & 0 deletions lib/simplecov.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def start(adapter=nil, &block)
return false unless SimpleCov.usable?

require 'coverage'
require 'simplecov/jruby16_fix'
load_adapter(adapter) unless adapter.nil?
Coverage.start
configure(&block) if block_given?
Expand Down
43 changes: 43 additions & 0 deletions lib/simplecov/jruby16_fix.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
if defined?(JRUBY_VERSION) && JRUBY_VERSION.to_f < 1.7
require 'jruby'
java_import 'org.jruby.ast.NodeType'

# Coverage for JRuby < 1.7.0 does not work correctly
#
# - does not distinguish lines that cannot be executed
# - does (partial) coverage for files loaded before `Coverage.start`.
# - does not expand a path like `lib/../spec` to `spec`.
#
# This monkey patches Coverage to address those issues
module Coverage
class << self
alias __broken_result__ result

def result
fixed = {}
__broken_result__.each do |path, executed_lines|
covered_lines = executed_lines.dup

process = lambda do |node|
if node.node_type == NodeType::NEWLINENODE
pos = node.position
covered_lines[pos.line] ||= 0
end
node.child_nodes.each(&process)
end

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

if (first = covered_lines.detect { |x| x }) && first > 0
fixed[File.expand_path(path)] = covered_lines
end
end

fixed
end
end
end
end