lib/simplecov.rb in simplecov-0.11.1 vs lib/simplecov.rb in simplecov-0.11.2
- old
+ new
@@ -1,16 +1,20 @@
#
# Code coverage for ruby 1.9. Please check out README for a full introduction.
#
# Coverage may be inaccurate under JRUBY.
-if defined?(JRUBY_VERSION)
- if ENV["JRUBY_OPTS"].to_s !~ /-Xcli.debug=true/
- warn "Coverage may be inaccurate; Try setting JRUBY_OPTS=\"-Xcli.debug=true --debug\""
- # see https://github.com/metricfu/metric_fu/pull/226
- # https://github.com/jruby/jruby/issues/1196
- # https://jira.codehaus.org/browse/JRUBY-6106
- # https://github.com/colszowka/simplecov/issues/86
+if defined?(JRUBY_VERSION) && defined?(JRuby)
+
+ # @see https://github.com/jruby/jruby/issues/1196
+ # @see https://github.com/metricfu/metric_fu/pull/226
+ # @see https://github.com/colszowka/simplecov/issues/420
+ # @see https://github.com/colszowka/simplecov/issues/86
+ # @see https://jira.codehaus.org/browse/JRUBY-6106
+
+ unless JRuby.runtime.debug?
+ warn 'Coverage may be inaccurate; set "cli.debug=true" ("-Xcli.debug=true") in your .jrubyrc or' \
+ ' do JRUBY_OPTS="-d"'
end
end
module SimpleCov
class << self
attr_accessor :running
@@ -51,13 +55,13 @@
#
# Finds files that were to be tracked but were not loaded and initializes
# their coverage to zero.
#
def add_not_loaded_files(result)
- if @track_files_glob
+ if track_files
result = result.dup
- Dir[@track_files_glob].each do |file|
+ Dir[track_files].each do |file|
absolute = File.expand_path(file)
result[absolute] ||= [0] * File.foreach(absolute).count
end
end
@@ -68,17 +72,25 @@
#
# Returns the result for the current coverage run, merging it across test suites
# from cache using SimpleCov::ResultMerger if use_merging is activated (default)
#
def result
- @result ||= SimpleCov::Result.new(add_not_loaded_files(Coverage.result)) if running
+ # Ensure the variable is defined to avoid ruby warnings
+ @result = nil unless defined?(@result)
+
+ # Collect our coverage result
+ if running && !result?
+ @result = SimpleCov::Result.new add_not_loaded_files(Coverage.result)
+ end
+
# If we're using merging of results, store the current result
# first, then merge the results and return those
if use_merging
- SimpleCov::ResultMerger.store_result(@result) if @result
- return SimpleCov::ResultMerger.merged_result
+ SimpleCov::ResultMerger.store_result(@result) if result?
+
+ SimpleCov::ResultMerger.merged_result
else
- return @result if defined? @result
+ @result
end
ensure
self.running = false
end