Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 9 additions & 7 deletions go/tools/builders/compilepkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ func compileArchive(
}

var (
coverIn []string
coverOut []string
coverIn []string
coverOut []string
srcPathMapping = make(map[string]string)
)
for i, origSrc := range combined {
Expand Down Expand Up @@ -312,12 +312,14 @@ func compileArchive(
// https://github.com/golang/go/blob/go1.24.5/src/cmd/go/internal/work/exec.go#L1932
sum := sha256.Sum256([]byte(importPath))
coverVar := fmt.Sprintf("goCover_%x_", sum[:6])
coverageCfg = workDir + "pkgcfg.txt"
coverOut, err := instrumentForCoverage(goenv, importPath, packageName, coverIn, coverVar, coverMode, coverOut, workDir, relCoverPath, srcPathMapping)
if err != nil {
return err
if len(coverOut) > 0 {
coverageCfg = workDir + "pkgcfg.txt"
coverOut, err := instrumentForCoverage(goenv, importPath, packageName, coverIn, coverVar, coverMode, coverOut, workDir, relCoverPath, srcPathMapping)
if err != nil {
return err
}
goSrcs = append(goSrcs, coverOut[0])
}
goSrcs = append(goSrcs, coverOut[0])
}

// If we have cgo, generate separate C and go files, and compile the
Expand Down
5 changes: 5 additions & 0 deletions tests/core/coverage/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ go_bazel_test(
srcs = ["issue3017_test.go"],
)

go_bazel_test(
name = "issue4414_test",
srcs = ["issue4414_test.go"],
)

go_bazel_test(
name = "reassign_flag_commandline_test",
srcs = ["reassign_flag_commandline_test.go"],
Expand Down
69 changes: 69 additions & 0 deletions tests/core/coverage/issue4414_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright 2019 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package coverage_test

import (
"testing"

"github.com/bazelbuild/rules_go/go/tools/bazel_testing"
)

func TestMain(m *testing.M) {
bazel_testing.TestMain(m, bazel_testing.Args{
Main: `
-- issue.go --
package internal

-- issue_test.go --
package internal

import (
"testing"
)

func TestOK(t *testing.T) {

}

func TestRead_MultipleMessages(t *testing.T) {

}

func TestError(t *testing.T) {

}

-- BUILD.bazel --
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "issue",
srcs = ["issue.go"],
importpath = "github.com/bakjos/test/internal",
)

go_test(
name = "issue_test",
srcs = ["issue_test.go"],
embed = [":issue"],
)
`,
})
}

func TestIssue4414(t *testing.T) {
if err := bazel_testing.RunBazel("coverage", "--instrument_test_targets", "//:issue_test"); err != nil {
t.Fatal(err)
}
}