Skip to content

Commit e762ab3

Browse files
committed
do not print skipped TestResults as failure, add Skipped count to summary
1 parent 2e5766a commit e762ab3

5 files changed

Lines changed: 33 additions & 11 deletions

File tree

pkg/output/cli.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type TestResult struct {
4444
FailedProperty string
4545
Diff string
4646
Error error
47-
Skip bool
47+
Skipped bool
4848
}
4949

5050
// GetEventHandler create a new runtime.EventHandler
@@ -91,7 +91,7 @@ func (w *OutputWriter) printResult(r TestResult) {
9191
}
9292

9393
func (w *OutputWriter) printSkip(r TestResult) {
94-
w.fprintf(fmt.Sprintf("- [skipped] %s: was skipped", r.Title))
94+
w.fprintf(fmt.Sprintf("- [skipped] %s", r.Title))
9595
}
9696

9797
func (w *OutputWriter) printFailures(results []runtime.TestResult) {
@@ -106,7 +106,7 @@ func (w *OutputWriter) printFailures(results []runtime.TestResult) {
106106
w.fprintf(r.Error.Error())
107107
continue
108108
}
109-
if !r.Success {
109+
if !r.Success && !r.Skipped {
110110
w.fprintf(w.au.Bold(w.au.Red(w.template.failures(r))))
111111
w.fprintf(r.Diff)
112112
}
@@ -130,7 +130,7 @@ func convertTestResult(tr runtime.TestResult) TestResult {
130130
FailedProperty: tr.FailedProperty,
131131
Diff: tr.ValidationResult.Diff,
132132
Error: tr.TestCase.Result.Error,
133-
Skip: tr.Skipped,
133+
Skipped: tr.Skipped,
134134
}
135135

136136
return testResult

pkg/output/cli_template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var commanderTmpl = `
4040
4141
// Summary
4242
{{define "summary" -}}
43-
Count: {{len .TestResults}}, Failed: {{ .Failed }}
43+
Count: {{len .TestResults}}, Failed: {{ .Failed }}, Skipped: {{ .Skipped }}
4444
{{- end -}}
4545
4646
// Result

pkg/output/cli_test.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,28 @@ func Test_EventHandlerTestFinished(t *testing.T) {
3030

3131
for _, tr := range testResults {
3232
eh.TestFinished(tr)
33-
3433
}
3534

3635
output := buf.String()
37-
3836
assert.Contains(t, output, "✗ [192.168.0.1] Failed test")
3937
assert.Contains(t, output, "✓ [docker-host] Successful test")
38+
}
39+
40+
func Test_EventHandlerTestSkipped(t *testing.T) {
41+
var buf bytes.Buffer
42+
writer := NewCliOutput(true)
43+
writer.out = &buf
44+
eh := writer.GetEventHandler()
45+
46+
testResults := createFakeTestResults()
4047

48+
for _, tr := range testResults {
49+
if tr.Skipped {
50+
eh.TestSkipped(tr)
51+
}
52+
}
53+
output := buf.String()
54+
assert.Contains(t, output, "- [skipped] Skipped test")
4155
}
4256

4357
func Test_PrintSummary(t *testing.T) {
@@ -98,5 +112,15 @@ func createFakeTestResults() []runtime.TestResult {
98112
Tries: 2,
99113
}
100114

101-
return []runtime.TestResult{tr, tr2, tr3}
115+
tr4 := runtime.TestResult{
116+
TestCase: runtime.TestCase{
117+
Title: "Skipped test",
118+
Command: runtime.CommandUnderTest{},
119+
},
120+
FailedProperty: "Stdout",
121+
Node: "192.168.0.1",
122+
Skipped: true,
123+
}
124+
125+
return []runtime.TestResult{tr, tr2, tr3, tr4}
102126
}

pkg/runtime/runner.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ func (r *Runner) Run(tests []TestCase) <-chan TestResult {
3131
defer wg.Done()
3232

3333
for t := range tests {
34-
// If test is disabled skip it
3534
if t.Skip {
3635
tr := TestResult{TestCase: t, Skipped: true}
3736
out <- tr

pkg/runtime/runtime.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,11 @@ func (r *Runtime) Start(tests []TestCase) Result {
141141
continue
142142
}
143143

144-
r.EventHandler.TestFinished(tr)
145-
146144
if !tr.ValidationResult.Success {
147145
result.Failed++
148146
}
149147

148+
r.EventHandler.TestFinished(tr)
150149
result.TestResults = append(result.TestResults, tr)
151150
}
152151
result.Duration = time.Since(start)

0 commit comments

Comments
 (0)