diff --git a/Makefile b/Makefile index 7a6d4df..a6dd335 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ generate: go run ./cmd/minimock/minimock.go -i ./tests.actor -o ./tests/actor_mock.go go run ./cmd/minimock/minimock.go -i ./tests.formatterAlias -o ./tests/formatter_alias_mock.go go run ./cmd/minimock/minimock.go -i ./tests.formatterType -o ./tests/formatter_type_mock.go - go run ./cmd/minimock/minimock.go -i ./tests.reader -o ./tests/reader_mock.go + go run ./cmd/minimock/minimock.go -i ./tests.reader -o ./tests/reader_mock.go -gr ./bin: mkdir ./bin diff --git a/cmd/minimock/minimock.go b/cmd/minimock/minimock.go index 801ab0e..45fa916 100644 --- a/cmd/minimock/minimock.go +++ b/cmd/minimock/minimock.go @@ -15,7 +15,7 @@ import ( "text/template" "time" - minimock "github.com/gojuno/minimock/v3" + "github.com/gojuno/minimock/v3" "github.com/gojuno/minimock/v3/internal/types" "github.com/hexdigest/gowrap/generator" "github.com/hexdigest/gowrap/pkg" @@ -51,11 +51,12 @@ var helpers = template.FuncMap{ type ( options struct { - interfaces []interfaceInfo - noGenerate bool - suffix string - mockNames []string - packageNames []string + interfaces []interfaceInfo + noGenerate bool + suffix string + mockNames []string + packageNames []string + goGenerateGoRun bool } interfaceInfo struct { @@ -162,6 +163,7 @@ func run(opts *options) (err error) { "GenerateInstruction": !opts.noGenerate, "Version": version, "PackageName": packageName, + "GenerateGoRun": opts.goGenerateGoRun, }, Vars: map[string]interface{}{}, Funcs: helpers, @@ -382,6 +384,8 @@ func processArgs(args []string, stdout, stderr io.Writer) (*options, error) { fs := flag.NewFlagSet("", flag.ContinueOnError) fs.BoolVar(&opts.noGenerate, "g", false, "don't put go:generate instruction into the generated code") + fs.BoolVar(&opts.goGenerateGoRun, "gr", false, `changes go:generate line from "//go:generate minimock args..." to "//go:generate go run github.com/gojuno/minimock/v3/cmd/minimock", +useful while controlling minimock version with go mod`) fs.StringVar(&opts.suffix, "s", "_mock_test.go", "mock file suffix") input := fs.String("i", "*", "comma-separated names of the interfaces to mock, i.e fmt.Stringer,io.Reader\nuse io.* notation to generate mocks for all interfaces in the \"io\" package") diff --git a/go.mod b/go.mod index 0e6985b..0078d61 100644 --- a/go.mod +++ b/go.mod @@ -6,15 +6,15 @@ require ( github.com/pkg/errors v0.9.1 github.com/pmezard/go-difflib v1.0.0 github.com/stretchr/testify v1.8.4 - golang.org/x/tools v0.1.12 + golang.org/x/tools v0.6.0 google.golang.org/protobuf v1.30.0 ) require ( github.com/kr/text v0.2.0 // indirect - golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect - golang.org/x/sys v0.5.0 // indirect - golang.org/x/text v0.3.8 // indirect + golang.org/x/mod v0.8.0 // indirect + golang.org/x/sys v0.15.0 // indirect + golang.org/x/text v0.14.0 // indirect golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index ebe1077..4bc120e 100644 --- a/go.sum +++ b/go.sum @@ -21,14 +21,16 @@ github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XF github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= -golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= -golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f h1:GGU+dLjvlC3qDwqYgL6UgRmHXhOOgns0bZu2Ty5mm6U= golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/internal/templates/header.tmpl b/internal/templates/header.tmpl index 4f265a8..77a9f57 100644 --- a/internal/templates/header.tmpl +++ b/internal/templates/header.tmpl @@ -8,7 +8,11 @@ package {{$packageName}} {{if $.Options.HeaderVars.GenerateInstruction}} + {{if $.Options.HeaderVars.GenerateGoRun}} +//go:generate go run github.com/gojuno/minimock/v3/cmd/minimock -i {{$.SourcePackage.PkgPath}}.{{$.Options.InterfaceName}} -o {{$.Options.HeaderVars.OutputFile}} -n {{(title (index $.Vars "MockName"))}} -p {{ $packageName }} -gr + {{else}} //go:generate minimock -i {{$.SourcePackage.PkgPath}}.{{$.Options.InterfaceName}} -o {{$.Options.HeaderVars.OutputFile}} -n {{(title (index $.Vars "MockName"))}} -p {{ $packageName }} + {{end}} {{end}} import ( diff --git a/tests/reader_mock.go b/tests/reader_mock.go index 04decdd..72c00e7 100644 --- a/tests/reader_mock.go +++ b/tests/reader_mock.go @@ -2,7 +2,7 @@ package tests -//go:generate minimock -i github.com/gojuno/minimock/v3/tests.reader -o reader_mock.go -n ReaderMock -p tests +//go:generate go run github.com/gojuno/minimock/v3/cmd/minimock -i github.com/gojuno/minimock/v3/tests.reader -o reader_mock.go -n ReaderMock -p tests -gr import ( "sync"