Commit e330c753 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent e8cfd4db
......@@ -28,6 +28,7 @@ import (
"fmt"
"os"
"os/exec"
"regexp"
"strings"
"sync"
"testing"
......@@ -179,6 +180,18 @@ func verifyInSubprocess(t *testing.T, f func(t *testing.T), targvExtra ...string
if !ok {
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 = append(argv, targvExtra...)
cmd := exec.Command(os.Args[0], argv...)
......@@ -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)
}
if out != expectOK.outputRe { // XXX match with re
badf("unexpected output:\n%s\nwant: %s\n", out, expectOK.outputRe)
if !outputRe.MatchString(out) {
badf("unexpected output:\n%s\nwant: ~\n%s\n", out, expectOK.output)
}
if bad != "" {
......@@ -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.
type testExpect struct {
exitCode int
outputRe string
output string
}
// testExpectMap maps <test name> -> testExpect.
var testExpectMap = map[string]testExpect{
"Test2ThreadsOK": {0, ""},
"TestDeadlock": {1, `
--- FAIL: TestDeadlock (.+s)
example_test.go:159: t2: recv: deadlock waiting for *tracetest_test.eventHi
example_test.go:159: test shutdown: #streams: 2, #(pending events): 1
"TestDeadlock": {1,
`--- FAIL: TestDeadlock (<TIME>)
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
# 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
# t2
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