From 789d923c14e79ac9527559367cbeb33664d4603b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Thu, 3 Aug 2023 16:56:28 +0200 Subject: [PATCH] Add test for C.Run for more coverage Add TestCRunFormatWithC to alse check that Format is passed from the parent to the child when c.TB has a Run method with signature func(string, func(*C) bool). This added coverage will be helpful to check alternative implementations of C.Run. --- quicktest_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/quicktest_test.go b/quicktest_test.go index ec23afb..df8a91a 100644 --- a/quicktest_test.go +++ b/quicktest_test.go @@ -527,6 +527,27 @@ want: `) } +func TestCRunFormatWithC(t *testing.T) { + tt, innerTT := &testingT{}, &testingT{} + // Wrap the C with another C so the C.Run has to call a Run(string, func(*C) bool) instead of Run(string, func(*testing.T) bool) + c := qt.New(qt.New(tt)) + c.SetFormat(func(v interface{}) string { + return fmt.Sprintf("myfmt(%v)", v) + }) + c.Run("my test", func(innerC *qt.C) { + innerC.TB = innerTT + innerC.Check(42, qt.Equals, nil) + }) + assertPrefix(t, innerTT.errorString(), ` +error: + values are not equal +got: + myfmt(42) +want: + myfmt() +`) +} + func TestHelper(t *testing.T) { tt := &testingT{} qt.Assert(tt, true, qt.IsFalse)