// 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 && !wasip1// 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 runExample( InternalExample) ( bool) {ifchatty.on {fmt.Printf("%s=== RUN %s\n", chatty.prefix(), .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.7.0-preview. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.