Skip to content

Commit 0b990c4

Browse files
committed
temporarily remove test ordering
To comply with the changes in go1.20, Cleanup is no longer an option to call Spec.Finish, which means for the time being, tests will be executed in sync order.
1 parent 2ec5962 commit 0b990c4

File tree

6 files changed

+44
-19
lines changed

6 files changed

+44
-19
lines changed

Spec.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,9 @@ func (spec *Spec) runTB(tb testing.TB, blk func(*T)) {
395395

396396
retryHandler, ok := spec.lookupRetryFlaky()
397397
if ok {
398-
retryHandler.Assert(tb, func(it assert.It) { test(it) })
398+
retryHandler.Assert(tb, func(it assert.It) {
399+
test(it)
400+
})
399401
} else {
400402
test(tb)
401403
}
@@ -525,17 +527,12 @@ func (spec *Spec) specsFromCurrent() []*Spec {
525527
return specs
526528
}
527529

528-
func (spec *Spec) lookupParentSpecContext() (*Spec, bool) {
530+
func (spec *Spec) lookupParent() (*Spec, bool) {
529531
spec.testingTB.Helper()
530-
var CurrentContextSkipped bool
531532
for _, s := range spec.specsFromCurrent() {
532533
if s.isTest {
533534
continue
534535
}
535-
if !CurrentContextSkipped {
536-
CurrentContextSkipped = true
537-
continue
538-
}
539536
return s, true
540537
}
541538
return nil, false
@@ -554,7 +551,12 @@ func (spec *Spec) getTagSet() map[string]struct{} {
554551

555552
func (spec *Spec) addTest(blk func()) {
556553
spec.testingTB.Helper()
557-
spec.tests = append(spec.tests, blk)
554+
blk()
555+
//if parent, ok := spec.lookupParent(); ok && parent.parent == nil {
556+
// blk()
557+
// return
558+
//}
559+
//spec.tests = append(spec.tests, blk)
558560
}
559561

560562
var escapeNameRGX = regexp.MustCompile(`\\.`)

Spec_test.go

+26-1
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,15 @@ func TestSpec_Test_flakyByRetry_willRunAgainWithTheProvidedRetry(t *testing.T) {
10681068
assert.Must(t).True(retryUsed)
10691069
}
10701070

1071+
func TestSpec_Test_smoke(t *testing.T) {
1072+
s := testcase.NewSpec(t)
1073+
1074+
var count int
1075+
s.Test(``, func(t *testcase.T) { count++ })
1076+
1077+
assert.Equal(t, 1, count)
1078+
}
1079+
10711080
func TestSpec_Test_flakyByStrategy_willRunAgainBasedOnTheStrategy(t *testing.T) {
10721081
s := testcase.NewSpec(t)
10731082

@@ -1082,14 +1091,18 @@ func TestSpec_Test_flakyByStrategy_willRunAgainBasedOnTheStrategy(t *testing.T)
10821091
// we need a truly random generation,
10831092
// because *testcase.T.Random is deterministic.
10841093
rnd := random.New(random.CryptoSeed{})
1094+
10851095
s.Test(``, func(t *testcase.T) {
10861096
testCount++
10871097
if rnd.Bool() {
10881098
t.FailNow()
10891099
}
10901100
}, testcase.Flaky(strategy))
10911101

1092-
assert.Must(t).Equal(strategyCallCount, testCount)
1102+
assert.Must(t).AnyOf(func(a *assert.AnyOf) {
1103+
a.Test(func(t assert.It) { t.Must.Equal(strategyCallCount, testCount) })
1104+
a.Test(func(t assert.It) { t.Must.Equal(strategyCallCount+1, testCount) }) // when there is no error, the total
1105+
})
10931106
}
10941107

10951108
func TestSpec_Test_flakyFlagWithInvalidValue_willPanics(t *testing.T) {
@@ -1147,6 +1160,8 @@ func TestSpec_Parallel_testPrepareActionsExecutedInParallel(t *testing.T) {
11471160
}
11481161

11491162
func TestSpec_nonParallelTestExecutionOrder_isRandom(t *testing.T) {
1163+
t.Skip("go1.20")
1164+
11501165
assert.Eventually{RetryStrategy: assert.Waiter{WaitDuration: time.Second}}.Assert(t, func(it assert.It) {
11511166

11521167
s := testcase.NewSpec(it)
@@ -1167,6 +1182,8 @@ func TestSpec_nonParallelTestExecutionOrder_isRandom(t *testing.T) {
11671182
}
11681183

11691184
func TestSpec_Finish(t *testing.T) {
1185+
t.Skip("go1.20")
1186+
11701187
s := testcase.NewSpec(t)
11711188
var ran bool
11721189
s.Test(``, func(t *testcase.T) { ran = true })
@@ -1191,6 +1208,8 @@ func TestSpec_Finish_finishedSpecIsImmutable(t *testing.T) {
11911208
}
11921209

11931210
func TestSpec_Finish_runOnlyOnce(t *testing.T) {
1211+
t.Skip("go1.20")
1212+
11941213
s := testcase.NewSpec(t)
11951214
var count int
11961215
s.Test(``, func(t *testcase.T) { count++ })
@@ -1226,6 +1245,8 @@ func TestSpec_eachContextRunsOnce(t *testing.T) {
12261245
}
12271246

12281247
func TestSpec_Finish_describeBlocksRunWhenTheyCloseAndNotAfter(t *testing.T) {
1248+
t.Skip("go1.20")
1249+
12291250
var (
12301251
testInDescribe int
12311252
testOnTopLevel int
@@ -1341,6 +1362,8 @@ func TestNewSpec_withTestcaseT_InheritContext(t *testing.T) {
13411362
}
13421363

13431364
func TestSpec_Test_whenTestingTBIsGivenThatDoesNotSupportTBRunner_executesOnFinish(t *testing.T) {
1365+
t.Skip("go1.20")
1366+
13441367
s := testcase.NewSpec(t)
13451368
var ran bool
13461369
s.Test(``, func(t *testcase.T) { ran = true })
@@ -1350,6 +1373,8 @@ func TestSpec_Test_whenTestingTBIsGivenThatDoesNotSupportTBRunner_executesOnFini
13501373
}
13511374

13521375
func TestSpec_Test_testingTBNoTBRunner_ordered(t *testing.T) {
1376+
t.Skip("go1.20")
1377+
13531378
testcase.SetEnv(t, testcase.EnvKeySeed, "42")
13541379
testcase.SetEnv(t, testcase.EnvKeyOrdering, string(testcase.OrderingAsRandom))
13551380
s := testcase.NewSpec(t)

T_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,15 @@ func TestT_Defer(t *testing.T) {
127127
//
128128
//goland:noinspection GoDeferGo
129129
func TestT_Defer_failNowWillNotHang(t *testing.T) {
130+
t.Skip("WIP")
131+
130132
var wg sync.WaitGroup
131133
wg.Add(1)
132134
go func() {
133135
defer wg.Done()
134136
defer recover()
135-
s := testcase.NewSpec(&doubles.RecorderTB{})
137+
138+
s := testcase.NewSpec(&doubles.RecorderTB{TB: &doubles.TB{}})
136139

137140
s.Before(func(t *testcase.T) {
138141
t.Defer(func() { t.FailNow() })

TableTest_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
)
1010

1111
func TestTableTest_orderIsDeterministic(t *testing.T) {
12+
t.Skip("go1.20")
13+
1214
t.Setenv(testcase.EnvKeySeed, "42")
1315

1416
var (

hooks.go

-1
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,4 @@ func (spec *Spec) BeforeAll(blk func(tb testing.TB)) {
8383
Block: func() { once.Do(func() { blk(spec.testingTB) }) },
8484
Frame: frame,
8585
})
86-
8786
}

hooks_test.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,18 @@ func TestSpec_BeforeAll_blkRunsOnlyOnce(t *testing.T) {
7575
s.Test(``, blk)
7676
s.Test(``, blk)
7777
})
78-
s.Finish()
7978

8079
assert.Must(t).Equal(1, counter)
8180
}
8281

8382
func TestSpec_BeforeAll_failIfDefinedAfterTestCases(t *testing.T) {
84-
var isAnyOfTheTestCaseRan bool
85-
blk := func(t *testcase.T) { isAnyOfTheTestCaseRan = true }
8683
stub := &doubles.TB{}
87-
8884
sandbox.Run(func() {
8985
s := testcase.NewSpec(stub)
90-
s.Test(``, blk)
86+
s.Test(``, func(t *testcase.T) {})
9187
s.BeforeAll(func(tb testing.TB) {})
92-
s.Test(``, blk)
88+
s.Test(``, func(t *testcase.T) {})
9389
s.Finish()
9490
})
95-
9691
assert.Must(t).True(stub.IsFailed)
97-
assert.Must(t).True(!isAnyOfTheTestCaseRan)
9892
}

0 commit comments

Comments
 (0)