Skip to content

Commit 6c7d6cf

Browse files
authored
tests: get test name from testing.T (ethereum#22941)
There were 2 TODOs about that fix after Golang 1.8 release. It's here for 3 years already, so now should be the right time.
1 parent 750115f commit 6c7d6cf

File tree

7 files changed

+16
-19
lines changed

7 files changed

+16
-19
lines changed

tests/block_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ func TestBlockchain(t *testing.T) {
4848
// using 4.6 TGas
4949
bt.skipLoad(`.*randomStatetest94.json.*`)
5050
bt.walk(t, blockTestDir, func(t *testing.T, name string, test *BlockTest) {
51-
if err := bt.checkFailure(t, name+"/trie", test.Run(false)); err != nil {
51+
if err := bt.checkFailure(t, test.Run(false)); err != nil {
5252
t.Errorf("test without snapshotter failed: %v", err)
5353
}
54-
if err := bt.checkFailure(t, name+"/snap", test.Run(true)); err != nil {
54+
if err := bt.checkFailure(t, test.Run(true)); err != nil {
5555
t.Errorf("test with snapshotter failed: %v", err)
5656
}
5757
})

tests/difficulty_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ func TestDifficulty(t *testing.T) {
7979
dt.config("difficulty.json", mainnetChainConfig)
8080

8181
dt.walk(t, difficultyTestDir, func(t *testing.T, name string, test *DifficultyTest) {
82-
cfg := dt.findConfig(name)
82+
cfg := dt.findConfig(t)
8383
if test.ParentDifficulty.Cmp(params.MinimumDifficulty) < 0 {
8484
t.Skip("difficulty below minimum")
8585
return
8686
}
87-
if err := dt.checkFailure(t, name, test.Run(cfg)); err != nil {
87+
if err := dt.checkFailure(t, test.Run(cfg)); err != nil {
8888
t.Error(err)
8989
}
9090
})

tests/init_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,22 +167,20 @@ func (tm *testMatcher) findSkip(name string) (reason string, skipload bool) {
167167
}
168168

169169
// findConfig returns the chain config matching defined patterns.
170-
func (tm *testMatcher) findConfig(name string) *params.ChainConfig {
171-
// TODO(fjl): name can be derived from testing.T when min Go version is 1.8
170+
func (tm *testMatcher) findConfig(t *testing.T) *params.ChainConfig {
172171
for _, m := range tm.configpat {
173-
if m.p.MatchString(name) {
172+
if m.p.MatchString(t.Name()) {
174173
return &m.config
175174
}
176175
}
177176
return new(params.ChainConfig)
178177
}
179178

180179
// checkFailure checks whether a failure is expected.
181-
func (tm *testMatcher) checkFailure(t *testing.T, name string, err error) error {
182-
// TODO(fjl): name can be derived from t when min Go version is 1.8
180+
func (tm *testMatcher) checkFailure(t *testing.T, err error) error {
183181
failReason := ""
184182
for _, m := range tm.failpat {
185-
if m.p.MatchString(name) {
183+
if m.p.MatchString(t.Name()) {
186184
failReason = m.reason
187185
break
188186
}

tests/rlp_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestRLP(t *testing.T) {
2424
t.Parallel()
2525
tm := new(testMatcher)
2626
tm.walk(t, rlpTestDir, func(t *testing.T, name string, test *RLPTest) {
27-
if err := tm.checkFailure(t, name, test.Run()); err != nil {
27+
if err := tm.checkFailure(t, test.Run()); err != nil {
2828
t.Error(err)
2929
}
3030
})

tests/state_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,11 @@ func TestState(t *testing.T) {
6464
for _, subtest := range test.Subtests() {
6565
subtest := subtest
6666
key := fmt.Sprintf("%s/%d", subtest.Fork, subtest.Index)
67-
name := name + "/" + key
6867

6968
t.Run(key+"/trie", func(t *testing.T) {
7069
withTrace(t, test.gasLimit(subtest), func(vmconfig vm.Config) error {
7170
_, _, err := test.Run(subtest, vmconfig, false)
72-
return st.checkFailure(t, name+"/trie", err)
71+
return st.checkFailure(t, err)
7372
})
7473
})
7574
t.Run(key+"/snap", func(t *testing.T) {
@@ -78,7 +77,7 @@ func TestState(t *testing.T) {
7877
if _, err := snaps.Journal(statedb.IntermediateRoot(false)); err != nil {
7978
return err
8079
}
81-
return st.checkFailure(t, name+"/snap", err)
80+
return st.checkFailure(t, err)
8281
})
8382
})
8483
}
@@ -117,6 +116,6 @@ func withTrace(t *testing.T, gasLimit uint64, test func(vm.Config) error) {
117116
} else {
118117
t.Log("EVM operation log:\n" + buf.String())
119118
}
120-
//t.Logf("EVM output: 0x%x", tracer.Output())
121-
//t.Logf("EVM error: %v", tracer.Error())
119+
// t.Logf("EVM output: 0x%x", tracer.Output())
120+
// t.Logf("EVM error: %v", tracer.Error())
122121
}

tests/transaction_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestTransaction(t *testing.T) {
4747
txt.skipLoad("^ttValue/TransactionWithHighValueOverflow.json")
4848
txt.walk(t, transactionTestDir, func(t *testing.T, name string, test *TransactionTest) {
4949
cfg := params.MainnetChainConfig
50-
if err := txt.checkFailure(t, name, test.Run(cfg)); err != nil {
50+
if err := txt.checkFailure(t, test.Run(cfg)); err != nil {
5151
t.Error(err)
5252
}
5353
})

tests/vm_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ func TestVM(t *testing.T) {
3030

3131
vmt.walk(t, vmTestDir, func(t *testing.T, name string, test *VMTest) {
3232
withTrace(t, test.json.Exec.GasLimit, func(vmconfig vm.Config) error {
33-
return vmt.checkFailure(t, name+"/trie", test.Run(vmconfig, false))
33+
return vmt.checkFailure(t, test.Run(vmconfig, false))
3434
})
3535
withTrace(t, test.json.Exec.GasLimit, func(vmconfig vm.Config) error {
36-
return vmt.checkFailure(t, name+"/snap", test.Run(vmconfig, true))
36+
return vmt.checkFailure(t, test.Run(vmconfig, true))
3737
})
3838
})
3939
}

0 commit comments

Comments
 (0)