forked from getgauge/gauge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge.go
155 lines (141 loc) · 5.08 KB
/
merge.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// Copyright 2015 ThoughtWorks, Inc.
// This file is part of Gauge.
// Gauge is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Gauge is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Gauge. If not, see <http://www.gnu.org/licenses/>.
package execution
import (
"time"
"strings"
"github.com/getgauge/gauge/execution/result"
m "github.com/getgauge/gauge/gauge_messages"
)
func mergeDataTableSpecResults(sResult *result.SuiteResult) *result.SuiteResult {
suiteRes := result.NewSuiteResult(sResult.Tags, time.Now())
suiteRes.IsFailed = sResult.IsFailed
suiteRes.ExecutionTime = sResult.ExecutionTime
suiteRes.PostSuite = sResult.PostSuite
suiteRes.PreSuite = sResult.PreSuite
suiteRes.UnhandledErrors = sResult.UnhandledErrors
suiteRes.Timestamp = sResult.Timestamp
suiteRes.ProjectName = sResult.ProjectName
suiteRes.Environment = sResult.Environment
suiteRes.Tags = sResult.Tags
combinedResults := make(map[string][]*result.SpecResult)
for _, res := range sResult.SpecResults {
fileName := res.ProtoSpec.GetFileName()
combinedResults[fileName] = append(combinedResults[fileName], res)
}
for _, res := range combinedResults {
mergedRes := res[0]
if len(res) > 1 {
mergedRes = mergeResults(res)
}
if mergedRes.GetFailed() {
suiteRes.SpecsFailedCount++
} else if mergedRes.Skipped {
suiteRes.SpecsSkippedCount++
}
suiteRes.SpecResults = append(suiteRes.SpecResults, mergedRes)
}
return suiteRes
}
func mergeResults(results []*result.SpecResult) *result.SpecResult {
specResult := &result.SpecResult{ProtoSpec: &m.ProtoSpec{IsTableDriven: true}}
var scnResults []*m.ProtoItem
table := &m.ProtoTable{}
dataTableScnResults := make(map[string][]*m.ProtoTableDrivenScenario)
max := results[0].ExecutionTime
for _, res := range results {
specResult.ExecutionTime += res.ExecutionTime
specResult.Errors = res.Errors
if res.ExecutionTime > max {
max = res.ExecutionTime
}
if res.GetFailed() {
specResult.IsFailed = true
}
for _, item := range res.ProtoSpec.Items {
switch item.ItemType {
case m.ProtoItem_Scenario:
scnResults = append(scnResults, item)
modifySpecStats(item.Scenario, specResult)
case m.ProtoItem_TableDrivenScenario:
scnResults = append(scnResults, item)
heading := item.TableDrivenScenario.Scenario.ScenarioHeading
item.TableDrivenScenario.TableRowIndex = int32(len(table.Rows) - 1)
dataTableScnResults[heading] = append(dataTableScnResults[heading], item.TableDrivenScenario)
case m.ProtoItem_Table:
table.Headers = item.Table.Headers
table.Rows = append(table.Rows, item.Table.Rows...)
}
}
addHookFailure(table, res.GetPreHook(), specResult.AddPreHook)
addHookFailure(table, res.GetPostHook(), specResult.AddPostHook)
}
if InParallel {
specResult.ExecutionTime = max
}
aggregateDataTableScnStats(dataTableScnResults, specResult)
specResult.ProtoSpec.FileName = results[0].ProtoSpec.FileName
specResult.ProtoSpec.Tags = results[0].ProtoSpec.Tags
specResult.ProtoSpec.SpecHeading = results[0].ProtoSpec.SpecHeading
specResult.ProtoSpec.Items = getItems(table, scnResults, results)
return specResult
}
func addHookFailure(table *m.ProtoTable, f []*m.ProtoHookFailure, add func(...*m.ProtoHookFailure)) {
for _, h := range f {
h.TableRowIndex = int32(len(table.Rows) - 1)
}
add(f...)
}
func getItems(table *m.ProtoTable, scnResults []*m.ProtoItem, results []*result.SpecResult) (items []*m.ProtoItem) {
index := 0
for _, item := range results[0].ProtoSpec.Items {
switch item.ItemType {
case m.ProtoItem_Scenario, m.ProtoItem_TableDrivenScenario:
items = append(items, scnResults[index])
index++
case m.ProtoItem_Table:
items = append(items, &m.ProtoItem{ItemType: m.ProtoItem_Table, Table: table})
default:
items = append(items, item)
}
}
items = append(items, scnResults[index:]...)
return
}
func aggregateDataTableScnStats(results map[string][]*m.ProtoTableDrivenScenario, specResult *result.SpecResult) {
for _, dResult := range results {
isFailed := 0
isSkipped := 0
for _, res := range dResult {
if res.Scenario.ExecutionStatus == m.ExecutionStatus_FAILED {
isFailed = 1
} else if res.Scenario.ExecutionStatus == m.ExecutionStatus_SKIPPED &&
!strings.Contains(res.Scenario.SkipErrors[0], "--table-rows") {
isSkipped = 1
}
}
specResult.ScenarioFailedCount += isFailed
specResult.ScenarioSkippedCount += isSkipped
specResult.ScenarioCount++
}
}
func modifySpecStats(scn *m.ProtoScenario, specRes *result.SpecResult) {
switch scn.ExecutionStatus {
case m.ExecutionStatus_SKIPPED:
specRes.ScenarioSkippedCount++
return
case m.ExecutionStatus_FAILED:
specRes.ScenarioFailedCount++
}
specRes.ScenarioCount++
}