forked from GeertJohan/fgt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfgt.go
59 lines (50 loc) · 976 Bytes
/
fgt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"fmt"
"io"
"os"
"os/exec"
"strings"
)
var anything bool
// writer that writes to wr and sets 'anything' bool on any data
type fgtWriter struct {
wr io.Writer
}
func (fgt *fgtWriter) Write(b []byte) (int, error) {
if len(b) > 0 {
anything = true
}
return fgt.wr.Write(b)
}
// fast go tester
func main() {
// check for valid args
if len(os.Args) < 2 {
fmt.Println("usage: fgt <cmd> <args>")
return
}
// prepare command
cmd := exec.Command(os.Args[1], os.Args[2:]...)
cmd.Stdin = os.Stdin
cmd.Stdout = &fgtWriter{
wr: os.Stdout,
}
cmd.Stderr = &fgtWriter{
wr: os.Stderr,
}
// run command, exit 1 on error
err := cmd.Run()
if err != nil && !strings.Contains(err.Error(), "exit status 1") {
fmt.Printf("error running command: %s\n", err)
os.Exit(1)
}
// exit 1 on no success
if !cmd.ProcessState.Success() {
os.Exit(1)
}
// exit 1 on anything being sent to stdout or stderr
if anything {
os.Exit(1)
}
}