Add -stub flag to stub func implementation (#132)

When a mock is generated with the flag enabled, it introduces the
following changes:
- Does not panic on calling the method without a mock implementation.
- Return zero values iff the implementation is not provided and the
  method has return parameters.

Co-authored-by: Scott Leuthaeuser <scott_leuthaeuser@homedepot.com>
This commit is contained in:
Suhas Karanth
2020-08-16 12:24:12 +05:30
committed by GitHub
parent 24883c20a6
commit 83ab8dd79f
6 changed files with 179 additions and 27 deletions

View File

@@ -17,6 +17,7 @@ type userFlags struct {
outFile string
pkgName string
formatter string
stubImpl bool
args []string
}
@@ -25,6 +26,8 @@ func main() {
flag.StringVar(&flags.outFile, "out", "", "output file (default stdout)")
flag.StringVar(&flags.pkgName, "pkg", "", "package name (default will infer)")
flag.StringVar(&flags.formatter, "fmt", "", "go pretty-printer: gofmt (default) or goimports")
flag.BoolVar(&flags.stubImpl, "stubImpl", false,
"return zero values when no mock implementation is provided, do not panic")
flag.Usage = func() {
fmt.Println(`moq [flags] source-dir interface [interface2 [interface3 [...]]]`)
@@ -59,6 +62,7 @@ func run(flags userFlags) error {
SrcDir: srcDir,
PkgName: flags.pkgName,
Formatter: flags.formatter,
StubImpl: flags.stubImpl,
})
if err != nil {
return err