cmd/gogio: send all e2e logs to t.Logf

chromedp was defaulting to log.Printf, which is not good for tests.

The xgb and xgbutil logs were suppressed if -v wasn't given, but they
were sent straight to os.Stderr otherwise:

	=== RUN   TestX11
	=== PAUSE TestX11
	=== CONT  TestX11
	XGB: conn.go:47: Could not get authority info: EOF
	XGB: conn.go:48: Trying connection without authority info...
	--- PASS: TestX11 (0.87s)

Instead, direct their loggers to an io.Writer implementation that sends
its output to t.Logf:

	=== RUN   TestX11
	=== PAUSE TestX11
	=== CONT  TestX11
	    TestX11: x11_test.go:187: XGB: conn.go:47: Could not get authority info: EOF
	    TestX11: x11_test.go:187: XGB: conn.go:48: Trying connection without authority info...
	--- PASS: TestX11 (0.86s)

We do end up with duplicate log prefixes, but at least we don't write
straight to stderr, which will be a problem as we add more concurrent
tests.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
This commit is contained in:
Daniel Martí
2019-10-30 15:46:11 +00:00
committed by Elias Naur
parent dc7af8fba3
commit d6f5902c5e
2 changed files with 21 additions and 5 deletions
+4 -1
View File
@@ -66,7 +66,10 @@ func TestJSOnChrome(t *testing.T) {
actx, cancel := chromedp.NewExecAllocator(context.Background(), opts...)
defer cancel()
ctx, cancel := chromedp.NewContext(actx)
ctx, cancel := chromedp.NewContext(actx,
// Send all logf/errf calls to t.Logf
chromedp.WithLogf(t.Logf),
)
defer cancel()
if err := chromedp.Run(ctx); err != nil {