Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions execution/stream/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/getgauge/gauge/gauge"
gm "github.com/getgauge/gauge/gauge_messages"
"github.com/getgauge/gauge/logger"
"github.com/getgauge/gauge/order"
"github.com/getgauge/gauge/reporter"
"github.com/getgauge/gauge/util"
"github.com/getgauge/gauge/validation"
Expand Down Expand Up @@ -245,10 +246,7 @@ func setFlags(req *gm.ExecutionRequest) []error {
reporter.NumberOfExecutionStreams = streams
filter.NumberOfExecutionStreams = streams
execution.Strategy = strings.ToLower(req.GetStrategy().String())
//TODO: should be changed to use Order instead
if req.GetSort() {
filter.Order = "sort"
}
order.Sorted = req.GetSort()
reporter.Verbose = true
logger.Initialize(strings.ToLower(req.GetLogLevel().String()))
if req.GetWorkingDir() != "" {
Expand All @@ -274,6 +272,6 @@ func resetFlags() {
reporter.NumberOfExecutionStreams = cores
filter.NumberOfExecutionStreams = cores
execution.Strategy = "lazy"
filter.Order = ""
order.Sorted = false
util.SetWorkingDir(config.ProjectRoot)
}
7 changes: 4 additions & 3 deletions execution/stream/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/getgauge/gauge/filter"
"github.com/getgauge/gauge/gauge"
gm "github.com/getgauge/gauge/gauge_messages"
"github.com/getgauge/gauge/order"
"github.com/getgauge/gauge/reporter"
"github.com/getgauge/gauge/util"
"golang.org/x/net/context"
Expand Down Expand Up @@ -414,7 +415,7 @@ func (s *MySuite) TestSetFlags(c *C) {
c.Assert(execution.NumberOfExecutionStreams, Equals, 3)
c.Assert(reporter.NumberOfExecutionStreams, Equals, 3)
c.Assert(filter.NumberOfExecutionStreams, Equals, 3)
c.Assert(filter.Order, Equals, "sort")
c.Assert(order.Sorted, Equals, true)
c.Assert(filter.ExecuteTags, Equals, "tag1 & tag2")
c.Assert(reporter.Verbose, Equals, true)
c.Assert(reporter.IsParallel, Equals, true)
Expand Down Expand Up @@ -443,7 +444,7 @@ func (s *MySuite) TestResetFlags(c *C) {
execution.NumberOfExecutionStreams = 1
reporter.NumberOfExecutionStreams = 2
filter.NumberOfExecutionStreams = 3
filter.Order = "sort"
order.Sorted = true
resetFlags()

cores := util.NumberOfCores()
Expand All @@ -452,7 +453,7 @@ func (s *MySuite) TestResetFlags(c *C) {
c.Assert(execution.NumberOfExecutionStreams, Equals, cores)
c.Assert(reporter.NumberOfExecutionStreams, Equals, cores)
c.Assert(filter.NumberOfExecutionStreams, Equals, cores)
c.Assert(filter.Order, Equals, "")
c.Assert(order.Sorted, Equals, false)
c.Assert(filter.ExecuteTags, Equals, "")
c.Assert(reporter.Verbose, Equals, false)
c.Assert(reporter.IsParallel, Equals, false)
Expand Down
3 changes: 1 addition & 2 deletions filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
var ExecuteTags string
var Distribute int
var NumberOfExecutionStreams int
var Order string

func FilterSpecs(specs []*gauge.Specification) []*gauge.Specification {
specs = applyFilters(specs, specsFilters())
Expand All @@ -23,7 +22,7 @@ func FilterSpecs(specs []*gauge.Specification) []*gauge.Specification {
}

func specsFilters() []specsFilter {
return []specsFilter{&tagsFilter{ExecuteTags}, &specsGroupFilter{Distribute, NumberOfExecutionStreams}, &specOrder{Order}}
return []specsFilter{&tagsFilter{ExecuteTags}, &specsGroupFilter{Distribute, NumberOfExecutionStreams}}
}

func applyFilters(specsToExecute []*gauge.Specification, filters []specsFilter) []*gauge.Specification {
Expand Down
17 changes: 0 additions & 17 deletions filter/specItemFilter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package filter

import "fmt"

//
import (
"testing"

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

func (s *MySuite) TestToSortSpecs(c *C) {
spec1 := &gauge.Specification{FileName: "ab"}
spec2 := &gauge.Specification{FileName: "b"}
spec3 := &gauge.Specification{FileName: "c"}
var specs []*gauge.Specification
specs = append(specs, spec3)
specs = append(specs, spec1)
specs = append(specs, spec2)

specs = sortSpecsList(specs)

c.Assert(specs[0].FileName, Equals, spec1.FileName)
c.Assert(specs[1].FileName, Equals, spec2.FileName)
c.Assert(specs[2].FileName, Equals, spec3.FileName)
}

func (s *MySuite) TestScenarioSpanFilter(c *C) {
scenario1 := &gauge.Scenario{
Heading: &gauge.Heading{Value: "First Scenario"},
Expand Down
46 changes: 0 additions & 46 deletions filter/specsFilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
package filter

import (
"math/rand"
"sort"
"time"

"github.com/getgauge/gauge/gauge"
"github.com/getgauge/gauge/logger"
)
Expand All @@ -39,10 +35,6 @@ type specsGroupFilter struct {
execStreams int
}

type specOrder struct {
order string
}

func (tagsFilter *tagsFilter) filter(specs []*gauge.Specification) []*gauge.Specification {
if tagsFilter.tagExp != "" {
validateTagExpression(tagsFilter.tagExp)
Expand Down Expand Up @@ -77,41 +69,3 @@ func DistributeSpecs(specifications []*gauge.Specification, distributions int) [
}
return s
}

func (specOrder *specOrder) filter(specs []*gauge.Specification) []*gauge.Specification {
if specOrder.order == "random" {
return shuffleSpecs(specs)
} else if specOrder.order == "sort" {
sortSpecsList(specs)
}
return specs
}

func shuffleSpecs(allSpecs []*gauge.Specification) []*gauge.Specification {
dest := make([]*gauge.Specification, len(allSpecs))
rand.Seed(int64(time.Now().Nanosecond()))
perm := rand.Perm(len(allSpecs))
for i, v := range perm {
dest[v] = allSpecs[i]
}
return dest
}

type ByFileName []*gauge.Specification

func (s ByFileName) Len() int {
return len(s)
}

func (s ByFileName) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}

func (s ByFileName) Less(i, j int) bool {
return s[i].FileName < s[j].FileName
}

func sortSpecsList(allSpecs []*gauge.Specification) []*gauge.Specification {
sort.Sort(ByFileName(allSpecs))
return allSpecs
}
12 changes: 0 additions & 12 deletions filter/specsFilter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,6 @@ func createSpecsList(number int) []*gauge.Specification {
return specs
}

func (s *MySuite) TestToShuffleSpecsToRandomize(c *C) {
var specs []*gauge.Specification
specs = append(specs, &gauge.Specification{FileName: "a"}, &gauge.Specification{FileName: "b"}, &gauge.Specification{FileName: "c"}, &gauge.Specification{FileName: "d"},
&gauge.Specification{FileName: "e"}, &gauge.Specification{FileName: "f"}, &gauge.Specification{FileName: "g"}, &gauge.Specification{FileName: "h"})
shuffledSpecs := shuffleSpecs(specs)
for i, spec := range shuffledSpecs {
if spec.FileName != specs[i].FileName {
c.Succeed()
}
}
}

func (s *MySuite) TestToRunSpecificSetOfSpecs(c *C) {
var specs []*gauge.Specification
spec1 := &gauge.Specification{Heading: &gauge.Heading{Value: "SPECHEADING1"}}
Expand Down
10 changes: 3 additions & 7 deletions gauge.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/getgauge/gauge/filter"
"github.com/getgauge/gauge/formatter"
"github.com/getgauge/gauge/logger"
"github.com/getgauge/gauge/order"
"github.com/getgauge/gauge/plugin"
"github.com/getgauge/gauge/refactor"
"github.com/getgauge/gauge/reporter"
Expand Down Expand Up @@ -73,8 +74,7 @@ var numberOfExecutionStreams = flag.Int([]string{"n"}, util.NumberOfCores(), "Sp
var distribute = flag.Int([]string{"g", "-group"}, -1, "Specify which group of specification to execute based on -n flag")
var workingDir = flag.String([]string{"-dir"}, ".", "Set the working directory for the current command, accepts a path relative to current directory.")
var strategy = flag.String([]string{"-strategy"}, "lazy", "Set the parallelization strategy for execution. Possible options are: `eager`, `lazy`. Ex: gauge -p --strategy=\"eager\"")
var doNotRandomize = flag.Bool([]string{"-sort", "s"}, false, "Run specs in Alphabetical Order. Eg: gauge -s specs")
var order = flag.String([]string{"-order", "o"}, "", "Set the specs execution order. Possible options are: `random`, `sort`. Ex: gauge --order=\"random\"")
var sort = flag.Bool([]string{"-sort", "s"}, false, "Run specs in Alphabetical Order. Eg: gauge -s specs")
var validate = flag.Bool([]string{"-validate", "#-check"}, false, "Check for validation and parse errors. Eg: gauge --validate specs")
var updateAll = flag.Bool([]string{"-update-all"}, false, "Updates all the installed Gauge plugins. Eg: gauge --update-all")
var checkUpdates = flag.Bool([]string{"-check-updates"}, false, "Checks for Gauge and plugins updates. Eg: gauge --check-updates")
Expand Down Expand Up @@ -230,11 +230,7 @@ func initPackageFlags() {
execution.InParallel = *parallel
execution.Strategy = *strategy
filter.ExecuteTags = *executeTags
if *doNotRandomize {
fmt.Println("This flag will be deprecated soon. Please use --order=sort instead.")
filter.Order = "sort"
}
filter.Order = *order
order.Sorted = *sort
filter.Distribute = *distribute
filter.NumberOfExecutionStreams = *numberOfExecutionStreams
reporter.NumberOfExecutionStreams = *numberOfExecutionStreams
Expand Down
47 changes: 47 additions & 0 deletions order/sort.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2015 ThoughtWorks, Inc.

// This file is part of Gauge.

// Gauge is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Gauge is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Gauge. If not, see <http://www.gnu.org/licenses/>.

package order

import (
"sort"

"github.com/getgauge/gauge/gauge"
)

var Sorted bool

type byFileName []*gauge.Specification

func (s byFileName) Len() int {
return len(s)
}

func (s byFileName) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}

func (s byFileName) Less(i, j int) bool {
return s[i].FileName < s[j].FileName
}

func Sort(specs []*gauge.Specification) []*gauge.Specification {
if Sorted {
sort.Sort(byFileName(specs))
}
return specs
}
43 changes: 43 additions & 0 deletions order/sort_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2015 ThoughtWorks, Inc.

// This file is part of Gauge.

// Gauge is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Gauge is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Gauge. If not, see <http://www.gnu.org/licenses/>.
package order

import (
"testing"

"github.com/getgauge/gauge/gauge"
)

func TestToSortSpecs(t *testing.T) {
spec1 := &gauge.Specification{FileName: "ab"}
spec2 := &gauge.Specification{FileName: "b"}
spec3 := &gauge.Specification{FileName: "c"}
var specs []*gauge.Specification
specs = append(specs, spec3)
specs = append(specs, spec1)
specs = append(specs, spec2)

Sorted = true
got := Sort(specs)
expected := []*gauge.Specification{spec1, spec2, spec3}

for i, s := range got {
if expected[i].FileName != s.FileName {
t.Errorf("Expected '%s' at position %d, got %s", expected[i].FileName, i, s.FileName)
}
}
}
3 changes: 2 additions & 1 deletion parser/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/getgauge/gauge/filter"
"github.com/getgauge/gauge/gauge"
"github.com/getgauge/gauge/logger"
"github.com/getgauge/gauge/order"
"github.com/getgauge/gauge/util"
)

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

func ParseSpecs(args []string, conceptsDictionary *gauge.ConceptDictionary, buildErrors *gauge.BuildErrors) ([]*gauge.Specification, bool) {
specs, failed := parseSpecsInDirs(conceptsDictionary, args, buildErrors)
specsToExecute := filter.FilterSpecs(specs)
specsToExecute := order.Sort(filter.FilterSpecs(specs))
return specsToExecute, failed
}

Expand Down