Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a8eab95654d4
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4ad378dea62c
Choose a head ref
  • 3 commits
  • 2 files changed
  • 2 contributors

Commits on Nov 20, 2015

  1. implement Coverage.peek_result

    This patch implements `Coverage.peek_result` that was implemented in MRI
    here:
    
      https://bugs.ruby-lang.org/issues/10816
    tenderlove committed Nov 20, 2015
    Copy the full SHA
    ced60e8 View commit details
  2. Merge branch 'peek_result' of https://github.com/tenderlove/jruby int…

    …o tenderlove-peek_result
    headius committed Nov 20, 2015
    Copy the full SHA
    0717e88 View commit details
  3. Copy the full SHA
    4ad378d View commit details
Showing with 18 additions and 1 deletion.
  1. +4 −0 core/src/main/java/org/jruby/ext/coverage/CoverageData.java
  2. +14 −1 core/src/main/java/org/jruby/ext/coverage/CoverageModule.java
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/ext/coverage/CoverageData.java
Original file line number Diff line number Diff line change
@@ -42,6 +42,10 @@ public boolean isCoverageEnabled() {
return coverage != null;
}

public Map<String, int[]> getCoverage() {
return this.coverage;
}

public synchronized void setCoverageEnabled(Ruby runtime, boolean enabled) {
if (enabled) {
coverage = new HashMap<String, int[]>();
15 changes: 14 additions & 1 deletion core/src/main/java/org/jruby/ext/coverage/CoverageModule.java
Original file line number Diff line number Diff line change
@@ -58,8 +58,21 @@ public static IRubyObject result(ThreadContext context, IRubyObject self) {
throw runtime.newRuntimeError("coverage measurement is not enabled");
}

Map<String, int[]> coverage = runtime.getCoverageData().resetCoverage(runtime);
return convertCoverageToRuby(context, runtime, runtime.getCoverageData().resetCoverage(runtime));
}

@JRubyMethod(module = true)
public static IRubyObject peekResult(ThreadContext context, IRubyObject self) {
Ruby runtime = context.runtime;

if (!runtime.getCoverageData().isCoverageEnabled()) {
throw runtime.newRuntimeError("coverage measurement is not enabled");
}

return convertCoverageToRuby(context, runtime, runtime.getCoverageData().getCoverage());
}

private static IRubyObject convertCoverageToRuby(ThreadContext context, Ruby runtime, Map<String, int[]> coverage) {
// populate a Ruby Hash with coverage data
RubyHash covHash = RubyHash.newHash(runtime);
for (Map.Entry<String, int[]> entry : coverage.entrySet()) {