Skip to content

Commit 4ce699e

Browse files
committed
Preserve execution order alphabetically by test title
1 parent 75acc48 commit 4ce699e

3 files changed

Lines changed: 32 additions & 1 deletion

File tree

commander_unix.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff 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
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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

pkg/runtime/runtime.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package runtime
22

33
import (
44
"log"
5+
"sort"
56
"time"
67
)
78

@@ -131,10 +132,16 @@ type Result struct {
131132

132133
// Start starts the given test suite and executes all tests
133134
func (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()
137143
for tr := range testCh {
144+
r.EventHandler.TestFinished(tr)
138145
if tr.Skipped {
139146
result.Skipped++
140147

0 commit comments

Comments
 (0)