-
Notifications
You must be signed in to change notification settings - Fork 1
/
testify.pattern
76 lines (52 loc) · 3.99 KB
/
testify.pattern
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#Rule
#(1) we use regex
#(2) s///g is the sed replace rule
#(3) use \(.*\) to extract the specific unchanged string
#Example: c *check.C ===> t *testing.T
s/c \\*check.C/t \\*testing.T/g
#Example: github.com/pingcap/ticdc/pkg/util/testleak ===> ''
s/\\"github.com\\/pingcap\\/ticdc\\/pkg\\/util\\/testleak\\"/ /g
#Example: defer testleak.AfterTest(c)() ===> ""
s/defer testleak.AfterTest(c)()/ /g
#Example: func Test(t *testing.T) { check.TestingT(t) } ===> ""
s/.*func Test(t \*testing.T) { check.TestingT(t) }.*/ /g
#Example: var _ = check.Suite(&workloadsSuite{}) ===> ""
s/.*check.Suite(.*/ /g
#Example: github.com/pingcap/check ===> github.com/stretchr/testify/require
s/github.com\\/pingcap\\/check/github.com\\/stretchr\\/testify\\/require/g
#Example: github.com/pingcap/tidb/util/testkit ===> github.com/pingcap/tidb/testkit
s/github.com\\/pingcap\\/tidb\\/util\\/testkit/github.com\\/pingcap\\/tidb\\/testkit/g
#Example: c.Assert(ddl, check.IsNil) ===> require.Nil(t, ddl)
s/.*c.Assert(\\(.*\\), check.IsNil).*/require.Nil(t, \\1)/g
#Example: c.Assert(tableID, check.Equals, int64(12345)) ===> require.Equal(t,tableID, int64(12345))
s/.*c.Assert(\\(.*\\), check.Equals, \\(.*\\)).*/require.Equal(t, \\2, \\1)/g
#Example: c.Assert(job.From, check.Not(check.Equals), job.To)
s/.*c.Assert(\\(.*\\), check.Not(check.Equals), \\(.*\\)).*/require.NotEqual(t, \\2, \\1)/g
#Example: c.Assert(tableID, check.Equals, int64(12345), check.Commentf("%v", cs)) ===> require.Equal(t,tableID, int64(12345), "%v", cs)
s/.*c.Assert(\\(.*\\), check.Equals, \\(.*\\), check.Commentf(\\(.*\\), \\(.*\\))).*/require.Equal(t, \\2, \\1, \\3, \\4)/g
#Example: c.Assert(tableID, check.DeepEquals, int64(12345), check.Commentf("%v", cs)) ===> require.Equal(t,tableID, int64(12345), "%v", cs)
s/.*c.Assert(\\(.*\\), check.DeepEquals, \\(.*\\), check.Commentf(\\(.*\\), \\(.*\\))).*/require.Equal(t, \\2, \\1, \\3, \\4)/g
#Example: c.Assert(tableID, check.DeepEquals, int64(12345)) ===> require.Equal(t,tableID, int64(12345))
s/.*c.Assert(\\(.*\\), check.DeepEquals, \\(.*\\)).*/require.Equal(t, \\2, \\1)/g
#Example: c.Assert(ok, check.IsTrue) ===> require.True(t, ok)
s/.*c.Assert(\\(.*\\), check.IsTrue).*/require.True(t, \\1)/g
#Example: c.Assert(ok, check.IsFalse) ===> require.False(t, ok)
s/.*c.Assert(\\(.*\\), check.IsFalse).*/require.False(t, \\1)/g
#Example: c.Assert(list, HasLen, 5) ===> require.Len(t, list, 5)
s/.*c.Assert(\\(.*\\), check.HasLen, \\(.*\\)).*/require.Len(t, \\1, \\2)/g
#Example: c.Assert(iface, NotNil) ===> require.NotNil(t, iface)
s/.*c.Assert(\\(.*\\), check.NotNil).*/require.NotNil(t, \\1)/g
#Example: c.Assert(time.Since(startTime), check.Less, time.Second) ===> require.Less(t, time.Since(startTime), time.Second)
s/.*c.Assert(\\(.*\\), check.Less, \\(.*\\)).*/require.Less(t, \\1, \\2)/g
#Example: c.Assert(time.Since(startTime), check.Greater, time.Second) ===> require.Greater(t, time.Since(startTime), time.Second)
s/.*c.Assert(\\(.*\\), check.Greater, \\(.*\\)).*/require.Greater(t, \\1, \\2)/g
#Example: c.Assert(time.Since(startTime), check.GreaterEqual, time.Second) ===> require.GreaterOrEqual(t, time.Since(startTime, time.Second)
s/.*c.Assert(\\(.*\\), check.GreaterEqual, \\(.*\\)).*/require.GreaterOrEqual(t, \\1, \\2)/g
#Example: c.Assert(time.Since(startTime), check.LessEqual, time.Second) ===> require.LessOrEqual(t, time.Since(startTime, time.Second)
s/.*c.Assert(\\(.*\\), check.LessEqual, \\(.*\\)).*/require.LessOrEqual(t, \\1, \\2)/g
#Example: c.Assert(err, check.ErrorMatches, "test error") ===> require.Regexp(t, "test.*", fmt.Errorf("test error"))
s/.*c.Assert(\\(.*\\), check.ErrorMatches, \\(.*\\)).*/require.Regexp(t, \\2, \\1)/g
#Example: c.Fatalf("locking finished unexpectedly") ===> require.FailNow(t, "locking finished unexpectedly")
s/.*c.Fatalf(\\(.*\\)).*/require.FailNow(t, \\1)/g
#Example: c.Assert(map[int]bool{4: true, 6: true}, check.HasKey, n.index) ===> require.Contains(n.t, map[int]bool{4: true, 6: true}, n.index)
s/.*c.Assert(\\(.*\\), check.HasKey, \\(.*\\)).*/require.Contains(t, \\1, \\2)/g