func appendResult(test JUnitXMLTest, results *core.TestResults) {
	results.NumTests++
	if test.Failure != nil {
		appendResult2(test, results, *test.Failure)
	} else if test.Error != nil {
		appendResult2(test, results, *test.Error)
	} else if test.Type == "FAILURE" || test.Success == "false" || test.Stacktrace != "" {
		appendResult2(test, results, JUnitXMLFailure{"", "FAILURE", test.Stacktrace})
	} else {
		results.Passed++
		results.Passes = append(results.Passes, test.Name)
	}
}
Exemple #2
0
func parseGoTestResults(data []byte) (core.TestResults, error) {
	results := core.TestResults{}
	lines := bytes.Split(data, []byte{'\n'})
	testsStarted := map[string]bool{}
	for i, line := range lines {
		testStartMatches := testStart.FindSubmatch(line)
		testResultMatches := testResult.FindSubmatch(line)
		if testStartMatches != nil {
			testsStarted[strings.TrimSpace(string(testStartMatches[1]))] = true
		} else if testResultMatches != nil {
			testName := strings.TrimSpace(string(testResultMatches[2]))
			if !testsStarted[testName] {
				continue
			}
			results.NumTests++
			if bytes.Equal(testResultMatches[1], []byte("PASS")) {
				results.Passed++
				results.Passes = append(results.Passes, testName)
			} else if bytes.Equal(testResultMatches[1], []byte("SKIP")) {
				results.Skipped++
				i++ // Skip following line too that has the reason for being skipped
			} else {
				output := ""
				for j := i + 1; j < len(lines) && !bytes.HasPrefix(lines[j], []byte("===")); j++ {
					output += string(lines[j]) + "\n"
					i = j
				}
				results.Failed++
				results.Failures = append(results.Failures, core.TestFailure{
					Name: testName, Type: "FAILURE", Traceback: output, Stdout: "", Stderr: "",
				})
			}
		} else if bytes.Equal(line, []byte("PASS")) {
			// Do nothing, all's well.
		} else if bytes.Equal(line, []byte("FAIL")) {
			if results.Failed == 0 {
				return results, fmt.Errorf("Test indicated final failure but no failures found yet")
			}
		}
	}
	return results, nil
}