Skip to content

Commit

Permalink
Fix call on path (#36)
Browse files Browse the repository at this point in the history
Signed-off-by: Davide Petilli <davide@petilli.me>
  • Loading branch information
k3rn31 committed Jul 22, 2022
1 parent 62c772e commit a44e017
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
6 changes: 5 additions & 1 deletion cmd/gremlins/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ var (
)

func main() {
var exitCode int
defer func() {
os.Exit(exitCode)
}()
log.Init(os.Stdout)
err := cmd.Execute(buildVersion(version, date, builtBy))
if err != nil {
log.Errorln(err)
os.Exit(1)
exitCode = 1
}
}

Expand Down
23 changes: 15 additions & 8 deletions cmd/unleash.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package cmd

import (
"fmt"
"github.com/k3rn31/gremlins/coverage"
"github.com/k3rn31/gremlins/log"
"github.com/k3rn31/gremlins/mutator"
Expand All @@ -41,16 +42,22 @@ func newUnleashCmd() *unleashCmd {
Args: cobra.MaximumNArgs(1),
Short: "Executes the mutation testing process",
Long: `Unleashes the gremlins and performs mutation testing on a Go module.`,
Run: func(cmd *cobra.Command, args []string) {
currentPath := "."
RunE: func(cmd *cobra.Command, args []string) error {
var currentPath string
if len(args) > 0 {
currentPath = args[0]
}
if currentPath != "." {
err := os.Chdir(currentPath)
if err != nil {
return err
}
currentPath = "."
}

workDir, err := ioutil.TempDir(os.TempDir(), "gremlins-")
if err != nil {
log.Errorf("impossible to create the workdir: %s", err)
os.Exit(1)
return fmt.Errorf("impossible to create the workdir: %w", err)
}
defer func(n string) {
err := os.RemoveAll(n)
Expand All @@ -61,14 +68,12 @@ func newUnleashCmd() *unleashCmd {

c, err := coverage.New(workDir, currentPath, coverage.WithBuildTags(buildTags))
if err != nil {
log.Errorf("directory %s does not contain main module\n", currentPath)
os.Exit(1)
return fmt.Errorf("directory %q does not contain main module: %w", currentPath, err)
}

p, err := c.Run()
if err != nil {
log.Errorln(err)
os.Exit(1)
return err
}

d := workdir.NewDealer(workDir, currentPath)
Expand All @@ -78,6 +83,8 @@ func newUnleashCmd() *unleashCmd {
results := mut.Run()

report.Do(results)

return nil
},
}

Expand Down

0 comments on commit a44e017

Please # to comment.