summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-07-21 10:25:57 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-07-21 12:46:49 +0200
commit8e5e668e1a0844ebafbfc8081d9f71a030feb1d6 (patch)
treed3f8a5d18f8304cc34929bcfdd803855024b9cf1
parentbe3ad008aad2745e3a80ca789025005e180c805e (diff)
downloadgitlab-ce-8e5e668e1a0844ebafbfc8081d9f71a030feb1d6.tar.gz
Patch SimpleCov to reuse code for coverage merger
-rwxr-xr-xscripts/merge-simplecov74
1 files changed, 21 insertions, 53 deletions
diff --git a/scripts/merge-simplecov b/scripts/merge-simplecov
index 9504321e6d7..ab15b43bd0f 100755
--- a/scripts/merge-simplecov
+++ b/scripts/merge-simplecov
@@ -1,61 +1,29 @@
#!/usr/bin/env ruby
-begin
- load File.expand_path('../spring', __FILE__)
-rescue LoadError => e
- raise unless e.message.include?('spring')
-end
require 'simplecov'
-def read(file)
- return unless File.exist?(file)
- data = File.read(file)
- return if data.nil? || data.length < 2
- data
-end
-
-def load(file)
- begin
- JSON.parse(read(file))
- rescue
- {}
- end
-end
-
-def files
- Dir.glob(File.join(SimpleCov.coverage_path, '*', '.resultset.json'))
-end
-
-def resultsfiles
- files.map { |file| load(file) }
-end
-
-def resultsets
- resultsfiles.reduce({}, :merge)
-end
-
-def all_results
- results = []
- resultsets.each do |command_name, data|
- result = SimpleCov::Result.from_hash(command_name => data)
- # Only add result if the timeout is above the configured threshold
- if (Time.now - result.created_at) < SimpleCov.merge_timeout
- results << result
+module SimpleCov
+ module ResultMerger
+ class << self
+ def resultset_files
+ Dir.glob(File.join(SimpleCov.coverage_path, '*', '.resultset.json'))
+ end
+
+ def resultset_hashes
+ resultset_files.map do |path|
+ begin
+ JSON.parse(File.read(path))
+ rescue
+ {}
+ end
+ end
+ end
+
+ def resultset
+ resultset_hashes.reduce({}, :merge)
+ end
end
end
- results
-end
-
-def merged_result
- merged = {}
- results = all_results
- results.each do |result|
- merged = result.original_result.merge_resultset(merged)
- end
- result = SimpleCov::Result.new(merged)
- # Specify the command name
- result.command_name = results.map(&:command_name).sort.join(", ")
- result
end
# Ignore CI environment
@@ -64,4 +32,4 @@ ENV['CI_BUILD_NAME'] = nil
require_relative '../spec/simplecov_env'
-merged_result.format!
+SimpleCov::ResultMerger.merged_result.format!