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

build: show failures when running tests #873

Merged
merged 6 commits into from
Aug 24, 2019
Merged
Changes from 4 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
37 changes: 25 additions & 12 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"bufio"
"bytes"
"fmt"
"github.com/urfave/cli"
"io/ioutil"
"log"
"os"
"os/exec"
"strings"

"github.com/urfave/cli"
)

var packages = []string{"cli", "altsrc"}
Expand Down Expand Up @@ -51,8 +52,23 @@ func main() {
}
}

func runCmd(args ...string) error {
var cmd *exec.Cmd
if len(args) > 1 {
cmd = exec.Command(args[0], args[1:]...)
} else {
cmd = exec.Command(args[0])
}
coilysiren marked this conversation as resolved.
Show resolved Hide resolved

cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
coilysiren marked this conversation as resolved.
Show resolved Hide resolved

return cmd.Run()
}

func VetActionFunc(_ *cli.Context) error {
return exec.Command("go", "vet").Run()
return runCmd("go", "vet")
}

func TestActionFunc(c *cli.Context) error {
Expand All @@ -67,10 +83,7 @@ func TestActionFunc(c *cli.Context) error {

coverProfile := fmt.Sprintf("--coverprofile=%s.coverprofile", pkg)

err := exec.Command(
"go", "test", "-v", coverProfile, packageName,
).Run()

err := runCmd("go", "test", "-v", coverProfile, packageName)
if err != nil {
return err
}
Expand Down Expand Up @@ -142,16 +155,16 @@ func GfmrunActionFunc(_ *cli.Context) error {
return err
}

return exec.Command("gfmrun", "-c", fmt.Sprint(counter), "-s", "README.md").Run()
return runCmd("gfmrun", "-c", fmt.Sprint(counter), "-s", "README.md")
}

func TocActionFunc(_ *cli.Context) error {
err := exec.Command("node_modules/.bin/markdown-toc", "-i", "README.md").Run()
err := runCmd("node_modules/.bin/markdown-toc", "-i", "README.md")
if err != nil {
return err
}

err = exec.Command("git", "diff", "--exit-code").Run()
err = runCmd("git", "diff", "--exit-code")
if err != nil {
return err
}
Expand All @@ -160,17 +173,17 @@ func TocActionFunc(_ *cli.Context) error {
}

func GenActionFunc(_ *cli.Context) error {
err := exec.Command("go", "generate", "flag-gen/main.go").Run()
err := runCmd("go", "generate", "flag-gen/main.go")
if err != nil {
return err
}

err = exec.Command("go", "generate", "cli.go").Run()
err = runCmd("go", "generate", "cli.go")
if err != nil {
return err
}

err = exec.Command("git", "diff", "--exit-code").Run()
err = runCmd("git", "diff", "--exit-code")
if err != nil {
return err
}
Expand Down