Skip to content

Commit

Permalink
Fix go generate ./... issues under root
Browse files Browse the repository at this point in the history
Running `go generate ./...` on current main fails for a couple of reasons

(1) The go:generate command in /mockgen/internal/tests/aux_imports_embedded_interface/bugreport.go
has an -aux_file argument that specifies a package `faux` that is not in the
stdlib and therefore not discoverable in GOROOT. Fixing this with a fully
qualified path causes another failure that is known and documented
in mockgen/internal/tests/aux_imports_embedded_interface/README.md.

Because this failure is known, I've opted to comment out the command as
documentation for reproducing the error.

(2) mockgen/internal/tests/internal_pkg/generate.go attempts to mock an
interface package with reflect mode and runs into fundamental go
restrictions of `go build` with internal package paths outside of the
internal package scope allowed by go.

I've removed the generate directive here since this isn't a supported feature
as the implementation of reflect mode creates a tempoorary directory and
invokes `go build` there.

ref: github.com/uber-go/mock/blob/8cd1a4cf46a6b1cf232b6862f2f11e81fe77a4e4/mockgen/reflect.go#L135
ref: github.com/golang/mock/issues/29

Not a failure fix but I've also changed type aliases of `any` back to type
aliases of `interface {}`. Looking at the parsing logic, github.com/uber-go/mock/blob/8cd1a4cf46a6b1cf232b6862f2f11e81fe77a4e4/mockgen/parse.go#L752
`interface{}` -> `any` causes *ast.TypeSpec to no longer type check to an *ast.InterfaceType
and ends up removing generate mock code meant to test against regressions.

ref: github.com//pull/48
  • Loading branch information
r-hang committed Sep 5, 2023
1 parent 7adc635 commit d6d1e04
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion mockgen/internal/tests/add_generate_directive/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bugreport

//go:generate mockgen -aux_files faux=faux/faux.go -destination bugreport_mock.go -package bugreport -source=bugreport.go Example
// Reproduce the issue described in the README.md with
// $ go:generate mockgen -aux_files faux=faux/faux.go -destination bugreport_mock.go -package bugreport -source=bugreport.go Example

import (
"log"
Expand Down
2 changes: 1 addition & 1 deletion mockgen/internal/tests/copyright_file/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package empty_interface

//go:generate mockgen -package empty_interface -destination mock.go -source input.go -copyright_file=mock_copyright_header

type Empty any
type Empty interface{} // migrating interface{} -> any does not resolve to an interface type dropping test generation added in b391ab3
4 changes: 2 additions & 2 deletions mockgen/internal/tests/defined_import_local_name/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mockgen/internal/tests/empty_interface/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package empty_interface

//go:generate mockgen -package empty_interface -destination mock.go -source input.go

type Empty any
type Empty interface{} // migrating interface{} -> any does not resolve to an interface type.
1 change: 0 additions & 1 deletion mockgen/internal/tests/internal_pkg/generate.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package test

//go:generate mockgen -destination subdir/internal/pkg/reflect_output/mock.go go.uber.org/mock/mockgen/internal/tests/internal_pkg/subdir/internal/pkg Intf
//go:generate mockgen -source subdir/internal/pkg/input.go -destination subdir/internal/pkg/source_output/mock.go

0 comments on commit d6d1e04

Please sign in to comment.