mirror-to-gitea/vendor/github.com/onsi/ginkgo/config/config.go
vendor/github.com/onsi/ginkgo/config/config.goRaw
1/*
2Ginkgo accepts a number of configuration options.
3
4These are documented [here](http://onsi.github.io/ginkgo/#the-ginkgo-cli)
5
6You can also learn more via
7
8 ginkgo help
9
10or (I kid you not):
11
12 go test -asdf
13*/
14package config
15
16import (
17 "flag"
18 "time"
19
20 "fmt"
21)
22
23const VERSION = "1.16.2"
24
25type GinkgoConfigType struct {
26 RandomSeed int64
27 RandomizeAllSpecs bool
28 RegexScansFilePath bool
29 FocusStrings []string
30 SkipStrings []string
31 SkipMeasurements bool
32 FailOnPending bool
33 FailFast bool
34 FlakeAttempts int
35 EmitSpecProgress bool
36 DryRun bool
37 DebugParallel bool
38
39 ParallelNode int
40 ParallelTotal int
41 SyncHost string
42 StreamHost string
43}
44
45var GinkgoConfig = GinkgoConfigType{}
46
47type DefaultReporterConfigType struct {
48 NoColor bool
49 SlowSpecThreshold float64
50 NoisyPendings bool
51 NoisySkippings bool
52 Succinct bool
53 Verbose bool
54 FullTrace bool
55 ReportPassed bool
56 ReportFile string
57}
58
59var DefaultReporterConfig = DefaultReporterConfigType{}
60
61func processPrefix(prefix string) string {
62 if prefix != "" {
63 prefix += "."
64 }
65 return prefix
66}
67
68type flagFunc func(string)
69
70func (f flagFunc) String() string { return "" }
71func (f flagFunc) Set(s string) error { f(s); return nil }
72
73func Flags(flagSet *flag.FlagSet, prefix string, includeParallelFlags bool) {
74 prefix = processPrefix(prefix)
75 flagSet.Int64Var(&(GinkgoConfig.RandomSeed), prefix+"seed", time.Now().Unix(), "The seed used to randomize the spec suite.")
76 flagSet.BoolVar(&(GinkgoConfig.RandomizeAllSpecs), prefix+"randomizeAllSpecs", false, "If set, ginkgo will randomize all specs together. By default, ginkgo only randomizes the top level Describe, Context and When groups.")
77 flagSet.BoolVar(&(GinkgoConfig.SkipMeasurements), prefix+"skipMeasurements", false, "If set, ginkgo will skip any measurement specs.")
78 flagSet.BoolVar(&(GinkgoConfig.FailOnPending), prefix+"failOnPending", false, "If set, ginkgo will mark the test suite as failed if any specs are pending.")
79 flagSet.BoolVar(&(GinkgoConfig.FailFast), prefix+"failFast", false, "If set, ginkgo will stop running a test suite after a failure occurs.")
80
81 flagSet.BoolVar(&(GinkgoConfig.DryRun), prefix+"dryRun", false, "If set, ginkgo will walk the test hierarchy without actually running anything. Best paired with -v.")
82
83 flagSet.Var(flagFunc(flagFocus), prefix+"focus", "If set, ginkgo will only run specs that match this regular expression. Can be specified multiple times, values are ORed.")
84 flagSet.Var(flagFunc(flagSkip), prefix+"skip", "If set, ginkgo will only run specs that do not match this regular expression. Can be specified multiple times, values are ORed.")
85
86 flagSet.BoolVar(&(GinkgoConfig.RegexScansFilePath), prefix+"regexScansFilePath", false, "If set, ginkgo regex matching also will look at the file path (code location).")
87
88 flagSet.IntVar(&(GinkgoConfig.FlakeAttempts), prefix+"flakeAttempts", 1, "Make up to this many attempts to run each spec. Please note that if any of the attempts succeed, the suite will not be failed. But any failures will still be recorded.")
89
90 flagSet.BoolVar(&(GinkgoConfig.EmitSpecProgress), prefix+"progress", false, "If set, ginkgo will emit progress information as each spec runs to the GinkgoWriter.")
91
92 flagSet.BoolVar(&(GinkgoConfig.DebugParallel), prefix+"debug", false, "If set, ginkgo will emit node output to files when running in parallel.")
93
94 if includeParallelFlags {
95 flagSet.IntVar(&(GinkgoConfig.ParallelNode), prefix+"parallel.node", 1, "This worker node's (one-indexed) node number. For running specs in parallel.")
96 flagSet.IntVar(&(GinkgoConfig.ParallelTotal), prefix+"parallel.total", 1, "The total number of worker nodes. For running specs in parallel.")
97 flagSet.StringVar(&(GinkgoConfig.SyncHost), prefix+"parallel.synchost", "", "The address for the server that will synchronize the running nodes.")
98 flagSet.StringVar(&(GinkgoConfig.StreamHost), prefix+"parallel.streamhost", "", "The address for the server that the running nodes should stream data to.")
99 }
100
101 flagSet.BoolVar(&(DefaultReporterConfig.NoColor), prefix+"noColor", false, "If set, suppress color output in default reporter.")
102 flagSet.Float64Var(&(DefaultReporterConfig.SlowSpecThreshold), prefix+"slowSpecThreshold", 5.0, "(in seconds) Specs that take longer to run than this threshold are flagged as slow by the default reporter.")
103 flagSet.BoolVar(&(DefaultReporterConfig.NoisyPendings), prefix+"noisyPendings", true, "If set, default reporter will shout about pending tests.")
104 flagSet.BoolVar(&(DefaultReporterConfig.NoisySkippings), prefix+"noisySkippings", true, "If set, default reporter will shout about skipping tests.")
105 flagSet.BoolVar(&(DefaultReporterConfig.Verbose), prefix+"v", false, "If set, default reporter print out all specs as they begin.")
106 flagSet.BoolVar(&(DefaultReporterConfig.Succinct), prefix+"succinct", false, "If set, default reporter prints out a very succinct report")
107 flagSet.BoolVar(&(DefaultReporterConfig.FullTrace), prefix+"trace", false, "If set, default reporter prints out the full stack trace when a failure occurs")
108 flagSet.BoolVar(&(DefaultReporterConfig.ReportPassed), prefix+"reportPassed", false, "If set, default reporter prints out captured output of passed tests.")
109 flagSet.StringVar(&(DefaultReporterConfig.ReportFile), prefix+"reportFile", "", "Override the default reporter output file path.")
110
111}
112
113func BuildFlagArgs(prefix string, ginkgo GinkgoConfigType, reporter DefaultReporterConfigType) []string {
114 prefix = processPrefix(prefix)
115 result := make([]string, 0)
116
117 if ginkgo.RandomSeed > 0 {
118 result = append(result, fmt.Sprintf("--%sseed=%d", prefix, ginkgo.RandomSeed))
119 }
120
121 if ginkgo.RandomizeAllSpecs {
122 result = append(result, fmt.Sprintf("--%srandomizeAllSpecs", prefix))
123 }
124
125 if ginkgo.SkipMeasurements {
126 result = append(result, fmt.Sprintf("--%sskipMeasurements", prefix))
127 }
128
129 if ginkgo.FailOnPending {
130 result = append(result, fmt.Sprintf("--%sfailOnPending", prefix))
131 }
132
133 if ginkgo.FailFast {
134 result = append(result, fmt.Sprintf("--%sfailFast", prefix))
135 }
136
137 if ginkgo.DryRun {
138 result = append(result, fmt.Sprintf("--%sdryRun", prefix))
139 }
140
141 for _, s := range ginkgo.FocusStrings {
142 result = append(result, fmt.Sprintf("--%sfocus=%s", prefix, s))
143 }
144
145 for _, s := range ginkgo.SkipStrings {
146 result = append(result, fmt.Sprintf("--%sskip=%s", prefix, s))
147 }
148
149 if ginkgo.FlakeAttempts > 1 {
150 result = append(result, fmt.Sprintf("--%sflakeAttempts=%d", prefix, ginkgo.FlakeAttempts))
151 }
152
153 if ginkgo.EmitSpecProgress {
154 result = append(result, fmt.Sprintf("--%sprogress", prefix))
155 }
156
157 if ginkgo.DebugParallel {
158 result = append(result, fmt.Sprintf("--%sdebug", prefix))
159 }
160
161 if ginkgo.ParallelNode != 0 {
162 result = append(result, fmt.Sprintf("--%sparallel.node=%d", prefix, ginkgo.ParallelNode))
163 }
164
165 if ginkgo.ParallelTotal != 0 {
166 result = append(result, fmt.Sprintf("--%sparallel.total=%d", prefix, ginkgo.ParallelTotal))
167 }
168
169 if ginkgo.StreamHost != "" {
170 result = append(result, fmt.Sprintf("--%sparallel.streamhost=%s", prefix, ginkgo.StreamHost))
171 }
172
173 if ginkgo.SyncHost != "" {
174 result = append(result, fmt.Sprintf("--%sparallel.synchost=%s", prefix, ginkgo.SyncHost))
175 }
176
177 if ginkgo.RegexScansFilePath {
178 result = append(result, fmt.Sprintf("--%sregexScansFilePath", prefix))
179 }
180
181 if reporter.NoColor {
182 result = append(result, fmt.Sprintf("--%snoColor", prefix))
183 }
184
185 if reporter.SlowSpecThreshold > 0 {
186 result = append(result, fmt.Sprintf("--%sslowSpecThreshold=%.5f", prefix, reporter.SlowSpecThreshold))
187 }
188
189 if !reporter.NoisyPendings {
190 result = append(result, fmt.Sprintf("--%snoisyPendings=false", prefix))
191 }
192
193 if !reporter.NoisySkippings {
194 result = append(result, fmt.Sprintf("--%snoisySkippings=false", prefix))
195 }
196
197 if reporter.Verbose {
198 result = append(result, fmt.Sprintf("--%sv", prefix))
199 }
200
201 if reporter.Succinct {
202 result = append(result, fmt.Sprintf("--%ssuccinct", prefix))
203 }
204
205 if reporter.FullTrace {
206 result = append(result, fmt.Sprintf("--%strace", prefix))
207 }
208
209 if reporter.ReportPassed {
210 result = append(result, fmt.Sprintf("--%sreportPassed", prefix))
211 }
212
213 if reporter.ReportFile != "" {
214 result = append(result, fmt.Sprintf("--%sreportFile=%s", prefix, reporter.ReportFile))
215 }
216
217 return result
218}
219
220// flagFocus implements the -focus flag.
221func flagFocus(arg string) {
222 if arg != "" {
223 GinkgoConfig.FocusStrings = append(GinkgoConfig.FocusStrings, arg)
224 }
225}
226
227// flagSkip implements the -skip flag.
228func flagSkip(arg string) {
229 if arg != "" {
230 GinkgoConfig.SkipStrings = append(GinkgoConfig.SkipStrings, arg)
231 }
232}