github.com/getgauge/gauge@v1.6.9/execution/result/result.go (about) 1 /*---------------------------------------------------------------- 2 * Copyright (c) ThoughtWorks, Inc. 3 * Licensed under the Apache License, Version 2.0 4 * See LICENSE in the project root for license information. 5 *----------------------------------------------------------------*/ 6 7 package result 8 9 import "github.com/getgauge/gauge-proto/go/gauge_messages" 10 11 // Result represents execution result 12 type Result interface { 13 GetPreHook() []*gauge_messages.ProtoHookFailure 14 GetPostHook() []*gauge_messages.ProtoHookFailure 15 GetFailed() bool 16 17 AddPreHook(...*gauge_messages.ProtoHookFailure) 18 AddPostHook(...*gauge_messages.ProtoHookFailure) 19 SetFailure() 20 21 Item() interface{} 22 ExecTime() int64 23 } 24 25 // ExecTimeTracker is an interface for tracking execution time 26 type ExecTimeTracker interface { 27 AddExecTime(int64) 28 } 29 30 // GetProtoHookFailure returns the failure result of hook execution 31 func GetProtoHookFailure(executionResult *gauge_messages.ProtoExecutionResult) *(gauge_messages.ProtoHookFailure) { 32 return &gauge_messages.ProtoHookFailure{ 33 StackTrace: executionResult.StackTrace, 34 ErrorMessage: executionResult.ErrorMessage, 35 FailureScreenshotFile: executionResult.FailureScreenshotFile, 36 TableRowIndex: -1, 37 } 38 } 39 40 // AddPreHook adds the before hook execution result to the actual result object 41 func AddPreHook(result Result, executionResult *gauge_messages.ProtoExecutionResult) { 42 if executionResult.GetFailed() { 43 result.AddPreHook(GetProtoHookFailure(executionResult)) 44 result.SetFailure() 45 } 46 } 47 48 // AddPostHook adds the after hook execution result to the actual result object 49 func AddPostHook(result Result, executionResult *gauge_messages.ProtoExecutionResult) { 50 if executionResult.GetFailed() { 51 result.AddPostHook(GetProtoHookFailure(executionResult)) 52 result.SetFailure() 53 } 54 }