File tree Expand file tree Collapse file tree 8 files changed +89
-11
lines changed
Expand file tree Collapse file tree 8 files changed +89
-11
lines changed Original file line number Diff line number Diff line change 11# v2.3.0
22
3+ - Preserve test execution order alphabetical order
34 - Add property ` skip ` , adds the ability to skip test cases
45
56# v2.2.0
Original file line number Diff line number Diff line change 11[ ![ Build Status] ( https://travis-ci.org/commander-cli/commander.svg?branch=master )] ( https://travis-ci.org/commander-cli/commander )
22[ ![ GoDoc] ( https://godoc.org/github.com/commander-cli/commander?status.svg )] ( https://godoc.org/github.com/commander-cli/commander )
3- [ ![ Go Report Card] ( https://goreportcard.com/badge/github.com/commander-cli/commander )] ( https://goreportcard.com/report/github.com/SimonBaeumer /commander )
3+ [ ![ Go Report Card] ( https://goreportcard.com/badge/github.com/commander-cli/commander )] ( https://goreportcard.com/report/github.com/commander-cli /commander )
44[ ![ Maintainability] ( https://api.codeclimate.com/v1/badges/cc848165784e0f809a51/maintainability )] ( https://codeclimate.com/github/commander-cli/commander/maintainability )
55[ ![ Test Coverage] ( https://api.codeclimate.com/v1/badges/cc848165784e0f809a51/test_coverage )] ( https://codeclimate.com/github/commander-cli/commander/test_coverage )
66[ ![ Github All Releases] ( https://img.shields.io/github/downloads/commander-cli/commander/total.svg )] ( https://github.com/commander-cli/commander/releases )
Original file line number Diff line number Diff line change @@ -46,7 +46,22 @@ func createCliApp() *cli.App {
4646func createTestCommand () cli.Command {
4747 return cli.Command {
4848 Name : "test" ,
49- Usage : "Execute the test suite, by default it will use the commander.yaml from your current directory" ,
49+ Usage : `Execute cli app tests
50+
51+ By default it will use the commander.yaml from your current directory.
52+ Tests are always executed in alphabetical order.
53+
54+ Examples:
55+
56+ Filtering tests:
57+ test commander.yaml --filter="my test"
58+
59+ Multiple filters:
60+ test commander.yaml --filter=filter1 --filter=filter2
61+
62+ Regex filters:
63+ test commander.yaml --filter="^filter1$"
64+ ` ,
5065 ArgsUsage : "[file] [--filter]" ,
5166 Flags : []cli.Flag {
5267 cli.BoolFlag {
@@ -65,14 +80,7 @@ func createTestCommand() cli.Command {
6580 },
6681 cli.StringSliceFlag {
6782 Name : "filter" ,
68- Usage : `Filter tests by a given regex pattern. Tests are filtered by its title.
69-
70- Example:
71- test commander.yaml --filter="my test"
72-
73- Apply multiple filters:
74- test commander.yaml --filter=filter1 --filter=filter2
75- ` ,
83+ Usage : `Filter tests by a given regex pattern. Tests are filtered by its title.` ,
7684 },
7785 },
7886 Action : func (c * cli.Context ) error {
Original file line number Diff line number Diff line change @@ -111,4 +111,15 @@ tests:
111111 - ✓ [local] should be ignored
112112 not-contains :
113113 - executed at the beginning is ignored
114- exit-code : 0
114+ exit-code : 0
115+
116+ it should be executed in alphabetical order :
117+ command : ./commander test integration/unix/alphabetically_order.yaml
118+ stdout :
119+ contains :
120+ - |-
121+ ✓ [local] ---
122+ ✓ [local] 123
123+ ✓ [local] a
124+ ✓ [local] b
125+ exit-code : 0
Original file line number Diff line number Diff line change 1+ # Tests are always executed in alphabetical order
2+
3+ tests :
4+ 001 - test :
5+ command : exit 0
6+ exit-code : 0
7+
8+ 002 - test :
9+ command : exit 0
10+ exit-code : 0
11+
12+ 003 - test :
13+ command : exit 0
14+ exit-code : 0
15+
16+ 004 - test :
17+ command : exit 0
18+ exit-code : 0
Original file line number Diff line number Diff line change 1+ tests :
2+ a :
3+ command : echo test
4+ exit-code : 0
5+ b :
6+ command : echo test
7+ exit-code : 0
8+ 123 :
9+ command : echo test
10+ exit-code : 0
11+ " --- " :
12+ command : echo test
13+ exit-code : 0
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package runtime
22
33import (
44 "log"
5+ "sort"
56 "time"
67)
78
@@ -131,6 +132,11 @@ type Result struct {
131132
132133// Start starts the given test suite and executes all tests
133134func (r * Runtime ) Start (tests []TestCase ) Result {
135+ // Sort tests alphabetically to preserve a reproducible execution order
136+ sort .SliceStable (tests , func (i , j int ) bool {
137+ return tests [i ].Title < tests [j ].Title
138+ })
139+
134140 result := Result {}
135141 testCh := r .Runner .Run (tests )
136142 start := time .Now ()
Original file line number Diff line number Diff line change @@ -47,6 +47,27 @@ func TestRuntime_WithRetries(t *testing.T) {
4747 assert .Equal (t , 1 , counter )
4848}
4949
50+ func Test_AlphabeticalOrder (t * testing.T ) {
51+ tests := []TestCase {
52+ {Title : "bbb" , Command : CommandUnderTest {Cmd : "exit 0;" }},
53+ {Title : "aaa" },
54+ {Title : "111" },
55+ {Title : "_" },
56+ }
57+
58+ got := []string {}
59+ runtime := NewRuntime (& EventHandler {TestFinished : func (r TestResult ) {
60+ got = append (got , r .TestCase .Title )
61+ }})
62+
63+ runtime .Start (tests )
64+
65+ assert .Equal (t , "111" , got [0 ])
66+ assert .Equal (t , "_" , got [1 ])
67+ assert .Equal (t , "aaa" , got [2 ])
68+ assert .Equal (t , "bbb" , got [3 ])
69+ }
70+
5071func Test_RuntimeWithRetriesAndInterval (t * testing.T ) {
5172 s := getExampleTestCases ()
5273 s [0 ].Command .Retries = 3
You can’t perform that action at this time.
0 commit comments