github.com/mattdotmatt/gauge@v0.3.2-0.20160421115137-425a4cdccb62/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) AddSpecResult(specResult *SpecResult) {
    59  	if specResult.IsFailed {
    60  		sr.IsFailed = true
    61  		sr.SpecsFailedCount++
    62  	}
    63  	sr.ExecutionTime += specResult.ExecutionTime
    64  	sr.SpecResults = append(sr.SpecResults, specResult)
    65  }
    66  
    67  func (sr *SuiteResult) AddSpecResults(specResults []*SpecResult) {
    68  	for _, result := range specResults {
    69  		sr.AddSpecResult(result)
    70  	}
    71  }
    72  
    73  func (sr *SuiteResult) getPreHook() **(gauge_messages.ProtoHookFailure) {
    74  	return &sr.PreSuite
    75  }
    76  
    77  func (sr *SuiteResult) getPostHook() **(gauge_messages.ProtoHookFailure) {
    78  	return &sr.PostSuite
    79  }