diff --git a/pkg/framework/core/common/common.go b/pkg/framework/core/common/common.go index df94a21..12e61e0 100644 --- a/pkg/framework/core/common/common.go +++ b/pkg/framework/core/common/common.go @@ -113,6 +113,8 @@ func (c *Common) LogfStep(format string, args ...interface{}) { // Error ... func (c *Common) Error(args ...interface{}) { + c.TestingT.Helper() + fullMessage := fmt.Sprintf("%s", args...) c.registerError(fullMessage) c.TestingT.Error(args...) @@ -120,6 +122,8 @@ func (c *Common) Error(args ...interface{}) { // Errorf ... func (c *Common) Errorf(format string, args ...interface{}) { + c.TestingT.Helper() + fullMessage := fmt.Sprintf(format, args...) c.registerError(fullMessage) c.TestingT.Errorf(format, args...) @@ -127,6 +131,8 @@ func (c *Common) Errorf(format string, args ...interface{}) { // Fatal ... func (c *Common) Fatal(args ...interface{}) { + c.TestingT.Helper() + fullMessage := fmt.Sprintf("%s", args...) c.registerError(fullMessage) c.TestingT.Fatal(args...) @@ -134,6 +140,8 @@ func (c *Common) Fatal(args ...interface{}) { // Fatalf ... func (c *Common) Fatalf(format string, args ...interface{}) { + c.TestingT.Helper() + fullMessage := fmt.Sprintf(format, args...) c.registerError(fullMessage) c.TestingT.Fatalf(format, args...) @@ -341,6 +349,10 @@ func (c *Common) SetRealT(realT provider.TestingT) { c.TestingT = realT } +func (c *Common) GetRealT() provider.TestingT { + return c.TestingT +} + func copyLabels(input, target *allure.Result) *allure.Result { if input == nil || target == nil { return target diff --git a/pkg/framework/core/common/common_test.go b/pkg/framework/core/common/common_test.go index d55df50..a579e30 100644 --- a/pkg/framework/core/common/common_test.go +++ b/pkg/framework/core/common/common_test.go @@ -184,6 +184,7 @@ type commonTMock struct { parallel bool run bool skipped bool + TestingT *testing.T } func newCommonTMock() *commonTMock { @@ -220,6 +221,8 @@ func (m *commonTMock) Run(testName string, testBody func(t *testing.T)) bool { return m.run } +func (m *commonTMock) Helper() {} + func TestCommon_Assert(t *testing.T) { asserts := helper.NewAssertsHelper(newCommonTMock()) comm := Common{assert: asserts} diff --git a/pkg/framework/core/common/step_context.go b/pkg/framework/core/common/step_context.go index a256821..56066c8 100644 --- a/pkg/framework/core/common/step_context.go +++ b/pkg/framework/core/common/step_context.go @@ -27,6 +27,7 @@ type StepT interface { Broken() BrokenNow() Name() string + GetRealT() provider.TestingT } type InternalStepCtx interface { @@ -91,20 +92,28 @@ func (ctx *stepCtx) FailNow() { } func (ctx *stepCtx) Error(args ...interface{}) { + ctx.t.GetRealT().Helper() + ctx.Fail() ctx.t.Error(args...) } func (ctx *stepCtx) Errorf(format string, args ...interface{}) { + ctx.t.GetRealT().Helper() + ctx.Fail() ctx.t.Errorf(format, args...) } func (ctx *stepCtx) Log(args ...interface{}) { + ctx.t.GetRealT().Helper() + ctx.t.Log(args...) } func (ctx *stepCtx) Logf(format string, args ...interface{}) { + ctx.t.GetRealT().Helper() + ctx.t.Logf(format, args...) } @@ -212,3 +221,7 @@ func (ctx *stepCtx) Breakf(format string, args ...interface{}) { ctx.Broken() ctx.t.Breakf(format, args...) } + +func (ctx *stepCtx) GetRealT() provider.TestingT { + return ctx.t.GetRealT() +} diff --git a/pkg/framework/core/common/step_context_test.go b/pkg/framework/core/common/step_context_test.go index 836a079..398b954 100644 --- a/pkg/framework/core/common/step_context_test.go +++ b/pkg/framework/core/common/step_context_test.go @@ -22,6 +22,8 @@ type providerTMockStep struct { failNow bool failed bool name string + + testingT provider.TestingT } func (m *providerTMockStep) Break(args ...interface{}) { @@ -83,6 +85,14 @@ func (m *providerTMockStep) Name() string { return m.name } +func (m *providerTMockStep) GetRealT() provider.TestingT { + return m.testingT +} + +func (m *providerTMockStep) SetRealT(realT provider.TestingT) { + m.testingT = realT +} + type providerMockStep struct { status allure.Status msg string @@ -104,6 +114,9 @@ func (m *providerMockStep) ExecutionContext() provider.ExecutionContext { return m.executionContext } +func (m *providerMockStep) Helper() { +} + type executionCtxMock struct { name string @@ -233,6 +246,7 @@ func TestStepCtx_Step(t *testing.T) { func TestStepCtx_Errorf_withParent(t *testing.T) { mockT := new(providerTMockStep) + mockT.SetRealT(t) parentStep := allure.NewSimpleStep("parentStep") parentCtx := &stepCtx{t: mockT, currentStep: parentStep} step := allure.NewSimpleStep("testStep") @@ -245,6 +259,7 @@ func TestStepCtx_Errorf_withParent(t *testing.T) { func TestStepCtx_Errorf_noParent(t *testing.T) { mockT := new(providerTMockStep) + mockT.SetRealT(t) step := allure.NewSimpleStep("testStep") ctx := stepCtx{t: mockT, currentStep: step} ctx.Errorf("test") @@ -254,6 +269,8 @@ func TestStepCtx_Errorf_noParent(t *testing.T) { func TestStepCtx_Error_withParent(t *testing.T) { mockT := new(providerTMockStep) + mockT.SetRealT(t) + parentStep := allure.NewSimpleStep("parentStep", allure.NewParameters("paramParent1", "v1", "paramParent2", "v2")...) parentCtx := &stepCtx{t: mockT, currentStep: parentStep} step := allure.NewSimpleStep("testStep") @@ -266,6 +283,8 @@ func TestStepCtx_Error_withParent(t *testing.T) { func TestStepCtx_Error_noParent(t *testing.T) { mockT := new(providerTMockStep) + mockT.SetRealT(t) + step := allure.NewSimpleStep("testStep") ctx := stepCtx{t: mockT, currentStep: step} ctx.Error("test")