@@ -2,6 +2,7 @@ package godog
2
2
3
3
import (
4
4
"bytes"
5
+ "flag"
5
6
"fmt"
6
7
"strings"
7
8
"testing"
@@ -75,3 +76,126 @@ func TestFlagsUsageShouldIncludeFormatDescriptons(t *testing.T) {
75
76
}
76
77
}
77
78
}
79
+
80
+ func TestBindFlagsShouldRespectFlagDefaults (t * testing.T ) {
81
+ opts := Options {}
82
+
83
+ BindFlags ("flagDefaults." , flag .CommandLine , & opts )
84
+
85
+ if opts .Format != "pretty" {
86
+ t .Fatalf ("expected Format: pretty, but it was: %s" , opts .Format )
87
+ }
88
+ if opts .Tags != "" {
89
+ t .Fatalf ("expected Tags: '', but it was: %s" , opts .Tags )
90
+ }
91
+ if opts .Concurrency != 1 {
92
+ t .Fatalf ("expected Concurrency: 1, but it was: %d" , opts .Concurrency )
93
+ }
94
+ if opts .ShowStepDefinitions {
95
+ t .Fatalf ("expected ShowStepDefinitions: false, but it was: %t" , opts .ShowStepDefinitions )
96
+ }
97
+ if opts .StopOnFailure {
98
+ t .Fatalf ("expected StopOnFailure: false, but it was: %t" , opts .StopOnFailure )
99
+ }
100
+ if opts .Strict {
101
+ t .Fatalf ("expected Strict: false, but it was: %t" , opts .Strict )
102
+ }
103
+ if opts .NoColors {
104
+ t .Fatalf ("expected NoColors: false, but it was: %t" , opts .NoColors )
105
+ }
106
+ if opts .Randomize != 0 {
107
+ t .Fatalf ("expected Randomize: 0, but it was: %d" , opts .Randomize )
108
+ }
109
+ }
110
+
111
+ func TestBindFlagsShouldRespectOptDefaults (t * testing.T ) {
112
+ opts := Options {
113
+ Format : "progress" ,
114
+ Tags : "test" ,
115
+ Concurrency : 2 ,
116
+ ShowStepDefinitions : true ,
117
+ StopOnFailure : true ,
118
+ Strict : true ,
119
+ NoColors : true ,
120
+ Randomize : int64 (7 ),
121
+ }
122
+
123
+ BindFlags ("optDefaults." , flag .CommandLine , & opts )
124
+
125
+ if opts .Format != "progress" {
126
+ t .Fatalf ("expected Format: progress, but it was: %s" , opts .Format )
127
+ }
128
+ if opts .Tags != "test" {
129
+ t .Fatalf ("expected Tags: 'test', but it was: %s" , opts .Tags )
130
+ }
131
+ if opts .Concurrency != 2 {
132
+ t .Fatalf ("expected Concurrency: 2, but it was: %d" , opts .Concurrency )
133
+ }
134
+ if ! opts .ShowStepDefinitions {
135
+ t .Fatalf ("expected ShowStepDefinitions: true, but it was: %t" , opts .ShowStepDefinitions )
136
+ }
137
+ if ! opts .StopOnFailure {
138
+ t .Fatalf ("expected StopOnFailure: true, but it was: %t" , opts .StopOnFailure )
139
+ }
140
+ if ! opts .Strict {
141
+ t .Fatalf ("expected Strict: true, but it was: %t" , opts .Strict )
142
+ }
143
+ if ! opts .NoColors {
144
+ t .Fatalf ("expected NoColors: true, but it was: %t" , opts .NoColors )
145
+ }
146
+ if opts .Randomize != 7 {
147
+ t .Fatalf ("expected Randomize: 7, but it was: %d" , opts .Randomize )
148
+ }
149
+ }
150
+
151
+ func TestBindFlagsShouldRespectFlagOverrides (t * testing.T ) {
152
+ opts := Options {
153
+ Format : "progress" ,
154
+ Tags : "test" ,
155
+ Concurrency : 2 ,
156
+ ShowStepDefinitions : true ,
157
+ StopOnFailure : true ,
158
+ Strict : true ,
159
+ NoColors : true ,
160
+ Randomize : 11 ,
161
+ }
162
+ flagSet := flag.FlagSet {}
163
+
164
+ BindFlags ("optOverrides." , & flagSet , & opts )
165
+
166
+ flagSet .Parse ([]string {
167
+ "--optOverrides.format=junit" ,
168
+ "--optOverrides.tags=test2" ,
169
+ "--optOverrides.concurrency=3" ,
170
+ "--optOverrides.definitions=false" ,
171
+ "--optOverrides.stop-on-failure=false" ,
172
+ "--optOverrides.strict=false" ,
173
+ "--optOverrides.no-colors=false" ,
174
+ "--optOverrides.random=2" ,
175
+ })
176
+
177
+ if opts .Format != "junit" {
178
+ t .Fatalf ("expected Format: junit, but it was: %s" , opts .Format )
179
+ }
180
+ if opts .Tags != "test2" {
181
+ t .Fatalf ("expected Tags: 'test2', but it was: %s" , opts .Tags )
182
+ }
183
+ if opts .Concurrency != 3 {
184
+ t .Fatalf ("expected Concurrency: 3, but it was: %d" , opts .Concurrency )
185
+ }
186
+ if opts .ShowStepDefinitions {
187
+ t .Fatalf ("expected ShowStepDefinitions: true, but it was: %t" , opts .ShowStepDefinitions )
188
+ }
189
+ if opts .StopOnFailure {
190
+ t .Fatalf ("expected StopOnFailure: true, but it was: %t" , opts .StopOnFailure )
191
+ }
192
+ if opts .Strict {
193
+ t .Fatalf ("expected Strict: true, but it was: %t" , opts .Strict )
194
+ }
195
+ if opts .NoColors {
196
+ t .Fatalf ("expected NoColors: true, but it was: %t" , opts .NoColors )
197
+ }
198
+ if opts .Randomize != 2 {
199
+ t .Fatalf ("expected Randomize: 2, but it was: %d" , opts .Randomize )
200
+ }
201
+ }
0 commit comments