mirror of
https://github.com/jstemmer/go-junit-report.git
synced 2025-04-08 06:28:08 -05:00
Add test for failing test output
Cleanup parser tests. Move test output to separate files.
This commit is contained in:
parent
4b851d63d2
commit
23311beb18
@ -1,19 +1,19 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestOutputPass(t *testing.T) {
|
type TestCase struct {
|
||||||
testOutputPass := `=== RUN TestOne
|
name string
|
||||||
--- PASS: TestOne (0.06 seconds)
|
expectedReport Report
|
||||||
=== RUN TestTwo
|
}
|
||||||
--- PASS: TestTwo (0.10 seconds)
|
|
||||||
PASS
|
|
||||||
ok package/name 0.160s`
|
|
||||||
|
|
||||||
expected := Report{
|
var testCases []TestCase = []TestCase{
|
||||||
|
{
|
||||||
|
name: "01-pass.txt",
|
||||||
|
expectedReport: Report{
|
||||||
Packages: []Package{
|
Packages: []Package{
|
||||||
{
|
{
|
||||||
Name: "package/name",
|
Name: "package/name",
|
||||||
@ -34,9 +34,43 @@ ok package/name 0.160s`
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "02-fail.txt",
|
||||||
|
expectedReport: Report{
|
||||||
|
Packages: []Package{
|
||||||
|
{
|
||||||
|
Name: "package/name",
|
||||||
|
Time: 151,
|
||||||
|
Tests: []Test{
|
||||||
|
{
|
||||||
|
Name: "TestOne",
|
||||||
|
Time: 20,
|
||||||
|
Result: FAIL,
|
||||||
|
Output: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "TestTwo",
|
||||||
|
Time: 130,
|
||||||
|
Result: PASS,
|
||||||
|
Output: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
report, err := Parse(strings.NewReader(testOutputPass))
|
func TestParser(t *testing.T) {
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
file, err := os.Open("tests/" + testCase.name)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
report, err := Parse(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error parsing: %s", err)
|
t.Fatalf("error parsing: %s", err)
|
||||||
}
|
}
|
||||||
@ -45,6 +79,7 @@ ok package/name 0.160s`
|
|||||||
t.Fatalf("Report == nil")
|
t.Fatalf("Report == nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
expected := testCase.expectedReport
|
||||||
if len(report.Packages) != len(expected.Packages) {
|
if len(report.Packages) != len(expected.Packages) {
|
||||||
t.Fatalf("Report packages == %d, want %d", len(report.Packages), len(expected.Packages))
|
t.Fatalf("Report packages == %d, want %d", len(report.Packages), len(expected.Packages))
|
||||||
}
|
}
|
||||||
@ -85,22 +120,4 @@ ok package/name 0.160s`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const testOutputFail = `=== RUN TestOne
|
|
||||||
--- FAIL: TestOne (0.02 seconds)
|
|
||||||
file_test.go:11: Error message
|
|
||||||
file_test.go:11: Longer
|
|
||||||
error
|
|
||||||
message.
|
|
||||||
=== RUN TestTwo
|
|
||||||
--- PASS: TestTwo (0.13 seconds)
|
|
||||||
FAIL
|
|
||||||
exit status 1
|
|
||||||
FAIL package/name 0.151s`
|
|
||||||
|
|
||||||
func TestOutputFail(t *testing.T) {
|
|
||||||
_, err := Parse(strings.NewReader(testOutputFail))
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("error parsing: %s", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
6
tests/01-pass.txt
Normal file
6
tests/01-pass.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
=== RUN TestOne
|
||||||
|
--- PASS: TestOne (0.06 seconds)
|
||||||
|
=== RUN TestTwo
|
||||||
|
--- PASS: TestTwo (0.10 seconds)
|
||||||
|
PASS
|
||||||
|
ok package/name 0.160s
|
11
tests/02-fail.txt
Normal file
11
tests/02-fail.txt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
=== RUN TestOne
|
||||||
|
--- FAIL: TestOne (0.02 seconds)
|
||||||
|
file_test.go:11: Error message
|
||||||
|
file_test.go:11: Longer
|
||||||
|
error
|
||||||
|
message.
|
||||||
|
=== RUN TestTwo
|
||||||
|
--- PASS: TestTwo (0.13 seconds)
|
||||||
|
FAIL
|
||||||
|
exit status 1
|
||||||
|
FAIL package/name 0.151s
|
Loading…
x
Reference in New Issue
Block a user