Skip to content

Commit

Permalink
-s flag is back
Browse files Browse the repository at this point in the history
  • Loading branch information
hexdigest committed Jan 15, 2019
1 parent cd03294 commit 1a52590
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![Build Status](https://travis-ci.org/gojuno/minimock.svg?branch=master)](https://travis-ci.org/gojuno/minimock)
[![Go Report Card](https://goreportcard.com/badge/github.com/gojuno/minimock)](https://goreportcard.com/report/github.com/gojuno/minimock)
[![Coverage Status](https://coveralls.io/repos/github/gojuno/minimock/badge.svg?branch=master)](https://coveralls.io/github/gojuno/minimock?branch=master)
[![Release](https://img.shields.io/github/release/gojuno/minimock.svg)](https://github.com/gojuno/minimock/releases/latest)
[![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/avelino/awesome-go#testing)


Expand Down Expand Up @@ -41,6 +42,8 @@ go get github.com/gojuno/minimock/cmd/minimock
-o string
comma-separated destination file names or packages to put the generated mocks in,
by default the generated mock is placed in the source package directory
-s string
mock file suffix (default "_mock_test.go")
```

Let's say we have the following interface declaration in github.com/gojuno/minimock/tests package:
Expand Down
13 changes: 8 additions & 5 deletions cmd/minimock/minimock.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type (
options struct {
interfaces []interfaceInfo
noGenerate bool
suffix string
}

interfaceInfo struct {
Expand Down Expand Up @@ -91,18 +92,18 @@ func run(opts *options) (err error) {
},
}

if err := processPackage(gopts, interfaces, in.WriteTo); err != nil {
if err := processPackage(gopts, interfaces, in.WriteTo, opts.suffix); err != nil {
return err
}
}

return nil
}

func processPackage(opts generator.Options, interfaces []string, writeTo string) (err error) {
func processPackage(opts generator.Options, interfaces []string, writeTo, suffix string) (err error) {
for _, name := range interfaces {
opts.InterfaceName = name
opts.OutputFile, err = destinationFile(name, writeTo)
opts.OutputFile, err = destinationFile(name, writeTo, suffix)
if err != nil {
return errors.Wrapf(err, "failed to generate mock for %s", name)
}
Expand Down Expand Up @@ -139,7 +140,7 @@ func isGoFile(path string) (bool, error) {
return strings.HasSuffix(path, ".go") && !stat.IsDir(), nil
}

func destinationFile(interfaceName, writeTo string) (string, error) {
func destinationFile(interfaceName, writeTo, suffix string) (string, error) {
ok, err := isGoFile(writeTo)
if err != nil {
return "", err
Expand All @@ -150,7 +151,7 @@ func destinationFile(interfaceName, writeTo string) (string, error) {
if ok {
path = writeTo
} else {
path = filepath.Join(writeTo, minimock.CamelToSnake(interfaceName)+"_mock_test.go")
path = filepath.Join(writeTo, minimock.CamelToSnake(interfaceName)+suffix)
}

if !strings.HasPrefix(path, "/") && !strings.HasPrefix(path, ".") {
Expand Down Expand Up @@ -241,6 +242,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.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")
output := fs.String("o", "", "comma-separated destination file names or packages to put the generated mocks in,\nby default the generated mock is placed in the source package directory")
help := fs.Bool("h", false, "show this help message")
Expand Down

0 comments on commit 1a52590

Please sign in to comment.