Skip to content

Commit

Permalink
gopls/internal/test/marker: reject "module testdata"
Browse files Browse the repository at this point in the history
Updates golang/go#65406

Change-Id: I1ce4e4d94f118c4b51dc52d624d90e2f7e05f048
Reviewed-on: https://go-review.googlesource.com/c/tools/+/559457
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
adonovan committed Feb 1, 2024
1 parent c07f927 commit 2e15dc7
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 19 deletions.
9 changes: 9 additions & 0 deletions gopls/internal/test/marker/marker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,15 @@ func loadMarkerTest(name string, content []byte) (*markerTest, error) {
return nil, fmt.Errorf("%s:%d: unwanted space before marker (// @)", file.Name, line)
}

// The 'go list' command doesn't work correct with modules named
// testdata", so don't allow it as a module name (golang/go#65406).
// (Otherwise files within it will end up in an ad hoc
// package, "command-line-arguments/$TMPDIR/...".)
if filepath.Base(file.Name) == "go.mod" &&
bytes.Contains(file.Data, []byte("module testdata")) {
return nil, fmt.Errorf("'testdata' is not a valid module name")
}

test.notes = append(test.notes, notes...)
test.files[file.Name] = file.Data
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ It is a regression test for bug #63287 in which
the final paramater's "..." would go missing.

-- go.mod --
module testdata
module example.com
go 1.18

-- a/a.go --
Expand Down
2 changes: 1 addition & 1 deletion gopls/internal/test/marker/testdata/codeaction/inline.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
This is a minimal test of the refactor.inline code action.

-- go.mod --
module testdata/codeaction
module example.com/codeaction
go 1.18

-- a/a.go --
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Test of an inlining failure due to an ill-typed input program (#64558).

-- go.mod --
module testdata
module example.com
go 1.18

-- a/a.go --
Expand Down
10 changes: 5 additions & 5 deletions gopls/internal/test/marker/testdata/hover/methods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Observe that:
- only accessible methods are shown.

-- go.mod --
module testdata
module example.com

-- lib/lib.go --
package lib
Expand All @@ -31,7 +31,7 @@ func (s *S) pb() {}
-- a/a.go --
package a

import "testdata/lib"
import "example.com/lib"

var _ lib.I //@hover("I", "I", I)
var _ lib.J //@hover("J", "J", J)
Expand All @@ -50,13 +50,13 @@ type I interface {
func (lib.J) C()
```

[`lib.I` on pkg.go.dev](https://pkg.go.dev/testdata/lib#I)
[`lib.I` on pkg.go.dev](https://pkg.go.dev/example.com/lib#I)
-- @J --
```go
type J interface{ C() }
```

[`lib.J` on pkg.go.dev](https://pkg.go.dev/testdata/lib#J)
[`lib.J` on pkg.go.dev](https://pkg.go.dev/example.com/lib#J)
-- @S --
```go
type S struct{ I }
Expand All @@ -68,4 +68,4 @@ func (lib.J) C()
func (s *lib.S) PA()
```

[`lib.S` on pkg.go.dev](https://pkg.go.dev/testdata/lib#S)
[`lib.S` on pkg.go.dev](https://pkg.go.dev/example.com/lib#S)
8 changes: 4 additions & 4 deletions gopls/internal/test/marker/testdata/rename/doclink.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
This test checks that doc links are also handled correctly (golang/go#64495).

-- go.mod --
module testdata
module example.com

go 1.21

Expand Down Expand Up @@ -35,7 +35,7 @@ func (E[T]) Foo() {} //@rename("Foo", "Bar", EFooToEBar)
-- b/b.go --
package b

import aa "testdata/a" //@rename("aa", "a", pkgRename)
import aa "example.com/a" //@rename("aa", "a", pkgRename)

// FooBar just for test [aa.Foo] [aa.A] [aa.B] [aa.C] [aa.C.F] [aa.C.PF]
// reference pointer type [*aa.D]
Expand Down Expand Up @@ -124,8 +124,8 @@ func FooBar() {
+// FooBar just for test [aa.Foo] [aa.A] [aa.B] [aa.C] [aa.C.F] [aa.C.PFF]
-- @pkgRename/b/b.go --
@@ -3 +3 @@
-import aa "testdata/a" //@rename("aa", "a", pkgRename)
+import "testdata/a" //@rename("aa", "a", pkgRename)
-import aa "example.com/a" //@rename("aa", "a", pkgRename)
+import "example.com/a" //@rename("aa", "a", pkgRename)
@@ -5,3 +5,3 @@
-// FooBar just for test [aa.Foo] [aa.A] [aa.B] [aa.C] [aa.C.F] [aa.C.PF]
-// reference pointer type [*aa.D]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ the server's Signature method never returns an actual error,
so the best we can assert is that there is no result.

-- go.mod --
module testdata
module example.com
go 1.18

-- a/a.go --
Expand Down
12 changes: 6 additions & 6 deletions gopls/internal/test/marker/testdata/suggestedfix/issue65024.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Regression test for #65024, "incorrect package qualification when
Regression example.com for #65024, "incorrect package qualification when
stubbing method in v2 module".

The second test (a-a) ensures that we don't use path-based heuristics
to guess the PkgName of an import.

-- a/v2/go.mod --
module testdata/a/v2
module example.com/a/v2
go 1.18

-- a/v2/a.go --
Expand All @@ -18,7 +18,7 @@ type T struct {}
-- a/v2/b/b.go --
package b

import "testdata/a/v2"
import "example.com/a/v2"

type B struct{}

Expand All @@ -40,7 +40,7 @@ var _ a.I = &B{} //@ suggestedfix("&B{}", re"does not implement", out)
// It won't do to use it as an identifier.
// The correct name is the one in the package decl,
// which in this case is not what the path heuristic would guess.
module testdata/a-a/v2
module example.com/a-a/v2
go 1.18

-- a-a/v2/a.go --
Expand All @@ -61,12 +61,12 @@ var _ I = &B{} //@ suggestedfix("&B{}", re"does not implement", out2)

-- a-a/v2/b/import-a-I.go --
package b
import "testdata/a-a/v2"
import "example.com/a-a/v2"
type I = a.I

-- @out2/a-a/v2/b/b.go --
@@ -3 +3,2 @@
+import a "testdata/a-a/v2"
+import a "example.com/a-a/v2"
+
@@ -7 +9,5 @@
+// F implements a.I.
Expand Down

0 comments on commit 2e15dc7

Please sign in to comment.