// Copyright 2019 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.//go:build !js// TODO(@musiol, @odeke-em): re-unify this entire file back into// example.go when js/wasm gets an os.Pipe implementation// and no longer needs this separation.package testingimport ()func ( InternalExample) ( bool) {if *chatty {fmt.Printf("=== RUN %s\n", .Name) }// Capture stdout. := os.Stdout , , := os.Pipe()if != nil {fmt.Fprintln(os.Stderr, )os.Exit(1) }os.Stdout = := make(chanstring)gofunc() {varstrings.Builder , := io.Copy(&, ) .Close()if != nil {fmt.Fprintf(os.Stderr, "testing: copying pipe: %v\n", )os.Exit(1) } <- .String() }() := false := time.Now()// Clean up in a deferred call so we can recover if the example panics.deferfunc() { := time.Since()// Close pipe, restore stdout, get output. .Close()os.Stdout = := <- := recover() = .processRunResult(, , , ) }()// Run example. .F() = truereturn}
The pages are generated with Goldsv0.4.9. (GOOS=linux GOARCH=amd64)