diff --git a/coverage/coverage.go b/coverage/coverage.go index 6c555657..3076b03c 100644 --- a/coverage/coverage.go +++ b/coverage/coverage.go @@ -107,38 +107,6 @@ func (fc FileCoverages) FuzzyFindByFile(file string) (*FileCoverage, error) { // return nil, fmt.Errorf("file name not found: %s", file) } -func (fc FileCoverages) PathPrefix() (string, error) { //nostyle:recvtype - if len(fc) == 0 { - return "", errors.New("no file coverages") - } - p := strings.Split(filepath.Dir(filepath.ToSlash(fc[0].File)), "/") - for _, c := range fc { - d := strings.Split(filepath.Dir(filepath.ToSlash(c.File)), "/") - i := 0 - for { - if len(p) <= i { - break - } - if len(d) <= i { - break - } - if p[i] != d[i] { - break - } - i += 1 - } - p = p[:i] - } - s := strings.Join(p, "/") - if s == "" && filepath.IsAbs(fc[0].File) { - s = "/" - } - if s == "." { - s = "" - } - return s, nil -} - func (fc *FileCoverage) FindBlocksByLine(n int) BlockCoverages { if fc == nil { return BlockCoverages{} diff --git a/coverage/coverage_test.go b/coverage/coverage_test.go index 975e6d5a..76e91511 100644 --- a/coverage/coverage_test.go +++ b/coverage/coverage_test.go @@ -90,57 +90,6 @@ func TestCompare(t *testing.T) { } } -func TestPathPrefix(t *testing.T) { - tests := []struct { - files FileCoverages - want string - }{ - { - FileCoverages{ - &FileCoverage{File: "file_a.go"}, - }, - "", - }, - { - FileCoverages{ - &FileCoverage{File: "path/to/file_a.go"}, - &FileCoverage{File: "path/file_b.go"}, - }, - "path", - }, - { - FileCoverages{ - &FileCoverage{File: "/path/to/file_a.go"}, - &FileCoverage{File: "/path/file_b.go"}, - }, - "/path", - }, - { - FileCoverages{ - &FileCoverage{File: "/path/to/foo/file_a.go"}, - &FileCoverage{File: "/path/to/foo/bar/file_b.go"}, - }, - "/path/to/foo", - }, - { - FileCoverages{ - &FileCoverage{File: "/to/foo/file_a.go"}, - &FileCoverage{File: "/path/to/foo/bar/file_b.go"}, - }, - "/", - }, - } - for _, tt := range tests { - got, err := tt.files.PathPrefix() - if err != nil { - t.Fatal(err) - } - if got != tt.want { - t.Errorf("got %v\nwant %v", got, tt.want) - } - } -} - func TestMaxCount(t *testing.T) { tests := []struct { blocks BlockCoverages