Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate benchmark for functions #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions gotests.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ import (

// Options provides custom filters and parameters for generating tests.
type Options struct {
Only *regexp.Regexp // Includes only functions that match.
Exclude *regexp.Regexp // Excludes functions that match.
Exported bool // Include only exported methods
PrintInputs bool // Print function parameters in error messages
Subtests bool // Print tests using Go 1.7 subtests
Importer func() types.Importer // A custom importer.
TemplateDir string // Path to custom template set
Only *regexp.Regexp // Includes only functions that match.
Exclude *regexp.Regexp // Excludes functions that match.
Exported bool // Include only exported methods
PrintInputs bool // Print function parameters in error messages
Subtests bool // Print tests using Go 1.7 subtests
Importer func() types.Importer // A custom importer.
TemplateDir string // Path to custom template set
WithBenchmark bool // Generate benchmark for function and methods
}

// A GeneratedTest contains information about a test file with generated tests.
Expand Down Expand Up @@ -115,9 +116,10 @@ func generateTest(src models.Path, files []models.Path, opt *Options) (*Generate
return nil, nil
}
b, err := output.Process(h, funcs, &output.Options{
PrintInputs: opt.PrintInputs,
Subtests: opt.Subtests,
TemplateDir: opt.TemplateDir,
PrintInputs: opt.PrintInputs,
Subtests: opt.Subtests,
TemplateDir: opt.TemplateDir,
WithBenchmark: opt.WithBenchmark,
})
if err != nil {
return nil, fmt.Errorf("output.Process: %v", err)
Expand Down
16 changes: 9 additions & 7 deletions gotests/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ import (
)

var (
onlyFuncs = flag.String("only", "", `regexp. generate tests for functions and methods that match only. Takes precedence over -all`)
exclFuncs = flag.String("excl", "", `regexp. generate tests for functions and methods that don't match. Takes precedence over -only, -exported, and -all`)
exportedFuncs = flag.Bool("exported", false, `generate tests for exported functions and methods. Takes precedence over -only and -all`)
allFuncs = flag.Bool("all", false, "generate tests for all functions and methods")
printInputs = flag.Bool("i", false, "print test inputs in error messages")
writeOutput = flag.Bool("w", false, "write output to (test) files instead of stdout")
templateDir = flag.String("template_dir", "", `optional. Path to a directory containing custom test code templates`)
onlyFuncs = flag.String("only", "", `regexp. generate tests for functions and methods that match only. Takes precedence over -all`)
exclFuncs = flag.String("excl", "", `regexp. generate tests for functions and methods that don't match. Takes precedence over -only, -exported, and -all`)
exportedFuncs = flag.Bool("exported", false, `generate tests for exported functions and methods. Takes precedence over -only and -all`)
allFuncs = flag.Bool("all", false, "generate tests for all functions and methods")
printInputs = flag.Bool("i", false, "print test inputs in error messages")
writeOutput = flag.Bool("w", false, "write output to (test) files instead of stdout")
templateDir = flag.String("template_dir", "", `optional. Path to a directory containing custom test code templates`)
withBenchmarks = flag.Bool("b", false, "generate benchmarks for functions and methods")
)

// nosubtests is always set to default value of true when Go < 1.7.
Expand All @@ -62,5 +63,6 @@ func main() {
Subtests: !nosubtests,
WriteOutput: *writeOutput,
TemplateDir: *templateDir,
WithBenchmark: *withBenchmarks,
})
}
14 changes: 8 additions & 6 deletions gotests/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Options struct {
Subtests bool // Print tests using Go 1.7 subtests
WriteOutput bool // Write output to test file(s).
TemplateDir string // Path to custom template set
WithBenchmark bool // Print benchmarks.
}

// Generates tests for the Go files defined in args with the given options.
Expand Down Expand Up @@ -63,12 +64,13 @@ func parseOptions(out io.Writer, opt *Options) *gotests.Options {
return nil
}
return &gotests.Options{
Only: onlyRE,
Exclude: exclRE,
Exported: opt.ExportedFuncs,
PrintInputs: opt.PrintInputs,
Subtests: opt.Subtests,
TemplateDir: opt.TemplateDir,
Only: onlyRE,
Exclude: exclRE,
Exported: opt.ExportedFuncs,
PrintInputs: opt.PrintInputs,
Subtests: opt.Subtests,
TemplateDir: opt.TemplateDir,
WithBenchmark: opt.WithBenchmark,
}
}

Expand Down
Loading