Skip to content

Commit

Permalink
Fix nogo issues
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Nov 8, 2024
1 parent 5170ede commit 7e1ee83
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 13 deletions.
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ go_download_sdk(
)

go_register_nogo(
nogo = "@//:tools_nogo",
nogo = "@//internal:nogo",
)

http_archive(
Expand Down
4 changes: 2 additions & 2 deletions go/tools/releaser/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func runPrepare(ctx context.Context, stderr io.Writer, args []string) error {
branchName := "release-" + majorMinor[len("v"):]
if !gitBranchExists(ctx, rootDir, branchName) {
if !isMinorRelease {
return fmt.Errorf("release branch %q does not exist locally. Fetch it, set RULES_GO_VERSION, add commits, and run this command again.")
return fmt.Errorf("release branch %q does not exist locally. Fetch it, set RULES_GO_VERSION, add commits, and run this command again.", branchName)
}
if err := checkRulesGoVersion(ctx, rootDir, "HEAD", version); err != nil {
return err
Expand Down Expand Up @@ -247,7 +247,7 @@ func checkRulesGoVersion(ctx context.Context, dir, refName, version string) erro
}
rulesGoVersionStr := []byte(fmt.Sprintf(`RULES_GO_VERSION = "%s"`, version[len("v"):]))
if !bytes.Contains(data, rulesGoVersionStr) {
return fmt.Errorf("RULES_GO_VERSION was not set to %q in go/def.bzl. Set it, add commits, and run this command again.")
return fmt.Errorf("RULES_GO_VERSION was not set to %q in go/def.bzl. Set it, add commits, and run this command again.", version)
}
return nil
}
6 changes: 3 additions & 3 deletions go/tools/releaser/upgradedep.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,8 @@ func upgradeDepDecl(ctx context.Context, gh *githubClient, workDir, name string,
}
patchName := patchLabelValue[len("//third_party:"):]
patchPath := filepath.Join(rootDir, "third_party", patchName)
prevDir := filepath.Join(workDir, name, string('a'+patchIndex))
patchDir := filepath.Join(workDir, name, string('a'+patchIndex+1))
prevDir := filepath.Join(workDir, name, fmt.Sprintf("a%d", patchIndex))
patchDir := filepath.Join(workDir, name, fmt.Sprintf("a%d", patchIndex+1))
var patchCmd []string
for _, c := range comments.Before {
words := strings.Fields(strings.TrimPrefix(c.Token, "#"))
Expand All @@ -484,7 +484,7 @@ func upgradeDepDecl(ctx context.Context, gh *githubClient, workDir, name string,
return err
}
}
patch, _ := runForOutput(ctx, filepath.Join(workDir, name), "diff", "-urN", string('a'+patchIndex), string('a'+patchIndex+1))
patch, _ := runForOutput(ctx, filepath.Join(workDir, name), "diff", "-urN", fmt.Sprintf("a%d", patchIndex), fmt.Sprintf("a%d", patchIndex+1))
patch = sanitizePatch(patch)
if err := os.WriteFile(patchPath, patch, 0666); err != nil {
return err
Expand Down
12 changes: 12 additions & 0 deletions internal/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("//go:def.bzl", "TOOLS_NOGO", "nogo")

nogo(
name = "nogo",
visibility = ["//visibility:public"],
deps = [
a
for a in TOOLS_NOGO
# Filter out shadow as it triggers on err and is very noisy.
if a != "@org_golang_x_tools//go/analysis/passes/shadow:go_default_library"
],
)
4 changes: 2 additions & 2 deletions tests/core/go_proto_library_importpath/importpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func Test(t *testing.T) {
var expected int64 = 5
if bar.Value.Value != expected {
t.Errorf(fmt.Sprintf("Not equal: \n"+
"expected: %s\n"+
"actual : %s", expected, bar.Value.Value))
"expected: %d\n"+
"actual : %d", expected, bar.Value.Value))
}
}
8 changes: 8 additions & 0 deletions tests/core/go_test/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import "fmt"

var Expected = "Expected"

// Please the "tests" nogo check.
var (
HelloWorld string
DontTestMe string
TestEmptyOutput string
TestQuoting string
)

func ExampleHelloWorld() {
fmt.Println("Hello Example!")
fmt.Println("expected: " + Expected)
Expand Down
2 changes: 1 addition & 1 deletion tests/core/go_test/filter_test_cases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func Test(t *testing.T) {
}
p, err := bazel_testing.BazelOutput("info", "bazel-testlogs")
if err != nil {
t.Fatal("could not find testlog root: %s", err)
t.Fatalf("could not find testlog root: %s", err)
}
path := filepath.Join(strings.TrimSpace(string(p)), "filter_test/test.xml")
b, err := ioutil.ReadFile(path)
Expand Down
2 changes: 1 addition & 1 deletion tests/core/go_test/timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestTimeout(t *testing.T) {
if err := bazel_testing.RunBazel("test", "//:timeout_test", "--test_timeout=3", "--test_arg=-test.v"); err == nil {
t.Fatal("expected bazel test to fail")
} else if exitErr, ok := err.(*bazel_testing.StderrExitError); !ok || exitErr.Err.ExitCode() != 3 {
t.Fatalf("expected bazel test to fail with exit code 3", err)
t.Fatalf("expected bazel test to fail with exit code 3, got %v", err)
} else {
stderr = string(exitErr.Err.Stderr)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/core/go_test/xmlreport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func Test(t *testing.T) {

p, err := bazel_testing.BazelOutput("info", "bazel-testlogs")
if err != nil {
t.Fatal("could not find testlog root: %s", err)
t.Fatalf("could not find testlog root: %s", err)
}
path := filepath.Join(strings.TrimSpace(string(p)), "xml_test/test.xml")
b, err := ioutil.ReadFile(path)
Expand Down
14 changes: 12 additions & 2 deletions tests/integration/reproducibility/reproducibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ func Test(t *testing.T) {
// Build the targets in each directory.
var wg sync.WaitGroup
wg.Add(len(dirs))
var errs []error
var mu sync.Mutex
for _, dir := range dirs {
go func(dir string) {
defer wg.Done()
Expand All @@ -196,11 +198,19 @@ func Test(t *testing.T) {
)
cmd.Dir = dir
if err := cmd.Run(); err != nil {
t.Fatalf("in %s, error running %s: %v", dir, strings.Join(cmd.Args, " "), err)
mu.Lock()
errs = append(errs, fmt.Errorf("in %s, error running %s: %v", dir, strings.Join(cmd.Args, " "), err))
mu.Unlock()
}
}(dir)
}
wg.Wait()
if len(errs) > 0 {
for _, err := range errs {
t.Error(err)
}
t.Fatal("errors building")
}

t.Run("Check Hashes", func(t *testing.T) {
// Hash files in each bazel-bin directory.
Expand Down Expand Up @@ -232,7 +242,7 @@ func Test(t *testing.T) {

// Compare dir0 and dir2. They should be different.
if err := compareHashes(dirHashes[0], dirHashes[2]); err == nil {
t.Fatalf("dir0 and dir2 are the same)", len(dirHashes[0]))
t.Fatal("dir0 and dir2 are the same")
}
})

Expand Down

0 comments on commit 7e1ee83

Please sign in to comment.