From 89086b0757c069a4ab49a42f36f8a2e54c831e4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 19 Mar 2025 20:48:34 +0100 Subject: [PATCH 1/2] Document consequences of calling t.FailNow() These comments are adapted from t.FailNow()'s own documentation. Closes #1701 --- mock/mock.go | 2 ++ require/doc.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/mock/mock.go b/mock/mock.go index eb5682df9..3f53d22c5 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -332,6 +332,8 @@ func (m *Mock) TestData() objx.Map { */ // Test sets the test struct variable of the mock object +// Test should not be called on an object that is going to be used in a +// goroutine other than the one running the test function. func (m *Mock) Test(t TestingT) { m.mutex.Lock() defer m.mutex.Unlock() diff --git a/require/doc.go b/require/doc.go index 968434724..c8e3f94a8 100644 --- a/require/doc.go +++ b/require/doc.go @@ -23,6 +23,8 @@ // // The `require` package have same global functions as in the `assert` package, // but instead of returning a boolean result they call `t.FailNow()`. +// A consequence of this is that it must be called from the goroutine running +// the test function, not from other goroutines created during the test. // // Every assertion function also takes an optional string message as the final argument, // allowing custom error messages to be appended to the message the assertion method outputs. From b1c9368f814ec4c2d286b557f12c255f33ea76e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Fri, 21 Mar 2025 13:21:25 +0100 Subject: [PATCH 2/2] Improve existing docs --- mock/mock.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mock/mock.go b/mock/mock.go index 3f53d22c5..a6be813c7 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -331,7 +331,8 @@ func (m *Mock) TestData() objx.Map { Setting expectations */ -// Test sets the test struct variable of the mock object +// Test sets the [TestingT] on which errors will be reported, otherwise errors +// will cause a panic. // Test should not be called on an object that is going to be used in a // goroutine other than the one running the test function. func (m *Mock) Test(t TestingT) {