gitee.com/mirrors/gauge@v1.0.6/execution/result/suiteResult.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 "path/filepath" 22 "time" 23 24 "github.com/getgauge/gauge/config" 25 "github.com/getgauge/gauge/env" 26 "github.com/getgauge/gauge/gauge_messages" 27 ) 28 29 // SuitResult represents the result of suit execution 30 type SuiteResult struct { 31 SpecResults []*SpecResult 32 PreSuite *(gauge_messages.ProtoHookFailure) 33 PostSuite *(gauge_messages.ProtoHookFailure) 34 IsFailed bool 35 SpecsFailedCount int 36 ExecutionTime int64 //in milliseconds 37 UnhandledErrors []error 38 Environment string 39 Tags string 40 ProjectName string 41 Timestamp string 42 SpecsSkippedCount int 43 PreHookMessages []string 44 PostHookMessages []string 45 PreHookScreenshots [][]byte 46 PostHookScreenshots [][]byte 47 } 48 49 // NewSuiteResult is a constructor for SuitResult 50 func NewSuiteResult(tags string, startTime time.Time) *SuiteResult { 51 result := new(SuiteResult) 52 result.SpecResults = make([]*SpecResult, 0) 53 result.Timestamp = startTime.Format(config.LayoutForTimeStamp) 54 result.ProjectName = filepath.Base(config.ProjectRoot) 55 result.Environment = env.CurrentEnvironments() 56 result.Tags = tags 57 return result 58 } 59 60 // SetFailure sets the result to failed 61 func (sr *SuiteResult) SetFailure() { 62 sr.IsFailed = true 63 } 64 65 // SetSpecsSkippedCount sets the count of specs skipped. 66 func (sr *SuiteResult) SetSpecsSkippedCount() { 67 sr.SpecsSkippedCount = 0 68 for _, specRes := range sr.SpecResults { 69 if specRes.Skipped { 70 sr.SpecsSkippedCount++ 71 } 72 } 73 } 74 75 // AddUnhandledError adds the unhandled error to suit result. 76 func (sr *SuiteResult) AddUnhandledError(err error) { 77 sr.UnhandledErrors = append(sr.UnhandledErrors, err) 78 } 79 80 func (sr *SuiteResult) UpdateExecTime(startTime time.Time) { 81 sr.ExecutionTime = int64(time.Since(startTime) / 1e6) 82 } 83 84 // AddSpecResult adds a specs result to suit result. 85 func (sr *SuiteResult) AddSpecResult(specResult *SpecResult) { 86 if specResult.IsFailed { 87 sr.IsFailed = true 88 sr.SpecsFailedCount++ 89 } 90 sr.ExecutionTime += specResult.ExecutionTime 91 sr.SpecResults = append(sr.SpecResults, specResult) 92 } 93 94 // AddSpecResults adds multiple spec results to suit result. 95 func (sr *SuiteResult) AddSpecResults(specResults []*SpecResult) { 96 for _, result := range specResults { 97 sr.AddSpecResult(result) 98 } 99 } 100 101 func (sr *SuiteResult) GetPreHook() []*gauge_messages.ProtoHookFailure { 102 if sr.PreSuite == nil { 103 return []*gauge_messages.ProtoHookFailure{} 104 } 105 return []*gauge_messages.ProtoHookFailure{sr.PreSuite} 106 } 107 108 func (sr *SuiteResult) GetPostHook() []*gauge_messages.ProtoHookFailure { 109 if sr.PostSuite == nil { 110 return []*gauge_messages.ProtoHookFailure{} 111 } 112 return []*gauge_messages.ProtoHookFailure{sr.PostSuite} 113 } 114 115 func (sr *SuiteResult) AddPreHook(f ...*gauge_messages.ProtoHookFailure) { 116 sr.PreSuite = f[0] 117 } 118 119 func (sr *SuiteResult) AddPostHook(f ...*gauge_messages.ProtoHookFailure) { 120 sr.PostSuite = f[0] 121 } 122 123 // ExecTime returns the time taken to execute the suit 124 func (sr *SuiteResult) ExecTime() int64 { 125 return sr.ExecutionTime 126 } 127 128 // GetFailed returns the state of the result 129 func (sr *SuiteResult) GetFailed() bool { 130 return sr.IsFailed 131 } 132 133 func (sr *SuiteResult) Item() interface{} { 134 return nil 135 }