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.7.0" 24 25type GinkgoConfigType struct { 26 RandomSeed int64 27 RandomizeAllSpecs bool 28 RegexScansFilePath bool 29 FocusString string 30 SkipString 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} 56 57var DefaultReporterConfig = DefaultReporterConfigType{} 58 59func processPrefix(prefix string) string { 60 if prefix != "" { 61 prefix = prefix + "." 62 } 63 return prefix 64} 65 66func Flags(flagSet *flag.FlagSet, prefix string, includeParallelFlags bool) { 67 prefix = processPrefix(prefix) 68 flagSet.Int64Var(&(GinkgoConfig.RandomSeed), prefix+"seed", time.Now().Unix(), "The seed used to randomize the spec suite.") 69 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.") 70 flagSet.BoolVar(&(GinkgoConfig.SkipMeasurements), prefix+"skipMeasurements", false, "If set, ginkgo will skip any measurement specs.") 71 flagSet.BoolVar(&(GinkgoConfig.FailOnPending), prefix+"failOnPending", false, "If set, ginkgo will mark the test suite as failed if any specs are pending.") 72 flagSet.BoolVar(&(GinkgoConfig.FailFast), prefix+"failFast", false, "If set, ginkgo will stop running a test suite after a failure occurs.") 73 74 flagSet.BoolVar(&(GinkgoConfig.DryRun), prefix+"dryRun", false, "If set, ginkgo will walk the test hierarchy without actually running anything. Best paired with -v.") 75 76 flagSet.StringVar(&(GinkgoConfig.FocusString), prefix+"focus", "", "If set, ginkgo will only run specs that match this regular expression.") 77 flagSet.StringVar(&(GinkgoConfig.SkipString), prefix+"skip", "", "If set, ginkgo will only run specs that do not match this regular expression.") 78 79 flagSet.BoolVar(&(GinkgoConfig.RegexScansFilePath), prefix+"regexScansFilePath", false, "If set, ginkgo regex matching also will look at the file path (code location).") 80 81 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.") 82 83 flagSet.BoolVar(&(GinkgoConfig.EmitSpecProgress), prefix+"progress", false, "If set, ginkgo will emit progress information as each spec runs to the GinkgoWriter.") 84 85 flagSet.BoolVar(&(GinkgoConfig.DebugParallel), prefix+"debug", false, "If set, ginkgo will emit node output to files when running in parallel.") 86 87 if includeParallelFlags { 88 flagSet.IntVar(&(GinkgoConfig.ParallelNode), prefix+"parallel.node", 1, "This worker node's (one-indexed) node number. For running specs in parallel.") 89 flagSet.IntVar(&(GinkgoConfig.ParallelTotal), prefix+"parallel.total", 1, "The total number of worker nodes. For running specs in parallel.") 90 flagSet.StringVar(&(GinkgoConfig.SyncHost), prefix+"parallel.synchost", "", "The address for the server that will synchronize the running nodes.") 91 flagSet.StringVar(&(GinkgoConfig.StreamHost), prefix+"parallel.streamhost", "", "The address for the server that the running nodes should stream data to.") 92 } 93 94 flagSet.BoolVar(&(DefaultReporterConfig.NoColor), prefix+"noColor", false, "If set, suppress color output in default reporter.") 95 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.") 96 flagSet.BoolVar(&(DefaultReporterConfig.NoisyPendings), prefix+"noisyPendings", true, "If set, default reporter will shout about pending tests.") 97 flagSet.BoolVar(&(DefaultReporterConfig.NoisySkippings), prefix+"noisySkippings", true, "If set, default reporter will shout about skipping tests.") 98 flagSet.BoolVar(&(DefaultReporterConfig.Verbose), prefix+"v", false, "If set, default reporter print out all specs as they begin.") 99 flagSet.BoolVar(&(DefaultReporterConfig.Succinct), prefix+"succinct", false, "If set, default reporter prints out a very succinct report") 100 flagSet.BoolVar(&(DefaultReporterConfig.FullTrace), prefix+"trace", false, "If set, default reporter prints out the full stack trace when a failure occurs") 101} 102 103func BuildFlagArgs(prefix string, ginkgo GinkgoConfigType, reporter DefaultReporterConfigType) []string { 104 prefix = processPrefix(prefix) 105 result := make([]string, 0) 106 107 if ginkgo.RandomSeed > 0 { 108 result = append(result, fmt.Sprintf("--%sseed=%d", prefix, ginkgo.RandomSeed)) 109 } 110 111 if ginkgo.RandomizeAllSpecs { 112 result = append(result, fmt.Sprintf("--%srandomizeAllSpecs", prefix)) 113 } 114 115 if ginkgo.SkipMeasurements { 116 result = append(result, fmt.Sprintf("--%sskipMeasurements", prefix)) 117 } 118 119 if ginkgo.FailOnPending { 120 result = append(result, fmt.Sprintf("--%sfailOnPending", prefix)) 121 } 122 123 if ginkgo.FailFast { 124 result = append(result, fmt.Sprintf("--%sfailFast", prefix)) 125 } 126 127 if ginkgo.DryRun { 128 result = append(result, fmt.Sprintf("--%sdryRun", prefix)) 129 } 130 131 if ginkgo.FocusString != "" { 132 result = append(result, fmt.Sprintf("--%sfocus=%s", prefix, ginkgo.FocusString)) 133 } 134 135 if ginkgo.SkipString != "" { 136 result = append(result, fmt.Sprintf("--%sskip=%s", prefix, ginkgo.SkipString)) 137 } 138 139 if ginkgo.FlakeAttempts > 1 { 140 result = append(result, fmt.Sprintf("--%sflakeAttempts=%d", prefix, ginkgo.FlakeAttempts)) 141 } 142 143 if ginkgo.EmitSpecProgress { 144 result = append(result, fmt.Sprintf("--%sprogress", prefix)) 145 } 146 147 if ginkgo.DebugParallel { 148 result = append(result, fmt.Sprintf("--%sdebug", prefix)) 149 } 150 151 if ginkgo.ParallelNode != 0 { 152 result = append(result, fmt.Sprintf("--%sparallel.node=%d", prefix, ginkgo.ParallelNode)) 153 } 154 155 if ginkgo.ParallelTotal != 0 { 156 result = append(result, fmt.Sprintf("--%sparallel.total=%d", prefix, ginkgo.ParallelTotal)) 157 } 158 159 if ginkgo.StreamHost != "" { 160 result = append(result, fmt.Sprintf("--%sparallel.streamhost=%s", prefix, ginkgo.StreamHost)) 161 } 162 163 if ginkgo.SyncHost != "" { 164 result = append(result, fmt.Sprintf("--%sparallel.synchost=%s", prefix, ginkgo.SyncHost)) 165 } 166 167 if ginkgo.RegexScansFilePath { 168 result = append(result, fmt.Sprintf("--%sregexScansFilePath", prefix)) 169 } 170 171 if reporter.NoColor { 172 result = append(result, fmt.Sprintf("--%snoColor", prefix)) 173 } 174 175 if reporter.SlowSpecThreshold > 0 { 176 result = append(result, fmt.Sprintf("--%sslowSpecThreshold=%.5f", prefix, reporter.SlowSpecThreshold)) 177 } 178 179 if !reporter.NoisyPendings { 180 result = append(result, fmt.Sprintf("--%snoisyPendings=false", prefix)) 181 } 182 183 if !reporter.NoisySkippings { 184 result = append(result, fmt.Sprintf("--%snoisySkippings=false", prefix)) 185 } 186 187 if reporter.Verbose { 188 result = append(result, fmt.Sprintf("--%sv", prefix)) 189 } 190 191 if reporter.Succinct { 192 result = append(result, fmt.Sprintf("--%ssuccinct", prefix)) 193 } 194 195 if reporter.FullTrace { 196 result = append(result, fmt.Sprintf("--%strace", prefix)) 197 } 198 199 return result 200} 201