github.com/ezbuy/gauge@v0.9.4-0.20171013092048-7ac5bd3931cd/execution/result/specResult.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 ( 21 "github.com/getgauge/gauge/gauge_messages" 22 ) 23 24 type SpecResult struct { 25 ProtoSpec *gauge_messages.ProtoSpec 26 ScenarioFailedCount int 27 ScenarioCount int 28 IsFailed bool 29 FailedDataTableRows []int32 30 ExecutionTime int64 31 Skipped bool 32 ScenarioSkippedCount int 33 Errors []*gauge_messages.Error 34 } 35 36 func (specResult *SpecResult) SetFailure() { 37 specResult.IsFailed = true 38 } 39 40 func (specResult *SpecResult) SetSkipped(skipped bool) { 41 specResult.Skipped = skipped 42 } 43 44 func (specResult *SpecResult) AddSpecItems(resolvedItems []*gauge_messages.ProtoItem) { 45 specResult.ProtoSpec.Items = append(specResult.ProtoSpec.Items, resolvedItems...) 46 } 47 48 func (specResult *SpecResult) AddScenarioResults(scenarioResults []Result) { 49 for _, scenarioResult := range scenarioResults { 50 if scenarioResult.GetFailed() { 51 specResult.IsFailed = true 52 specResult.ScenarioFailedCount++ 53 } 54 specResult.AddExecTime(scenarioResult.ExecTime()) 55 specResult.ProtoSpec.Items = append(specResult.ProtoSpec.Items, &gauge_messages.ProtoItem{ItemType: gauge_messages.ProtoItem_Scenario, Scenario: scenarioResult.Item().(*gauge_messages.ProtoScenario)}) 56 } 57 specResult.ScenarioCount += len(scenarioResults) 58 } 59 60 func (specResult *SpecResult) AddTableRelatedScenarioResult(scenarioResults [][]Result, index int) { 61 numberOfScenarios := len(scenarioResults[0]) 62 63 for scenarioIndex := 0; scenarioIndex < numberOfScenarios; scenarioIndex++ { 64 scenarioFailed := false 65 for _, eachRow := range scenarioResults { 66 protoScenario := eachRow[scenarioIndex].Item().(*gauge_messages.ProtoScenario) 67 specResult.AddExecTime(protoScenario.GetExecutionTime()) 68 if protoScenario.GetExecutionStatus() == gauge_messages.ExecutionStatus_FAILED { 69 scenarioFailed = true 70 specResult.FailedDataTableRows = append(specResult.FailedDataTableRows, int32(index)) 71 } 72 protoTableDrivenScenario := &gauge_messages.ProtoTableDrivenScenario{Scenario: protoScenario, TableRowIndex: int32(index)} 73 protoItem := &gauge_messages.ProtoItem{ItemType: gauge_messages.ProtoItem_TableDrivenScenario, TableDrivenScenario: protoTableDrivenScenario} 74 specResult.ProtoSpec.Items = append(specResult.ProtoSpec.Items, protoItem) 75 } 76 if scenarioFailed { 77 specResult.ScenarioFailedCount++ 78 specResult.IsFailed = true 79 } 80 } 81 specResult.ProtoSpec.IsTableDriven = true 82 specResult.ScenarioCount += numberOfScenarios 83 } 84 85 func (specResult *SpecResult) AddExecTime(execTime int64) { 86 specResult.ExecutionTime += execTime 87 } 88 89 func (specResult *SpecResult) GetPreHook() []*gauge_messages.ProtoHookFailure { 90 return specResult.ProtoSpec.PreHookFailures 91 } 92 93 func (specResult *SpecResult) GetPostHook() []*gauge_messages.ProtoHookFailure { 94 return specResult.ProtoSpec.PostHookFailures 95 } 96 97 func (specResult *SpecResult) AddPreHook(f ...*gauge_messages.ProtoHookFailure) { 98 specResult.ProtoSpec.PreHookFailures = append(specResult.ProtoSpec.PreHookFailures, f...) 99 } 100 101 func (specResult *SpecResult) AddPostHook(f ...*gauge_messages.ProtoHookFailure) { 102 specResult.ProtoSpec.PostHookFailures = append(specResult.ProtoSpec.PostHookFailures, f...) 103 } 104 105 func (specResult *SpecResult) ExecTime() int64 { 106 return specResult.ExecutionTime 107 } 108 109 func (specResult *SpecResult) GetFailed() bool { 110 return specResult.IsFailed 111 } 112 113 func (specResult *SpecResult) Item() interface{} { 114 return specResult.ProtoSpec 115 }