-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
build: TestProtoMarshal correctly avoids Marshal methods #18496
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,38 +129,72 @@ func TestStyle(t *testing.T) { | |
|
||
t.Run("TestEnvutil", func(t *testing.T) { | ||
t.Parallel() | ||
cmd, stderr, filter, err := dirCmd(pkg.Dir, "git", "grep", "-nE", `os\.(Getenv|LookupEnv)`, "--", "*.go") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
for _, tc := range []struct { | ||
re string | ||
excludes []string | ||
}{ | ||
{re: `\bos\.(Getenv|LookupEnv)\("COCKROACH`}, | ||
{ | ||
re: `\bos\.(Getenv|LookupEnv)\(`, | ||
excludes: []string{ | ||
":!acceptance", | ||
":!build/style_test.go", | ||
":!ccl/acceptanceccl/backup_test.go", | ||
":!ccl/sqlccl/backup_cloud_test.go", | ||
":!ccl/storageccl/export_storage_test.go", | ||
":!cmd", | ||
":!util/envutil/env.go", | ||
":!util/log/clog.go", | ||
":!util/log/color.go", | ||
":!util/sdnotify/sdnotify_unix.go", | ||
}, | ||
}, | ||
} { | ||
cmd, stderr, filter, err := dirCmd( | ||
pkg.Dir, | ||
"git", | ||
append([]string{ | ||
"grep", | ||
"-nE", | ||
tc.re, | ||
"--", | ||
"*.go", | ||
}, tc.excludes...)..., | ||
) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if err := cmd.Start(); err != nil { | ||
t.Fatal(err) | ||
} | ||
if err := cmd.Start(); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if err := stream.ForEach(stream.Sequence( | ||
filter, | ||
stream.GrepNot(`^cmd(/.*)?/\w+\.go\b`), | ||
stream.GrepNot(`^build/style_test\.go\b`), | ||
stream.GrepNot(`^ccl/(sqlccl/backup_cloud|storageccl/export_storage|acceptanceccl/backup)_test\.go\b`), | ||
stream.GrepNot(`^acceptance(/.*)?/\w+\.go\b`), | ||
stream.GrepNot(`^util/(log|envutil|sdnotify)/\w+\.go\b`), | ||
), func(s string) { | ||
t.Errorf(`%s <- forbidden; use "envutil" instead`, s) | ||
}); err != nil { | ||
t.Error(err) | ||
} | ||
if err := stream.ForEach(filter, func(s string) { | ||
t.Errorf(`%s <- forbidden; use "envutil" instead`, s) | ||
}); err != nil { | ||
t.Error(err) | ||
} | ||
|
||
if err := cmd.Wait(); err != nil { | ||
if out := stderr.String(); len(out) > 0 { | ||
t.Fatalf("err=%s, stderr=%s", err, out) | ||
if err := cmd.Wait(); err != nil { | ||
if out := stderr.String(); len(out) > 0 { | ||
t.Fatalf("err=%s, stderr=%s", err, out) | ||
} | ||
} | ||
} | ||
}) | ||
|
||
t.Run("TestSyncutil", func(t *testing.T) { | ||
t.Parallel() | ||
cmd, stderr, filter, err := dirCmd(pkg.Dir, "git", "grep", "-nE", `sync\.(RW)?Mutex`, "--", "*.go") | ||
cmd, stderr, filter, err := dirCmd( | ||
pkg.Dir, | ||
"git", | ||
"grep", | ||
"-nE", | ||
`\bsync\.(RW)?Mutex`, | ||
"--", | ||
"*.go", | ||
":!util/syncutil/mutex_sync.go", | ||
) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
@@ -169,10 +203,7 @@ func TestStyle(t *testing.T) { | |
t.Fatal(err) | ||
} | ||
|
||
if err := stream.ForEach(stream.Sequence( | ||
filter, | ||
stream.GrepNot(`^util/syncutil/mutex_sync\.go\b`), | ||
), func(s string) { | ||
if err := stream.ForEach(filter, func(s string) { | ||
t.Errorf(`%s <- forbidden; use "syncutil.{,RW}Mutex" instead`, s) | ||
}); err != nil { | ||
t.Error(err) | ||
|
@@ -187,6 +218,7 @@ func TestStyle(t *testing.T) { | |
|
||
t.Run("TestTodoStyle", func(t *testing.T) { | ||
t.Parallel() | ||
// TODO(tamird): enforce presence of name. | ||
cmd, stderr, filter, err := dirCmd(pkg.Dir, "git", "grep", "-nE", `\sTODO\([^)]*\)[^:]`, "--", "*.go") | ||
if err != nil { | ||
t.Fatal(err) | ||
|
@@ -211,7 +243,23 @@ func TestStyle(t *testing.T) { | |
|
||
t.Run("TestTimeutil", func(t *testing.T) { | ||
t.Parallel() | ||
cmd, stderr, filter, err := dirCmd(pkg.Dir, "git", "grep", "-nE", `time\.(Now|Since)`, "--", "*.go") | ||
cmd, stderr, filter, err := dirCmd( | ||
pkg.Dir, | ||
"git", | ||
"grep", | ||
"-nE", | ||
`\btime\.(Now|Since)`, | ||
"--", | ||
"*.go", | ||
":!util/log/clog_test.go", | ||
":!util/log/clog.go", | ||
":!util/log/crash_reporting.go", | ||
":!util/log/file_test.go", | ||
":!util/timeutil/now_unix.go", | ||
":!util/timeutil/now_windows.go", | ||
":!util/tracing/tracer_span.go", | ||
":!util/tracing/tracer.go", | ||
) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
@@ -220,10 +268,7 @@ func TestStyle(t *testing.T) { | |
t.Fatal(err) | ||
} | ||
|
||
if err := stream.ForEach(stream.Sequence( | ||
filter, | ||
stream.GrepNot(`^util/(log|syncutil|timeutil|tracing)/\w+\.go\b`), | ||
), func(s string) { | ||
if err := stream.ForEach(filter, func(s string) { | ||
t.Errorf(`%s <- forbidden; use "timeutil" instead`, s) | ||
}); err != nil { | ||
t.Error(err) | ||
|
@@ -238,7 +283,18 @@ func TestStyle(t *testing.T) { | |
|
||
t.Run("TestGrpc", func(t *testing.T) { | ||
t.Parallel() | ||
cmd, stderr, filter, err := dirCmd(pkg.Dir, "git", "grep", "-nE", `grpc.NewServer\([^)]*\)`, "--", "*.go") | ||
cmd, stderr, filter, err := dirCmd( | ||
pkg.Dir, | ||
"git", | ||
"grep", | ||
"-nE", | ||
`\bgrpc\.NewServer\(`, | ||
"--", | ||
"*.go", | ||
":!rpc/context_test.go", | ||
":!rpc/context.go", | ||
":!util/grpcutil/grpc_util_test.go", | ||
) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
@@ -247,11 +303,7 @@ func TestStyle(t *testing.T) { | |
t.Fatal(err) | ||
} | ||
|
||
if err := stream.ForEach(stream.Sequence( | ||
filter, | ||
stream.GrepNot(`^rpc/context(_test)?\.go\b`), | ||
stream.GrepNot(`^util/grpcutil/`), | ||
), func(s string) { | ||
if err := stream.ForEach(filter, func(s string) { | ||
t.Errorf(`%s <- forbidden; use "rpc.NewServer" instead`, s) | ||
}); err != nil { | ||
t.Error(err) | ||
|
@@ -266,7 +318,17 @@ func TestStyle(t *testing.T) { | |
|
||
t.Run("TestProtoClone", func(t *testing.T) { | ||
t.Parallel() | ||
cmd, stderr, filter, err := dirCmd(pkg.Dir, "git", "grep", "-nE", `\.Clone\([^)]+\)`, "--", "*.go") | ||
cmd, stderr, filter, err := dirCmd( | ||
pkg.Dir, | ||
"git", | ||
"grep", | ||
"-nE", | ||
`\.Clone\([^)]`, | ||
"--", | ||
"*.go", | ||
":!util/protoutil/clone_test.go", | ||
":!util/protoutil/clone.go", | ||
) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
@@ -277,8 +339,7 @@ func TestStyle(t *testing.T) { | |
|
||
if err := stream.ForEach(stream.Sequence( | ||
filter, | ||
stream.GrepNot(`protoutil\.Clone\([^)]+\)`), | ||
stream.GrepNot(`^util/protoutil/clone(_test)?\.go\b`), | ||
stream.GrepNot(`protoutil\.Clone\(`), | ||
), func(s string) { | ||
t.Errorf(`%s <- forbidden; use "protoutil.Clone" instead`, s) | ||
}); err != nil { | ||
|
@@ -294,7 +355,17 @@ func TestStyle(t *testing.T) { | |
|
||
t.Run("TestProtoMarshal", func(t *testing.T) { | ||
t.Parallel() | ||
cmd, stderr, filter, err := dirCmd(pkg.Dir, "git", "grep", "-nE", `\.Marshal\([^)]+\)`, "--", "*.go") | ||
cmd, stderr, filter, err := dirCmd( | ||
pkg.Dir, | ||
"git", | ||
"grep", | ||
"-nE", | ||
`\.Marshal\(`, | ||
"--", | ||
"*.go", | ||
":!util/protoutil/marshal.go", | ||
":!settings/settings_test.go", | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This pattern really seems to deserve a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eh, I'm not sure I agree that there's much benefit to the indirection. Feel free to follow up if you feel strongly enough. |
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
@@ -305,8 +376,7 @@ func TestStyle(t *testing.T) { | |
|
||
if err := stream.ForEach(stream.Sequence( | ||
filter, | ||
stream.GrepNot(`(json|yaml|protoutil|Field)\.Marshal`), | ||
stream.GrepNot(`^util/protoutil/marshal(_test)?\.go\b`), | ||
stream.GrepNot(`(json|yaml|protoutil|\.Field)\.Marshal\(`), | ||
), func(s string) { | ||
t.Errorf(`%s <- forbidden; use "protoutil.Marshal" instead`, s) | ||
}); err != nil { | ||
|
@@ -322,7 +392,16 @@ func TestStyle(t *testing.T) { | |
|
||
t.Run("TestProtoUnmarshal", func(t *testing.T) { | ||
t.Parallel() | ||
cmd, stderr, filter, err := dirCmd(pkg.Dir, "git", "grep", "-nE", `\.Unmarshal\([^)]+\)`, "--", "*.go") | ||
cmd, stderr, filter, err := dirCmd( | ||
pkg.Dir, | ||
"git", | ||
"grep", | ||
"-nE", | ||
`\.Unmarshal\(`, | ||
"--", | ||
"*.go", | ||
":!*.pb.go", | ||
) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
@@ -333,8 +412,7 @@ func TestStyle(t *testing.T) { | |
|
||
if err := stream.ForEach(stream.Sequence( | ||
filter, | ||
stream.GrepNot(`(json|jsonpb|yaml|proto)\.Unmarshal`), | ||
stream.GrepNot(`\.pb\.go\b`), | ||
stream.GrepNot(`(json|jsonpb|yaml|proto)\.Unmarshal\(`), | ||
), func(s string) { | ||
t.Errorf(`%s <- forbidden; use "proto.Unmarshal" instead`, s) | ||
}); err != nil { | ||
|
@@ -649,6 +727,9 @@ func TestStyle(t *testing.T) { | |
// TODO(tamird): replace this with errcheck.NewChecker() when | ||
// https://github.com/dominikh/go-tools/issues/57 is fixed. | ||
t.Run("TestErrCheck", func(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("short flag") | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any particular reason you're sidecar-ing this bit? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this just got missed earlier; |
||
// errcheck uses 1GB of ram (as of 2017-02-18), so don't parallelize it. | ||
cmd, stderr, filter, err := dirCmd( | ||
pkg.Dir, | ||
|
@@ -679,6 +760,9 @@ func TestStyle(t *testing.T) { | |
}) | ||
|
||
t.Run("TestReturnCheck", func(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("short flag") | ||
} | ||
// returncheck uses 1GB of ram (as of 2017-02-18), so don't parallelize it. | ||
cmd, stderr, filter, err := dirCmd(pkg.Dir, "returncheck", pkgScope) | ||
if err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't in
pkg
, is it? Why would it get picked up?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
git grep
doesn't care about the directory you're in, or at least it doesn't when you specify'*.go'
.