-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
73 lines (65 loc) · 1.44 KB
/
main.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"errors"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"strings"
"sync"
"github.com/whytheplatypus/reagent/experiment"
)
var exitCode = 0
var errBadStringMapVar = errors.New("Variables must be of the form key=value")
type stringMapVar map[string]string
func (av stringMapVar) String() string {
return ""
}
func (av stringMapVar) Set(s string) error {
args := strings.SplitN(s, "=", 2)
if len(args) != 2 {
return errBadStringMapVar
}
av[args[0]] = args[1]
return nil
}
func main() {
flags := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
flags.Usage = func() {
fmt.Fprintf(flags.Output(), "Usage of %s:\n %s [flags] [files]\nFlags:\n", os.Args[0], os.Args[0])
flags.PrintDefaults()
}
vars := stringMapVar{}
var verbose bool
flags.BoolVar(&verbose, "v", false, "Enable for verbose logging")
flags.Var(&vars, "var", "Variables to use in the rendering of test files. Must be of the form key=value")
flags.Parse(os.Args[1:])
tf := flags.Args()
if verbose {
log.SetFlags(log.LstdFlags)
} else {
log.SetOutput(ioutil.Discard)
}
var wg sync.WaitGroup
for _, f := range tf {
wg.Add(1)
go func(f string) {
defer wg.Done()
t, err := experiment.NewTrial(f, vars, f)
if err != nil {
exitCode = 1
fmt.Println(t.Name, err)
return
}
if err := t.Run(); err != nil {
exitCode = 1
log.Println(t.Name, err)
return
}
log.Println("PASS:", f)
}(f)
}
wg.Wait()
os.Exit(exitCode)
}