Skip to content

Commit

Permalink
fix: do not return errors for tests (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Jun 23, 2020
1 parent 4460d6a commit e95c7e3
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ import (
"github.com/spf13/cobra"
)

func check(err error) {
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "%v", err)
os.Exit(1)
}
}

// RootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Use: "go-acc <flags> <packages...>",
Expand Down Expand Up @@ -57,7 +64,6 @@ GO_TEST_BINARY="gotest"

var packages []string
var passthrough []string

for _, a := range args {
if len(a) == 0 {
continue
Expand All @@ -75,7 +81,7 @@ GO_TEST_BINARY="gotest"
c.Stdout = &buf
c.Stderr = &buf
if err := c.Run(); err != nil {
return fmt.Errorf("unable to run go list: %w", err)
check(fmt.Errorf("unable to run go list: %w", err))
}

var add []string
Expand Down Expand Up @@ -133,26 +139,20 @@ GO_TEST_BINARY="gotest"
c = exec.Command(gt[0], ca...)

stderr, err := c.StderrPipe()
if err != nil {
return err
}
check(err)

stdout, err := c.StdoutPipe()
if err != nil {
return err
}
check(err)

if err := c.Start(); err != nil {
return err
}
check(c.Start())

var wg sync.WaitGroup
wg.Add(2)
go scan(&wg, stderr)
go scan(&wg, stdout)

if err := c.Wait(); err != nil {
return err
}
check(c.Wait())
check(c.Start())

wg.Wait()
}
Expand All @@ -163,20 +163,17 @@ GO_TEST_BINARY="gotest"
}

p, err := ioutil.ReadFile(file)
if err != nil {
return err
}
check(err)

ps := strings.Split(string(p), "\n")
payload += strings.Join(ps[1:], "\n")
}

output, err := cmd.Flags().GetString("output")
if err != nil {
return err
}
check(err)

return ioutil.WriteFile(output, []byte(payload), 0644)
check(ioutil.WriteFile(output, []byte(payload), 0644))
return nil
},
}

Expand Down

0 comments on commit e95c7e3

Please sign in to comment.