Skip to content

Commit 0378f22

Browse files
committed
Prevent re-interpreting errors if they have placeholder patterns
1 parent 7675158 commit 0378f22

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

ct/test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type TestLike interface {
1414
Skipf(msg string, args ...interface{})
1515
Error(args ...interface{})
1616
Errorf(msg string, args ...interface{})
17+
Fatal(msg string)
1718
Fatalf(msg string, args ...interface{})
1819
Failed() bool
1920
Name() string
@@ -29,6 +30,13 @@ func Errorf(t TestLike, format string, args ...any) {
2930
t.Errorf(format, args...)
3031
}
3132

33+
// Fatal is a wrapper around t.Fatal which prints the failing error message in red.
34+
func Fatal(t TestLike, format string) {
35+
t.Helper()
36+
format = ansiRedForeground + format + ansiResetForeground
37+
t.Fatal(format)
38+
}
39+
3240
// Fatalf is a wrapper around t.Fatalf which prints the failing error message in red.
3341
func Fatalf(t TestLike, format string, args ...any) {
3442
t.Helper()

must/must.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func ParseJSON(t ct.TestLike, b io.ReadCloser) gjson.Result {
3434
t.Helper()
3535
res, err := should.ParseJSON(b)
3636
if err != nil {
37-
ct.Fatalf(t, err.Error())
37+
ct.Fatal(t, err.Error())
3838
}
3939
return res
4040
}
@@ -45,7 +45,7 @@ func MatchRequest(t ct.TestLike, req *http.Request, m match.HTTPRequest) []byte
4545
t.Helper()
4646
res, err := should.MatchRequest(req, m)
4747
if err != nil {
48-
ct.Fatalf(t, err.Error())
48+
ct.Fatal(t, err.Error())
4949
}
5050
return res
5151
}
@@ -55,7 +55,7 @@ func MatchRequest(t ct.TestLike, req *http.Request, m match.HTTPRequest) []byte
5555
func MatchSuccess(t ct.TestLike, res *http.Response) {
5656
t.Helper()
5757
if err := should.MatchSuccess(res); err != nil {
58-
ct.Fatalf(t, err.Error())
58+
ct.Fatal(t, err.Error())
5959
}
6060
}
6161

@@ -64,7 +64,7 @@ func MatchSuccess(t ct.TestLike, res *http.Response) {
6464
func MatchFailure(t ct.TestLike, res *http.Response) {
6565
t.Helper()
6666
if err := should.MatchFailure(res); err != nil {
67-
ct.Fatalf(t, err.Error())
67+
ct.Fatal(t, err.Error())
6868
}
6969
}
7070

@@ -74,7 +74,7 @@ func MatchResponse(t ct.TestLike, res *http.Response, m match.HTTPResponse) []by
7474
t.Helper()
7575
body, err := should.MatchResponse(res, m)
7676
if err != nil {
77-
ct.Fatalf(t, err.Error())
77+
ct.Fatal(t, err.Error())
7878
}
7979
return body
8080
}
@@ -84,7 +84,7 @@ func MatchFederationRequest(t ct.TestLike, fedReq *fclient.FederationRequest, ma
8484
t.Helper()
8585
err := should.MatchFederationRequest(fedReq)
8686
if err != nil {
87-
ct.Fatalf(t, err.Error())
87+
ct.Fatal(t, err.Error())
8888
}
8989
}
9090

@@ -94,7 +94,7 @@ func MatchGJSON(t ct.TestLike, jsonResult gjson.Result, matchers ...match.JSON)
9494
t.Helper()
9595
err := should.MatchGJSON(jsonResult, matchers...)
9696
if err != nil {
97-
ct.Fatalf(t, err.Error())
97+
ct.Fatal(t, err.Error())
9898
}
9999
}
100100

@@ -104,7 +104,7 @@ func MatchJSONBytes(t ct.TestLike, rawJson []byte, matchers ...match.JSON) {
104104
t.Helper()
105105
err := should.MatchJSONBytes(rawJson, matchers...)
106106
if err != nil {
107-
ct.Fatalf(t, err.Error())
107+
ct.Fatal(t, err.Error())
108108
}
109109
}
110110

@@ -141,7 +141,7 @@ func GetJSONFieldStr(t ct.TestLike, body gjson.Result, wantKey string) string {
141141
t.Helper()
142142
str, err := should.GetJSONFieldStr(body, wantKey)
143143
if err != nil {
144-
ct.Fatalf(t, err.Error())
144+
ct.Fatal(t, err.Error())
145145
}
146146
return str
147147
}
@@ -152,7 +152,7 @@ func HaveInOrder[V comparable](t ct.TestLike, gots []V, wants []V) {
152152
t.Helper()
153153
err := should.HaveInOrder(gots, wants)
154154
if err != nil {
155-
ct.Fatalf(t, err.Error())
155+
ct.Fatal(t, err.Error())
156156
}
157157
}
158158

@@ -163,7 +163,7 @@ func ContainSubset[V comparable](t ct.TestLike, larger []V, smaller []V) {
163163
t.Helper()
164164
err := should.ContainSubset(larger, smaller)
165165
if err != nil {
166-
ct.Fatalf(t, err.Error())
166+
ct.Fatal(t, err.Error())
167167
}
168168
}
169169

@@ -174,7 +174,7 @@ func NotContainSubset[V comparable](t ct.TestLike, larger []V, smaller []V) {
174174
t.Helper()
175175
err := should.NotContainSubset(larger, smaller)
176176
if err != nil {
177-
ct.Fatalf(t, err.Error())
177+
ct.Fatal(t, err.Error())
178178
}
179179
}
180180

@@ -188,7 +188,7 @@ func CheckOffAll(t ct.TestLike, items []interface{}, wantItems []interface{}) {
188188
t.Helper()
189189
err := should.CheckOffAll(items, wantItems)
190190
if err != nil {
191-
ct.Fatalf(t, err.Error())
191+
ct.Fatal(t, err.Error())
192192
}
193193
}
194194

@@ -202,7 +202,7 @@ func CheckOffAllAllowUnwanted(t ct.TestLike, items []interface{}, wantItems []in
202202
t.Helper()
203203
result, err := should.CheckOffAllAllowUnwanted(items, wantItems)
204204
if err != nil {
205-
ct.Fatalf(t, err.Error())
205+
ct.Fatal(t, err.Error())
206206
}
207207
return result
208208
}
@@ -215,7 +215,7 @@ func CheckOff(t ct.TestLike, items []interface{}, wantItem interface{}) []interf
215215
t.Helper()
216216
result, err := should.CheckOff(items, wantItem)
217217
if err != nil {
218-
ct.Fatalf(t, err.Error())
218+
ct.Fatal(t, err.Error())
219219
}
220220
return result
221221
}

0 commit comments

Comments
 (0)