-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
101 lines (85 loc) · 2.19 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"log"
"os"
internal "github.com/rwojsznis/rspec-sanity/internal"
"github.com/urfave/cli/v2"
)
func main() {
settings := internal.Settings{}
app := &cli.App{
Usage: "a tool that helps you to ticket flaky tests in your RSpec suite",
ArgsUsage: "[test files or directories]",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "skip-rerun",
Usage: "Do not re-run the tests (also skips reporting)",
Destination: &settings.SkipRerun,
},
&cli.StringFlag{
Name: "config",
DefaultText: ".rspec-sanity.toml",
Usage: "Load configuration from `FILE`",
Destination: &settings.ConfigPath,
Value: ".rspec-sanity.toml",
},
},
Commands: []*cli.Command{
{
Name: "verify",
Usage: "verify configuration - will try to add a test issue report to Jira/Github",
Action: func(cCtx *cli.Context) error {
err := settings.Load(cCtx)
if err != nil {
return err
}
reporter := settings.Config.GetReporter()
err = reporter.Init()
if err != nil {
return err
}
return reporter.Verify()
},
},
{
Name: "run",
Usage: "run rspec according to the configuration",
Action: func(cCtx *cli.Context) error {
err := settings.Load(cCtx)
if err != nil {
return err
}
err = settings.Validate()
if err != nil {
return err
}
runner := internal.Runner{
Settings: &settings,
}
runnerStatus := runner.Run()
if runnerStatus.HasFlakies() {
// we will crash app on error here; otherwise debugging potential
// issues in reporter itself will be nightmare
reporter := settings.Config.GetReporter()
err = reporter.Init()
if err != nil {
return err
}
err = internal.ReportFlakies(reporter, runnerStatus.FlakyExamples)
if err != nil {
return err
}
} else {
log.Println("[rspec-sanity] No flaky examples found")
}
// if nothing failed during reporting - propagate exit code from rspec
os.Exit(runnerStatus.StatusCode)
return nil
},
},
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}