github.com/mattdotmatt/gauge@v0.3.2-0.20160421115137-425a4cdccb62/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  	"github.com/golang/protobuf/proto"
    23  )
    24  
    25  type SpecResult struct {
    26  	ProtoSpec            *gauge_messages.ProtoSpec
    27  	ScenarioFailedCount  int
    28  	ScenarioCount        int
    29  	IsFailed             bool
    30  	FailedDataTableRows  []int32
    31  	ExecutionTime        int64
    32  	Skipped              bool
    33  	ScenarioSkippedCount int
    34  }
    35  
    36  func (specResult *SpecResult) SetFailure() {
    37  	specResult.IsFailed = true
    38  }
    39  
    40  func (specResult *SpecResult) AddSpecItems(resolvedItems []*gauge_messages.ProtoItem) {
    41  	specResult.ProtoSpec.Items = append(specResult.ProtoSpec.Items, resolvedItems...)
    42  }
    43  
    44  func (specResult *SpecResult) AddScenarioResults(scenarioResults []*ScenarioResult) {
    45  	for _, scenarioResult := range scenarioResults {
    46  		if scenarioResult.ProtoScenario.GetFailed() {
    47  			specResult.IsFailed = true
    48  			specResult.ScenarioFailedCount++
    49  		}
    50  		specResult.AddExecTime(scenarioResult.ProtoScenario.GetExecutionTime())
    51  		specResult.ProtoSpec.Items = append(specResult.ProtoSpec.Items, &gauge_messages.ProtoItem{ItemType: gauge_messages.ProtoItem_Scenario.Enum(), Scenario: scenarioResult.ProtoScenario})
    52  	}
    53  	specResult.ScenarioCount += len(scenarioResults)
    54  }
    55  
    56  func (specResult *SpecResult) AddTableDrivenScenarioResult(scenarioResults [][](*ScenarioResult)) {
    57  	numberOfScenarios := len(scenarioResults[0])
    58  
    59  	for scenarioIndex := 0; scenarioIndex < numberOfScenarios; scenarioIndex++ {
    60  		protoTableDrivenScenario := &gauge_messages.ProtoTableDrivenScenario{Scenarios: make([]*gauge_messages.ProtoScenario, 0)}
    61  		scenarioFailed := false
    62  		for rowIndex, eachRow := range scenarioResults {
    63  			protoScenario := eachRow[scenarioIndex].ProtoScenario
    64  			protoTableDrivenScenario.Scenarios = append(protoTableDrivenScenario.GetScenarios(), protoScenario)
    65  			specResult.AddExecTime(protoScenario.GetExecutionTime())
    66  			if protoScenario.GetFailed() {
    67  				scenarioFailed = true
    68  				specResult.FailedDataTableRows = append(specResult.FailedDataTableRows, int32(rowIndex))
    69  			}
    70  		}
    71  		if scenarioFailed {
    72  			specResult.ScenarioFailedCount++
    73  			specResult.IsFailed = true
    74  		}
    75  		protoItem := &gauge_messages.ProtoItem{ItemType: gauge_messages.ProtoItem_TableDrivenScenario.Enum(), TableDrivenScenario: protoTableDrivenScenario}
    76  		specResult.ProtoSpec.Items = append(specResult.ProtoSpec.Items, protoItem)
    77  	}
    78  	specResult.ProtoSpec.IsTableDriven = proto.Bool(true)
    79  	specResult.ScenarioCount += numberOfScenarios
    80  }
    81  
    82  func (specResult *SpecResult) AddExecTime(execTime int64) {
    83  	specResult.ExecutionTime += execTime
    84  }
    85  
    86  func (specResult *SpecResult) getPreHook() **(gauge_messages.ProtoHookFailure) {
    87  	return &specResult.ProtoSpec.PreHookFailure
    88  }
    89  
    90  func (specResult *SpecResult) getPostHook() **(gauge_messages.ProtoHookFailure) {
    91  	return &specResult.ProtoSpec.PostHookFailure
    92  }
    93  
    94  func (specResult *SpecResult) setFileName(fileName string) {
    95  	specResult.ProtoSpec.FileName = proto.String(fileName)
    96  }