Closed TimVosch closed 1 year ago
Expected error message in the TestParseError
test is couldn't load source package: ~/moq/pkg/moq/testpackages/_parseerror/service/service.go:3:8: could not import github.com/matryer/notexist (invalid package name: "")
.
Not sure why the error is couldn't load source package: err: exit status 1: stderr: go build github.com/matryer/notexist: service.go:3:8: cannot find package "." in: ~/moq/pkg/moq/testpackages/vendor/github.com/matryer/notexist
only on Go 1.19.
~Hmm, this also appears to happen on the main branch. I expect it's an issue unrelated to this PR. I'll see if I can find something.~
Edit: Actually installing the moq
package in the docker container runs the tests on main succesfully now, but only for <= 1.19.9
docker run --rm -it -v `pwd`:/project --workdir /project golang:1.19.0 sh -c 'go version && git --version && go install -buildvcs=false . && go test ./...'
Specifically version 1.19.10 does not work. All minor revisions below that work. Since it was released just two weeks ago, that is why it probably wasn't picked up earlier. I am going through the changelog to see why. I expected the error message just changed and the test needs an update.
docker run --rm -it -v `pwd`:/project --workdir /project golang:1.19.10 sh -c 'git -v && go install -buildvcs=false . && go test ./...'
Edit 2: Between go 1.19.9 and 1.19.10 the following change happened. I expect that the test should expect a build error instead of the import error, but only for go 1.19.10.
diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go
index c24d210711..567f045922 100644
--- a/src/cmd/go/internal/work/exec.go
+++ b/src/cmd/go/internal/work/exec.go
@@ -528,6 +528,12 @@ func (b *Builder) build(ctx context.Context, a *Action) (err error) {
b.Print(a.Package.ImportPath + "\n")
}
+ if p.Error != nil {
+ // Don't try to build anything for packages with errors. There may be a
+ // problem with the inputs that makes the package unsafe to build.
+ return p.Error
+ }
+
if a.Package.BinaryOnly {
p.Stale = true
p.StaleReason = "binary-only packages are no longer supported"
@sudo-suhas I am unsure what to do with this, do you have an idea?
We can add an additional clause for the error string check to cover errors from both Go 1.18 and Go 1.19.
I updated the test to also check for stderr: go build github.com/matryer/notexist
This change has been released in v0.3.2
🎉
Fixes missing imports and package prefixing to generic types. See #177
In the following example a method must be mocked which has a return parameter that has a generic type:
otherpackage.Foo
.Currently mocking
IFooBar
will result in a missingotherpackage
import and the package prefix toFoo
. Note:FoobarFunc: func() GenericBar[Foo]
instead ofFoobarFunc: func() GenericBar[otherpackage.Foo]
.This happens because of an invalid key lookup here, which returns an empty string
""
: internal/registry/var.goThis is fixed by checking if a Named Type has type arguments, and populating imports for those types. internal/registry/method_scope.go
A new golden test was added for this specific case.
Closes #177 Closes #190