// 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
// +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 testing

import (
	
	
	
	
	
)

func runExample( 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(chan string)
	go func() {
		var  strings.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.
	defer func() {
		 := time.Since()

		// Close pipe, restore stdout, get output.
		.Close()
		os.Stdout = 
		 := <-

		 := recover()
		 = .processRunResult(, , , )
	}()

	// Run example.
	.F()
	 = true
	return
}