summaryrefslogtreecommitdiff
path: root/scripts/merge-simplecov
blob: b59ff0ae9a09a858259a5fa59190e0594809d9b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/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
    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

SimpleCov.configure do
  merge_timeout 7200
end

merged_result.format!