From fa2ac5a57f459371020b1eefe6833d6ae45d7a9c Mon Sep 17 00:00:00 2001 From: Valentin Kiselev Date: Thu, 6 Apr 2023 10:55:07 +0300 Subject: [PATCH] fix: golang detector regexp --- spec/coverage_reporter/parsers/golang_parser_spec.cr | 1 + spec/fixtures/golang/coverage-dashes.out | 2 ++ src/coverage_reporter/parsers/golang_parser.cr | 4 ++-- 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 spec/fixtures/golang/coverage-dashes.out diff --git a/spec/coverage_reporter/parsers/golang_parser_spec.cr b/spec/coverage_reporter/parsers/golang_parser_spec.cr index 74e49c5d..af93bf43 100644 --- a/spec/coverage_reporter/parsers/golang_parser_spec.cr +++ b/spec/coverage_reporter/parsers/golang_parser_spec.cr @@ -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 diff --git a/spec/fixtures/golang/coverage-dashes.out b/spec/fixtures/golang/coverage-dashes.out new file mode 100644 index 00000000..47e23570 --- /dev/null +++ b/spec/fixtures/golang/coverage-dashes.out @@ -0,0 +1,2 @@ +mode: atomic +github.com/evilmartians/lefthook-go/internal/log/log.go:47.20,58.2 1 1 diff --git a/src/coverage_reporter/parsers/golang_parser.cr b/src/coverage_reporter/parsers/golang_parser.cr index 8f82d9ff..c1a1a724 100644 --- a/src/coverage_reporter/parsers/golang_parser.cr +++ b/src/coverage_reporter/parsers/golang_parser.cr @@ -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 @@ -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