=== RUN TestSampleSuccessful --- PASS: TestSampleSuccessful (0.00s) === RUN TestSampleFail --- FAIL: TestSampleFail (0.00s) Error Trace: samples_test.go:20 Error: Should be true Messages: Should be true === RUN TestSampleSuite === RUN TestSampleSuite/TestSuiteSampleFail === RUN TestSampleSuite/TestSuiteSampleSuccessful --- FAIL: TestSampleSuite (0.00s) --- FAIL: TestSampleSuite/TestSuiteSampleFail (0.0 Error Trace: samples_test.go:28 Error: Should be true Messages: Should be true --- PASS: TestSampleSuite/TestSuiteSampleSuccessful (0.00s) FAIL exit status 1 FAIL _/Users/Teodor/go2xunit_samples 0.016s
The output file generated by go2xunit is:
`<?xml version="1.0" encoding="UTF-8"?>
Error Trace: samples_test.go:20
Error: Should be true
Messages: Should be true]]>
`.
As you can see there are tags instead of error message.
The bug is caused by adding the error message to the curTest instead of adding it to the previous test. The fix that I came up through my mind is:
`// Returns previous test in a suite, for a given test. Returns error if previous
// test doesn't exist.
func getPreviousTest(suite *Suite, curTest *Test) (*Test, error) {
previousTestIndex := -1
for test_index, test := range suite.Tests {
if test.Name == curTest.Name {
previousTestIndex = test_index - 1
break
}
}
if previousTestIndex >= 0 {
return suite.Tests[previousTestIndex], nil
}
return nil, fmt.Errorf("Not found previous test of %s in suite %s", curTest.Name, suite.Name)
}
...
// ParseGotest parser output of gotest
// TODO: Make it shorter
func ParseGotest(rd io.Reader, suitePrefix string) (Suites, error) {
...
...
if Options.FailOnRace && hasDatarace(out) {
curTest.Status = Failed
}
curTest.Time = tokens[3]
if len(out) > 0 {
prevTest, err := getPreviousTest(curSuite, curTest)
if err == nil {
var test *Test
if prevTest.Status == Failed {
test = prevTest
} else {
test = curTest
}
test.Message = strings.Join(out, "\n")
} else {
curTest.Message = strings.Join(out, "\n")
}
}`
WDYT ?
Hello,
I think I found a bug for go 1.7.5. Here is test file:
` package go2xunitsample import ( "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" )
type SampleTestSuite struct { suite.Suite }
func TestSampleSuccessful(t *testing.T) { assert.True(t, true, "Should be true") }
func TestSampleFail(t *testing.T) { assert.True(t, false, "Should be true") }
func (suite *SampleTestSuite) TestSuiteSampleSuccessful() { suite.True(true, "Should be true") }
func (suite *SampleTestSuite) TestSuiteSampleFail() { suite.True(false, "Should be true") }
func TestSampleSuite(t *testing.T) { suite.Run(t, new(SampleTestSuite)) } `
For this case the result output is:
=== RUN TestSampleSuccessful --- PASS: TestSampleSuccessful (0.00s) === RUN TestSampleFail --- FAIL: TestSampleFail (0.00s) Error Trace: samples_test.go:20 Error: Should be true Messages: Should be true === RUN TestSampleSuite === RUN TestSampleSuite/TestSuiteSampleFail === RUN TestSampleSuite/TestSuiteSampleSuccessful --- FAIL: TestSampleSuite (0.00s) --- FAIL: TestSampleSuite/TestSuiteSampleFail (0.0 Error Trace: samples_test.go:28 Error: Should be true Messages: Should be true --- PASS: TestSampleSuite/TestSuiteSampleSuccessful (0.00s) FAIL exit status 1 FAIL _/Users/Teodor/go2xunit_samples 0.016s
The output file generated by go2xunit is: `<?xml version="1.0" encoding="UTF-8"?>