Commits

Jiri Simsa committed f432984

Failing test when they surface data races is optional and can be
enabled using a command-line flag.

  • Participants
  • Parent commits 465ab89

Comments (0)

Files changed (2)

 	gc_endRE = "(PASS|FAIL): [^:]+:[^:]+: ([A-Za-z_][[:word:]]*).([A-Za-z_][[:word:]]*)([[:space:]]+([0-9]+.[0-9]+))?"
 )
 
+var (
+	failOnRace = false
+)
+
 type Test struct {
 	Name, Time, Message string
 	Failed              bool
 			if tokens[2] != curTest.Name {
 				return nil, fmt.Errorf("%d: name mismatch", lnum)
 			}
-			curTest.Failed = (tokens[1] == "FAIL") || hasDatarace(out)
+			curTest.Failed = (tokens[1] == "FAIL") || (failOnRace && hasDatarace(out))
 			curTest.Skipped = (tokens[1] == "SKIP")
 			curTest.Time = tokens[3]
 			curTest.Message = strings.Join(out, "\n")
 	showVersion := flag.Bool("version", false, "print version and exit")
 	bamboo := flag.Bool("bamboo", false, "xml compatible with Atlassian's Bamboo")
 	is_gocheck := flag.Bool("gocheck", false, "parse gocheck output")
+	flag.BoolVar(&failOnRace, "fail-on-race", false, "mark test as failing if it exposes a data race")
 	flag.Parse()
 
 	if *showVersion {
 }
 
 func Test_parseDatarace(t *testing.T) {
+	failOnRace = true
 	filename := "data/gotest-datarace.out"
 	suites, err := loadGotest(filename, t)
 	if err != nil {
 	if suite.NumFailed() != numFailed {
 		t.Fatalf("wrong number of failed %d, should be %d", suite.NumFailed(), numFailed)
 	}
+	failOnRace = false
+}
+
+func Test_ignoreDatarace(t *testing.T) {
+	filename := "data/gotest-datarace.out"
+	suites, err := loadGotest(filename, t)
+	if err != nil {
+		t.Fatalf("error loading %s - %s", filename, err)
+	}
+
+	suite := suites[0]
+	tests := suite.Tests
+	numTests := 1
+	if len(tests) != numTests {
+		t.Fatalf("got %d tests instead of %d", len(tests), numTests)
+	}
+
+	expectedMessage := "WARNING: DATA RACE"
+	for i, test := range suite.Tests {
+		if test.Message != expectedMessage {
+			t.Errorf(
+				"test %v message does not match expected result:\n\tGot: \"%v\"\n\tExpected: \"%v\"\n",
+				i,
+				test.Message,
+				expectedMessage)
+		}
+	}
+	numFailed := 0
+	if suite.NumFailed() != numFailed {
+		t.Fatalf("wrong number of failed %d, should be %d", suite.NumFailed(), numFailed)
+	}
 }
 
 func Test_parseLogOutput(t *testing.T) {