Skip to content

Commit ff4da59

Browse files
srivkashishm
authored andcommitted
remove --order flag #641 (#664)
- preserve --sort flag - remove randomizer logic
1 parent 662d7d2 commit ff4da59

10 files changed

Lines changed: 103 additions & 93 deletions

File tree

execution/stream/stream.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
"github.com/getgauge/gauge/gauge"
4040
gm "github.com/getgauge/gauge/gauge_messages"
4141
"github.com/getgauge/gauge/logger"
42+
"github.com/getgauge/gauge/order"
4243
"github.com/getgauge/gauge/reporter"
4344
"github.com/getgauge/gauge/util"
4445
"github.com/getgauge/gauge/validation"
@@ -245,10 +246,7 @@ func setFlags(req *gm.ExecutionRequest) []error {
245246
reporter.NumberOfExecutionStreams = streams
246247
filter.NumberOfExecutionStreams = streams
247248
execution.Strategy = strings.ToLower(req.GetStrategy().String())
248-
//TODO: should be changed to use Order instead
249-
if req.GetSort() {
250-
filter.Order = "sort"
251-
}
249+
order.Sorted = req.GetSort()
252250
reporter.Verbose = true
253251
logger.Initialize(strings.ToLower(req.GetLogLevel().String()))
254252
if req.GetWorkingDir() != "" {
@@ -274,6 +272,6 @@ func resetFlags() {
274272
reporter.NumberOfExecutionStreams = cores
275273
filter.NumberOfExecutionStreams = cores
276274
execution.Strategy = "lazy"
277-
filter.Order = ""
275+
order.Sorted = false
278276
util.SetWorkingDir(config.ProjectRoot)
279277
}

execution/stream/stream_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/getgauge/gauge/filter"
3434
"github.com/getgauge/gauge/gauge"
3535
gm "github.com/getgauge/gauge/gauge_messages"
36+
"github.com/getgauge/gauge/order"
3637
"github.com/getgauge/gauge/reporter"
3738
"github.com/getgauge/gauge/util"
3839
"golang.org/x/net/context"
@@ -414,7 +415,7 @@ func (s *MySuite) TestSetFlags(c *C) {
414415
c.Assert(execution.NumberOfExecutionStreams, Equals, 3)
415416
c.Assert(reporter.NumberOfExecutionStreams, Equals, 3)
416417
c.Assert(filter.NumberOfExecutionStreams, Equals, 3)
417-
c.Assert(filter.Order, Equals, "sort")
418+
c.Assert(order.Sorted, Equals, true)
418419
c.Assert(filter.ExecuteTags, Equals, "tag1 & tag2")
419420
c.Assert(reporter.Verbose, Equals, true)
420421
c.Assert(reporter.IsParallel, Equals, true)
@@ -443,7 +444,7 @@ func (s *MySuite) TestResetFlags(c *C) {
443444
execution.NumberOfExecutionStreams = 1
444445
reporter.NumberOfExecutionStreams = 2
445446
filter.NumberOfExecutionStreams = 3
446-
filter.Order = "sort"
447+
order.Sorted = true
447448
resetFlags()
448449

449450
cores := util.NumberOfCores()
@@ -452,7 +453,7 @@ func (s *MySuite) TestResetFlags(c *C) {
452453
c.Assert(execution.NumberOfExecutionStreams, Equals, cores)
453454
c.Assert(reporter.NumberOfExecutionStreams, Equals, cores)
454455
c.Assert(filter.NumberOfExecutionStreams, Equals, cores)
455-
c.Assert(filter.Order, Equals, "")
456+
c.Assert(order.Sorted, Equals, false)
456457
c.Assert(filter.ExecuteTags, Equals, "")
457458
c.Assert(reporter.Verbose, Equals, false)
458459
c.Assert(reporter.IsParallel, Equals, false)

filter/filter.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
var ExecuteTags string
1010
var Distribute int
1111
var NumberOfExecutionStreams int
12-
var Order string
1312

1413
func FilterSpecs(specs []*gauge.Specification) []*gauge.Specification {
1514
specs = applyFilters(specs, specsFilters())
@@ -23,7 +22,7 @@ func FilterSpecs(specs []*gauge.Specification) []*gauge.Specification {
2322
}
2423

2524
func specsFilters() []specsFilter {
26-
return []specsFilter{&tagsFilter{ExecuteTags}, &specsGroupFilter{Distribute, NumberOfExecutionStreams}, &specOrder{Order}}
25+
return []specsFilter{&tagsFilter{ExecuteTags}, &specsGroupFilter{Distribute, NumberOfExecutionStreams}}
2726
}
2827

2928
func applyFilters(specsToExecute []*gauge.Specification, filters []specsFilter) []*gauge.Specification {

filter/specItemFilter_test.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package filter
1919

2020
import "fmt"
2121

22-
//
2322
import (
2423
"testing"
2524

@@ -167,22 +166,6 @@ func (s *MySuite) TestToEvaluateTagExpressionConsistingSpecialCharacters(c *C) {
167166
c.Assert(filter.filterTags([]string{"a", "b"}), Equals, true)
168167
}
169168

170-
func (s *MySuite) TestToSortSpecs(c *C) {
171-
spec1 := &gauge.Specification{FileName: "ab"}
172-
spec2 := &gauge.Specification{FileName: "b"}
173-
spec3 := &gauge.Specification{FileName: "c"}
174-
var specs []*gauge.Specification
175-
specs = append(specs, spec3)
176-
specs = append(specs, spec1)
177-
specs = append(specs, spec2)
178-
179-
specs = sortSpecsList(specs)
180-
181-
c.Assert(specs[0].FileName, Equals, spec1.FileName)
182-
c.Assert(specs[1].FileName, Equals, spec2.FileName)
183-
c.Assert(specs[2].FileName, Equals, spec3.FileName)
184-
}
185-
186169
func (s *MySuite) TestScenarioSpanFilter(c *C) {
187170
scenario1 := &gauge.Scenario{
188171
Heading: &gauge.Heading{Value: "First Scenario"},

filter/specsFilter.go

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
package filter
1919

2020
import (
21-
"math/rand"
22-
"sort"
23-
"time"
24-
2521
"github.com/getgauge/gauge/gauge"
2622
"github.com/getgauge/gauge/logger"
2723
)
@@ -39,10 +35,6 @@ type specsGroupFilter struct {
3935
execStreams int
4036
}
4137

42-
type specOrder struct {
43-
order string
44-
}
45-
4638
func (tagsFilter *tagsFilter) filter(specs []*gauge.Specification) []*gauge.Specification {
4739
if tagsFilter.tagExp != "" {
4840
validateTagExpression(tagsFilter.tagExp)
@@ -77,41 +69,3 @@ func DistributeSpecs(specifications []*gauge.Specification, distributions int) [
7769
}
7870
return s
7971
}
80-
81-
func (specOrder *specOrder) filter(specs []*gauge.Specification) []*gauge.Specification {
82-
if specOrder.order == "random" {
83-
return shuffleSpecs(specs)
84-
} else if specOrder.order == "sort" {
85-
sortSpecsList(specs)
86-
}
87-
return specs
88-
}
89-
90-
func shuffleSpecs(allSpecs []*gauge.Specification) []*gauge.Specification {
91-
dest := make([]*gauge.Specification, len(allSpecs))
92-
rand.Seed(int64(time.Now().Nanosecond()))
93-
perm := rand.Perm(len(allSpecs))
94-
for i, v := range perm {
95-
dest[v] = allSpecs[i]
96-
}
97-
return dest
98-
}
99-
100-
type ByFileName []*gauge.Specification
101-
102-
func (s ByFileName) Len() int {
103-
return len(s)
104-
}
105-
106-
func (s ByFileName) Swap(i, j int) {
107-
s[i], s[j] = s[j], s[i]
108-
}
109-
110-
func (s ByFileName) Less(i, j int) bool {
111-
return s[i].FileName < s[j].FileName
112-
}
113-
114-
func sortSpecsList(allSpecs []*gauge.Specification) []*gauge.Specification {
115-
sort.Sort(ByFileName(allSpecs))
116-
return allSpecs
117-
}

filter/specsFilter_test.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,6 @@ func createSpecsList(number int) []*gauge.Specification {
6363
return specs
6464
}
6565

66-
func (s *MySuite) TestToShuffleSpecsToRandomize(c *C) {
67-
var specs []*gauge.Specification
68-
specs = append(specs, &gauge.Specification{FileName: "a"}, &gauge.Specification{FileName: "b"}, &gauge.Specification{FileName: "c"}, &gauge.Specification{FileName: "d"},
69-
&gauge.Specification{FileName: "e"}, &gauge.Specification{FileName: "f"}, &gauge.Specification{FileName: "g"}, &gauge.Specification{FileName: "h"})
70-
shuffledSpecs := shuffleSpecs(specs)
71-
for i, spec := range shuffledSpecs {
72-
if spec.FileName != specs[i].FileName {
73-
c.Succeed()
74-
}
75-
}
76-
}
77-
7866
func (s *MySuite) TestToRunSpecificSetOfSpecs(c *C) {
7967
var specs []*gauge.Specification
8068
spec1 := &gauge.Specification{Heading: &gauge.Heading{Value: "SPECHEADING1"}}

gauge.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"github.com/getgauge/gauge/filter"
3535
"github.com/getgauge/gauge/formatter"
3636
"github.com/getgauge/gauge/logger"
37+
"github.com/getgauge/gauge/order"
3738
"github.com/getgauge/gauge/plugin"
3839
"github.com/getgauge/gauge/refactor"
3940
"github.com/getgauge/gauge/reporter"
@@ -73,8 +74,7 @@ var numberOfExecutionStreams = flag.Int([]string{"n"}, util.NumberOfCores(), "Sp
7374
var distribute = flag.Int([]string{"g", "-group"}, -1, "Specify which group of specification to execute based on -n flag")
7475
var workingDir = flag.String([]string{"-dir"}, ".", "Set the working directory for the current command, accepts a path relative to current directory.")
7576
var strategy = flag.String([]string{"-strategy"}, "lazy", "Set the parallelization strategy for execution. Possible options are: `eager`, `lazy`. Ex: gauge -p --strategy=\"eager\"")
76-
var doNotRandomize = flag.Bool([]string{"-sort", "s"}, false, "Run specs in Alphabetical Order. Eg: gauge -s specs")
77-
var order = flag.String([]string{"-order", "o"}, "", "Set the specs execution order. Possible options are: `random`, `sort`. Ex: gauge --order=\"random\"")
77+
var sort = flag.Bool([]string{"-sort", "s"}, false, "Run specs in Alphabetical Order. Eg: gauge -s specs")
7878
var validate = flag.Bool([]string{"-validate", "#-check"}, false, "Check for validation and parse errors. Eg: gauge --validate specs")
7979
var updateAll = flag.Bool([]string{"-update-all"}, false, "Updates all the installed Gauge plugins. Eg: gauge --update-all")
8080
var checkUpdates = flag.Bool([]string{"-check-updates"}, false, "Checks for Gauge and plugins updates. Eg: gauge --check-updates")
@@ -230,11 +230,7 @@ func initPackageFlags() {
230230
execution.InParallel = *parallel
231231
execution.Strategy = *strategy
232232
filter.ExecuteTags = *executeTags
233-
if *doNotRandomize {
234-
fmt.Println("This flag will be deprecated soon. Please use --order=sort instead.")
235-
filter.Order = "sort"
236-
}
237-
filter.Order = *order
233+
order.Sorted = *sort
238234
filter.Distribute = *distribute
239235
filter.NumberOfExecutionStreams = *numberOfExecutionStreams
240236
reporter.NumberOfExecutionStreams = *numberOfExecutionStreams

order/sort.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2015 ThoughtWorks, Inc.
2+
3+
// This file is part of Gauge.
4+
5+
// Gauge is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
10+
// Gauge is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
15+
// You should have received a copy of the GNU General Public License
16+
// along with Gauge. If not, see <http://www.gnu.org/licenses/>.
17+
18+
package order
19+
20+
import (
21+
"sort"
22+
23+
"github.com/getgauge/gauge/gauge"
24+
)
25+
26+
var Sorted bool
27+
28+
type byFileName []*gauge.Specification
29+
30+
func (s byFileName) Len() int {
31+
return len(s)
32+
}
33+
34+
func (s byFileName) Swap(i, j int) {
35+
s[i], s[j] = s[j], s[i]
36+
}
37+
38+
func (s byFileName) Less(i, j int) bool {
39+
return s[i].FileName < s[j].FileName
40+
}
41+
42+
func Sort(specs []*gauge.Specification) []*gauge.Specification {
43+
if Sorted {
44+
sort.Sort(byFileName(specs))
45+
}
46+
return specs
47+
}

order/sort_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2015 ThoughtWorks, Inc.
2+
3+
// This file is part of Gauge.
4+
5+
// Gauge is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
10+
// Gauge is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
15+
// You should have received a copy of the GNU General Public License
16+
// along with Gauge. If not, see <http://www.gnu.org/licenses/>.
17+
package order
18+
19+
import (
20+
"testing"
21+
22+
"github.com/getgauge/gauge/gauge"
23+
)
24+
25+
func TestToSortSpecs(t *testing.T) {
26+
spec1 := &gauge.Specification{FileName: "ab"}
27+
spec2 := &gauge.Specification{FileName: "b"}
28+
spec3 := &gauge.Specification{FileName: "c"}
29+
var specs []*gauge.Specification
30+
specs = append(specs, spec3)
31+
specs = append(specs, spec1)
32+
specs = append(specs, spec2)
33+
34+
Sorted = true
35+
got := Sort(specs)
36+
expected := []*gauge.Specification{spec1, spec2, spec3}
37+
38+
for i, s := range got {
39+
if expected[i].FileName != s.FileName {
40+
t.Errorf("Expected '%s' at position %d, got %s", expected[i].FileName, i, s.FileName)
41+
}
42+
}
43+
}

parser/parse.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/getgauge/gauge/filter"
2828
"github.com/getgauge/gauge/gauge"
2929
"github.com/getgauge/gauge/logger"
30+
"github.com/getgauge/gauge/order"
3031
"github.com/getgauge/gauge/util"
3132
)
3233

@@ -63,7 +64,7 @@ func ParseSpecFiles(specFiles []string, conceptDictionary *gauge.ConceptDictiona
6364

6465
func ParseSpecs(args []string, conceptsDictionary *gauge.ConceptDictionary, buildErrors *gauge.BuildErrors) ([]*gauge.Specification, bool) {
6566
specs, failed := parseSpecsInDirs(conceptsDictionary, args, buildErrors)
66-
specsToExecute := filter.FilterSpecs(specs)
67+
specsToExecute := order.Sort(filter.FilterSpecs(specs))
6768
return specsToExecute, failed
6869
}
6970

0 commit comments

Comments
 (0)