Skip to content

Commit

Permalink
Add option to fail on empty results (#41)
Browse files Browse the repository at this point in the history
Co-authored-by: Norman Gehrsitz <[email protected]>
  • Loading branch information
ngehrsitz and Norman Gehrsitz authored Oct 26, 2023
1 parent 95a46a4 commit b3c7ff1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
30 changes: 16 additions & 14 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,25 @@ import (
)

type config struct {
onlyDegression bool
threshold float64
base string
compare []string
benchCmd string
benchArgs []string
gitPath string
onlyDegression bool
failWithoutResults bool
threshold float64
base string
compare []string
benchCmd string
benchArgs []string
gitPath string
}

func newConfig(c *cli.Context) config {
return config{
onlyDegression: c.Bool("only-degression"),
threshold: c.Float64("threshold"),
base: c.String("base"),
compare: strings.Split(c.String("compare"), ","),
benchCmd: c.String("bench-cmd"),
benchArgs: strings.Fields(c.String("bench-args")),
gitPath: c.String("git-path"),
onlyDegression: c.Bool("only-degression"),
failWithoutResults: c.Bool("fail-without-results"),
threshold: c.Float64("threshold"),
base: c.String("base"),
compare: strings.Split(c.String("compare"), ","),
benchCmd: c.String("bench-cmd"),
benchArgs: strings.Fields(c.String("bench-args")),
gitPath: c.String("git-path"),
}
}
13 changes: 13 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func main() {
Name: "only-degression",
Usage: "Show only benchmarks with worse score",
},
&cli.BoolFlag{
Name: "fail-without-results",
Usage: "Exit with an error if the parsing fails",
},
&cli.Float64Flag{
Name: "threshold",
Usage: "The program fails if the benchmark gets worse than the threshold",
Expand Down Expand Up @@ -146,6 +150,15 @@ func run(c config) error {
return xerrors.Errorf("failed to run a benchmark: %w", err)
}

if c.failWithoutResults {
if len(prevSet) == 0 {
return xerrors.New("could not parse any benchmark results for the previous commit")
}
if len(headSet) == 0 {
return xerrors.New("could not parse any benchmark results for the current commit")
}
}

var ratios []result
var rows [][]string
for benchName, headBenchmarks := range headSet {
Expand Down

0 comments on commit b3c7ff1

Please sign in to comment.