Skip to content

Commit 28cd718

Browse files
dmitshurgopherbot
authored andcommitted
cmd/stringer: place test package files in a test module
The most natural environment for a modern Go package is to be inside a Go module. Do that so we can remove the temporary GO111MODULE=auto workaround without causing "0 packages matching ." errors. Fixes golang/go#30874. Change-Id: Ifdf7efee6fe54e3214a0cd72f8e3f496ecbca44d Reviewed-on: https://go-review.googlesource.com/c/tools/+/613135 LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Daniel Martí <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent d3a1606 commit 28cd718

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

cmd/stringer/endtoend_test.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,10 @@ func TestTags(t *testing.T) {
121121
t.Fatal(err)
122122
}
123123
}
124-
// Run stringer in the directory that contains the package files.
125-
// We cannot run stringer in the current directory for the following reasons:
126-
// - Versions of Go earlier than Go 1.11, do not support absolute directories as a pattern.
127-
// - When the current directory is inside a go module, the path will not be considered
128-
// a valid path to a package.
124+
// Run stringer in the directory that contains the module that contains the package files.
125+
if err := os.WriteFile(filepath.Join(dir, "go.mod"), []byte("module test\n"), 0o600); err != nil {
126+
t.Fatal(err)
127+
}
129128
err := runInDir(t, dir, stringer, "-type", "Const", ".")
130129
if err != nil {
131130
t.Fatal(err)
@@ -167,7 +166,10 @@ func TestConstValueChange(t *testing.T) {
167166
t.Fatal(err)
168167
}
169168
stringSource := filepath.Join(dir, "day_string.go")
170-
// Run stringer in the directory that contains the package files.
169+
// Run stringer in the directory that contains the module that contains the package files.
170+
if err := os.WriteFile(filepath.Join(dir, "go.mod"), []byte("module test\n"), 0o600); err != nil {
171+
t.Fatal(err)
172+
}
171173
err = runInDir(t, dir, stringer, "-type", "Day", "-output", stringSource)
172174
if err != nil {
173175
t.Fatal(err)
@@ -388,7 +390,6 @@ func runInDir(t testing.TB, dir, name string, arg ...string) error {
388390
t.Helper()
389391
cmd := testenv.Command(t, name, arg...)
390392
cmd.Dir = dir
391-
cmd.Env = append(os.Environ(), "GO111MODULE=auto")
392393
out, err := cmd.CombinedOutput()
393394
if len(out) > 0 {
394395
t.Logf("%s", out)

0 commit comments

Comments
 (0)