github.com/ezbuy/gauge@v0.9.4-0.20171013092048-7ac5bd3931cd/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  type SuiteResult struct {
    30  	SpecResults       []*SpecResult
    31  	PreSuite          *(gauge_messages.ProtoHookFailure)
    32  	PostSuite         *(gauge_messages.ProtoHookFailure)
    33  	IsFailed          bool
    34  	SpecsFailedCount  int
    35  	ExecutionTime     int64 //in milliseconds
    36  	UnhandledErrors   []error
    37  	Environment       string
    38  	Tags              string
    39  	ProjectName       string
    40  	Timestamp         string
    41  	SpecsSkippedCount int
    42  }
    43  
    44  func NewSuiteResult(tags string, startTime time.Time) *SuiteResult {
    45  	result := new(SuiteResult)
    46  	result.SpecResults = make([]*SpecResult, 0)
    47  	result.Timestamp = startTime.Format(config.LayoutForTimeStamp)
    48  	result.ProjectName = filepath.Base(config.ProjectRoot)
    49  	result.Environment = env.CurrentEnv()
    50  	result.Tags = tags
    51  	return result
    52  }
    53  
    54  func (sr *SuiteResult) SetFailure() {
    55  	sr.IsFailed = true
    56  }
    57  
    58  func (sr *SuiteResult) SetSpecsSkippedCount() {
    59  	sr.SpecsSkippedCount = 0
    60  	for _, specRes := range sr.SpecResults {
    61  		if specRes.Skipped {
    62  			sr.SpecsSkippedCount++
    63  		}
    64  	}
    65  }
    66  
    67  func (sr *SuiteResult) AddUnhandledError(err error) {
    68  	sr.UnhandledErrors = append(sr.UnhandledErrors, err)
    69  }
    70  
    71  func (sr *SuiteResult) UpdateExecTime(startTime time.Time) {
    72  	sr.ExecutionTime = int64(time.Since(startTime) / 1e6)
    73  }
    74  
    75  func (sr *SuiteResult) AddSpecResult(specResult *SpecResult) {
    76  	if specResult.IsFailed {
    77  		sr.IsFailed = true
    78  		sr.SpecsFailedCount++
    79  	}
    80  	sr.ExecutionTime += specResult.ExecutionTime
    81  	sr.SpecResults = append(sr.SpecResults, specResult)
    82  }
    83  
    84  func (sr *SuiteResult) AddSpecResults(specResults []*SpecResult) {
    85  	for _, result := range specResults {
    86  		sr.AddSpecResult(result)
    87  	}
    88  }
    89  
    90  func (sr *SuiteResult) GetPreHook() []*gauge_messages.ProtoHookFailure {
    91  	if sr.PreSuite == nil {
    92  		return []*gauge_messages.ProtoHookFailure{}
    93  	}
    94  	return []*gauge_messages.ProtoHookFailure{sr.PreSuite}
    95  }
    96  
    97  func (sr *SuiteResult) GetPostHook() []*gauge_messages.ProtoHookFailure {
    98  	if sr.PostSuite == nil {
    99  		return []*gauge_messages.ProtoHookFailure{}
   100  	}
   101  	return []*gauge_messages.ProtoHookFailure{sr.PostSuite}
   102  }
   103  
   104  func (sr *SuiteResult) AddPreHook(f ...*gauge_messages.ProtoHookFailure) {
   105  	sr.PreSuite = f[0]
   106  }
   107  
   108  func (sr *SuiteResult) AddPostHook(f ...*gauge_messages.ProtoHookFailure) {
   109  	sr.PostSuite = f[0]
   110  }
   111  
   112  func (sr *SuiteResult) ExecTime() int64 {
   113  	return sr.ExecutionTime
   114  }
   115  
   116  func (sr *SuiteResult) GetFailed() bool {
   117  	return sr.IsFailed
   118  }
   119  
   120  func (sr *SuiteResult) Item() interface{} {
   121  	return nil
   122  }