Commits

Thomas Pelletier committed 068ad50 Draft

Apply patch from github.com/pelletier/go2xunit

* Make it compliant with Go 1.0.2
* Fix the edge-case of the last test failing.

Comments (0)

Files changed (1)

 	reader := bufio.NewReader(rd)
 	var test *Test = nil
 	for {
-		/* FIXME: Handle isPrefix */
 		buf, _, err := reader.ReadLine()
 
 		switch err {
 		}
 
 		line := string(buf)
+
 		switch {
 		case strings.HasPrefix(line, startPrefix):
+		case strings.HasPrefix(line, failPrefix):
+			// We are switching to the next test, so store the
+			// current one.
 			if test != nil {
 				tests = append(tests, test)
 			}
-			test = &Test{Name: line[len(startPrefix):]}
-		case strings.HasPrefix(line, failPrefix):
-			if test == nil {
-				return nil, fmt.Errorf("fail not inside test")
-			}
-			test.Failed = true
-			name, time, err := parseEnd(failPrefix, line)
-			if err != nil {
-				return nil, err
-			}
-			if name != test.Name {
-				return nil, fmt.Errorf("wrong test end (%s!=%s)", name, test.Name)
-			}
-			test.Time = time
-		case strings.HasPrefix(line, passPrefix):
-			if test == nil {
-				return nil, fmt.Errorf("pass not inside test")
-			}
-			test.Failed = false
+
+			// Extract the test name and the duration:
 			name, time, err := parseEnd(passPrefix, line)
 			if err != nil {
 				return nil, err
 			}
-			if name != test.Name {
-				return nil, fmt.Errorf("wrong test end (%s!=%s)", name, test.Name)
+
+			test = &Test{
+				Name: name,
+				Time: time,
+				Failed: true,
 			}
-			test.Time = time
+
+		case strings.HasPrefix(line, passPrefix):
+			// We are switching to the next test, so store the
+			// current one.
+			if test != nil {
+				tests = append(tests, test)
+			}
+			// Extract the test name and the duration:
+			name, time, err := parseEnd(passPrefix, line)
+			if err != nil {
+				return nil, err
+			}
+
+			// Create the test structure and store it.
+			tests = append(tests, &Test{
+				Name: name,
+				Time: time,
+				Failed: false,
+			})
+			test = nil
+		case line == "FAIL":
+			// Handle the edge case of the last test failing: the
+			// following line will be "FAIL", so we just stop there.
+			tests = append(tests, test)
+			test = nil
 		default:
 			if test != nil { // test != nil marks we're in the middle of a test
 				test.Message += line + "\n"