Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve golang detector regexp #49

Merged
merged 1 commit into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions spec/coverage_reporter/parsers/golang_parser_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Spectator.describe CoverageReporter::GolangParser do
describe "#matches?" do
it "matches correct filenames" do
expect(subject.matches?("spec/fixtures/golang/coverage.out")).to eq true
expect(subject.matches?("spec/fixtures/golang/coverage-dashes.out")).to eq true
expect(subject.matches?("spec/fixtures/test.lcov")).to eq false
expect(subject.matches?("some-non-existing-file.out")).to eq false
end
Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/golang/coverage-dashes.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mode: atomic
github.com/evilmartians/lefthook-go/internal/log/log.go:47.20,58.2 1 1
4 changes: 2 additions & 2 deletions src/coverage_reporter/parsers/golang_parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require "./base_parser"

module CoverageReporter
class GolangParser < BaseParser
COVERAGE_RE = /^[\w.]+\/[\w.]+\/[\w.]+\/(?:v\d+\/)?(.*\.go):(\d+)\.\d+,(\d+)\.\d+\s+\d+\s+(\d+)/
COVERAGE_RE = /^[\w.-]+\/[\w.-]+\/[\w.-]+\/(?:v\d+\/)?(.*\.go):(\d+)\.\d+,(\d+)\.\d+\s+\d+\s+(\d+)/

def globs : Array(String)
[] of String
Expand All @@ -12,7 +12,7 @@ module CoverageReporter
return false unless File.exists?(filename)

File.open(filename, "r") do |f|
# 1st line can be "mode: set"
# 1st line can contain "mode:"
2.times do
return true if COVERAGE_RE.matches?(f.gets.to_s)
end
Expand Down