Commit e330c753 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent e8cfd4db
...@@ -28,6 +28,7 @@ import ( ...@@ -28,6 +28,7 @@ import (
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
"regexp"
"strings" "strings"
"sync" "sync"
"testing" "testing"
...@@ -179,6 +180,18 @@ func verifyInSubprocess(t *testing.T, f func(t *testing.T), targvExtra ...string ...@@ -179,6 +180,18 @@ func verifyInSubprocess(t *testing.T, f func(t *testing.T), targvExtra ...string
if !ok { if !ok {
panic(fmt.Sprintf("testExpectMap[%q] not defined", t.Name())) panic(fmt.Sprintf("testExpectMap[%q] not defined", t.Name()))
} }
outputOK := regexp.QuoteMeta(expectOK.output)
// empty line -> kind of "<BLANKLINE>"
for {
__ := strings.ReplaceAll(outputOK, "\n\n", "\n\\s*\n")
if __ == outputOK {
break
}
outputOK = __
}
outputOK = strings.ReplaceAll(outputOK, "<TIME>", ".+s")
outputOK = strings.ReplaceAll(outputOK, "<LINE>", "[0-9]+")
outputRe := regexp.MustCompile(outputOK)
argv := []string{"-test.run="+t.Name()} argv := []string{"-test.run="+t.Name()}
argv = append(argv, targvExtra...) argv = append(argv, targvExtra...)
cmd := exec.Command(os.Args[0], argv...) cmd := exec.Command(os.Args[0], argv...)
...@@ -207,8 +220,8 @@ func verifyInSubprocess(t *testing.T, f func(t *testing.T), targvExtra ...string ...@@ -207,8 +220,8 @@ func verifyInSubprocess(t *testing.T, f func(t *testing.T), targvExtra ...string
badf("exit code: %d ; expected: %d", ecode, expectOK.exitCode) badf("exit code: %d ; expected: %d", ecode, expectOK.exitCode)
} }
if out != expectOK.outputRe { // XXX match with re if !outputRe.MatchString(out) {
badf("unexpected output:\n%s\nwant: %s\n", out, expectOK.outputRe) badf("unexpected output:\n%s\nwant: ~\n%s\n", out, expectOK.output)
} }
if bad != "" { if bad != "" {
...@@ -219,19 +232,27 @@ func verifyInSubprocess(t *testing.T, f func(t *testing.T), targvExtra ...string ...@@ -219,19 +232,27 @@ func verifyInSubprocess(t *testing.T, f func(t *testing.T), targvExtra ...string
// testExpect describes what result to expect from a test. // testExpect describes what result to expect from a test.
type testExpect struct { type testExpect struct {
exitCode int exitCode int
outputRe string output string
} }
// testExpectMap maps <test name> -> testExpect. // testExpectMap maps <test name> -> testExpect.
var testExpectMap = map[string]testExpect{ var testExpectMap = map[string]testExpect{
"Test2ThreadsOK": {0, ""}, "Test2ThreadsOK": {0, ""},
"TestDeadlock": {1, ` "TestDeadlock": {1,
--- FAIL: TestDeadlock (.+s) `--- FAIL: TestDeadlock (<TIME>)
example_test.go:159: t2: recv: deadlock waiting for *tracetest_test.eventHi example_test.go:161: t2: recv: deadlock waiting for *tracetest_test.eventHi
example_test.go:159: test shutdown: #streams: 2, #(pending events): 1 example_test.go:161: test shutdown: #streams: 2, #(pending events): 1
t1 <- tracetest_test.eventHi T1·A
# t2
tracetest.go:<LINE>: t1: send: canceled (test failed)
`},
"TestDeadlockQQQ": {1, `
--- FAIL: TestDeadlock \(.+s\)
example_test.go:161: t2: recv: deadlock waiting for *tracetest_test.eventHi
example_test.go:161: test shutdown: #streams: 2, #(pending events): 1
t1 <- tracetest_test.eventHi T1·A t1 <- tracetest_test.eventHi T1·A
# t2 # t2
tracetest.go:175: t1: send: canceled (test failed) tracetest.go:175: t1: send: canceled (test failed)
...
`}, `},
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment