gitee.com/mirrors/gauge@v1.0.6/execution/result/result.go (about) 1 // Copyright 2015 ThoughtWorks, Inc. 2 3 // This file is part of Gauge. 4 5 // Gauge is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 10 // Gauge is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 15 // You should have received a copy of the GNU General Public License 16 // along with Gauge. If not, see <http://www.gnu.org/licenses/>. 17 18 package result 19 20 import "github.com/getgauge/gauge/gauge_messages" 21 22 // Result represents execution result 23 type Result interface { 24 GetPreHook() []*gauge_messages.ProtoHookFailure 25 GetPostHook() []*gauge_messages.ProtoHookFailure 26 GetFailed() bool 27 28 AddPreHook(...*gauge_messages.ProtoHookFailure) 29 AddPostHook(...*gauge_messages.ProtoHookFailure) 30 SetFailure() 31 32 Item() interface{} 33 ExecTime() int64 34 } 35 36 // ExecTimeTracker is an interface for tracking execution time 37 type ExecTimeTracker interface { 38 AddExecTime(int64) 39 } 40 41 // GetProtoHookFailure returns the failure result of hook execution 42 func GetProtoHookFailure(executionResult *gauge_messages.ProtoExecutionResult) *(gauge_messages.ProtoHookFailure) { 43 return &gauge_messages.ProtoHookFailure{StackTrace: executionResult.StackTrace, ErrorMessage: executionResult.ErrorMessage, FailureScreenshot: executionResult.ScreenShot, TableRowIndex: -1} 44 } 45 46 // AddPreHook adds the before hook execution result to the actual result object 47 func AddPreHook(result Result, executionResult *gauge_messages.ProtoExecutionResult) { 48 if executionResult.GetFailed() { 49 result.AddPreHook(GetProtoHookFailure(executionResult)) 50 result.SetFailure() 51 } 52 } 53 54 // AddPostHook adds the after hook execution result to the actual result object 55 func AddPostHook(result Result, executionResult *gauge_messages.ProtoExecutionResult) { 56 if executionResult.GetFailed() { 57 result.AddPostHook(GetProtoHookFailure(executionResult)) 58 result.SetFailure() 59 } 60 }