• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

coverallsapp / coverage-reporter / 4424338159

15 Mar 2023 09:00AM UTC coverage: 90.616% (-3.0%) from 93.57%
4424338159

push

github

GitHub
fix: improve ci support (#32)

76 of 76 new or added lines in 8 files covered. (100.0%)

647 of 714 relevant lines covered (90.62%)

1.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.31
/src/coverage_reporter/parser.cr
1
require "./parsers/*"
2

3
module CoverageReporter
4
  # General parser that can do the following:
5
  # * Automatically find coverage report files.
6
  # * Parse coverage report files and return the format that Coveralls API requires.
7
  #
8
  # New parsers can be easily added. See `BaseParser` for details.
9
  class Parser
10
    getter file : String?
11
    getter parsers : Array(BaseParser)
12

13
    # A list of available parsers.
14
    # See `CoverageReporter::BaseParser` for details.
15
    PARSERS = {
2✔
16
      LcovParser,
17
      SimplecovParser,
18
      CoberturaParser,
19
      JacocoParser,
20
      GcovParser,
21
      GolangParser,
22
      CoveragepyParser,
23
    }
24

25
    class NotFound < BaseException
26
      def initialize(@filename : String)
3✔
27
      end
1✔
28

29
      def message
×
30
        "🚨 ERROR: Couldn't find specified file: #{@filename}"
×
31
      end
32
    end
33

34
    def initialize(@file : String?, base_path : String?)
12✔
35
      @parsers = PARSERS.map(&.new(base_path)).to_a
6✔
36
    end
37

38
    # Returns coverage report files that can be parsed by utility.
39
    def files : Array(String)
2✔
40
      if custom_file = file
1✔
41
        if !File.exists?(custom_file)
2✔
42
          raise NotFound.new(custom_file)
1✔
43
        end
44

45
        Log.info "📄 Using coverage file: #{custom_file}"
1✔
46
        return [custom_file]
1✔
47
      end
48

49
      files = [] of String
1✔
50
      Dir[parsers.flat_map(&.globs)].each do |filename|
3✔
51
        unless filename =~ /node_modules|vendor/
2✔
52
          files.push(filename)
1✔
53
          Log.info "🔍 Detected coverage file: #{filename}"
1✔
54
        end
55
      end
56

57
      files
58
    end
59

60
    def parse : Array(FileReport)
1✔
61
      files.flat_map do |filename|
1✔
62
        parse_file(filename)
1✔
63
      end
64
    end
65

66
    private def parse_file(filename : String)
2✔
67
      parsers.each do |parser|
68
        next unless parser.matches?(filename)
2✔
69

70
        return parser.parse(filename)
1✔
71
      end
72

73
      Log.info "⚠️ Coverage reporter does not yet know how to process this file: #{filename}"
1✔
74
      [] of FileReport
1✔
75
    end
76
  end
77
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc