Skip to content

Commit 1aeaa32

Browse files
committed
fix: Plain assert allows override assert msg
1 parent ff0f65c commit 1aeaa32

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

assert/asserter.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ func (asserter Asserter) reportAssertionFault(defaultMsg string, a []any) {
7373
}
7474
if len(a) > 0 {
7575
if format, ok := a[0].(string); ok {
76-
f := x.Whom(defaultMsg != "", defaultMsg+conCatErrStr+format, format)
76+
allowDefMsg := !asserter.isErrorOnly() && defaultMsg != ""
77+
f := x.Whom(allowDefMsg, defaultMsg+conCatErrStr+format, format)
7778
asserter.reportPanic(fmt.Sprintf(f, a[1:]...))
7879
} else {
7980
asserter.reportPanic(fmt.Sprintln(append([]any{defaultMsg}, a...)))
@@ -141,6 +142,10 @@ func (asserter Asserter) callerInfo(msg string) (info string) {
141142
return
142143
}
143144

145+
func (asserter Asserter) isErrorOnly() bool {
146+
return asserter == AsserterToError
147+
}
148+
144149
func (asserter Asserter) hasToError() bool {
145150
return asserter&AsserterToError != 0
146151
}

0 commit comments

Comments
 (0)