// Copyright 2009 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.package testingimport ()typeInternalExamplestruct { Name string F func() Output string Unordered bool}// RunExamples is an internal function but exported because it is cross-package;// it is part of the implementation of the "go test" command.func ( func(, string) (bool, error), []InternalExample) ( bool) { _, = runExamples(, )return}func runExamples( func(, string) (bool, error), []InternalExample) (, bool) { = true := newMatcher(, *match, "-test.run", *skip)varInternalExamplefor _, = range { , , := .fullName(nil, .Name)if ! {continue } = trueif !runExample() { = false } }return , }func sortLines( string) string { := strings.Split(, "\n")slices.Sort()returnstrings.Join(, "\n")}// processRunResult computes a summary and status of the result of running an example test.// stdout is the captured output from stdout of the test.// recovered is the result of invoking recover after running the test, in case it panicked.//// If stdout doesn't match the expected output or if recovered is non-nil, it'll print the cause of failure to stdout.// If the test is chatty/verbose, it'll print a success message to stdout.// If recovered is non-nil, it'll panic with that value.// If the test panicked with nil, or invoked runtime.Goexit, it'll be// made to fail and panic with errNilPanicOrGoexitfunc ( *InternalExample) ( string, time.Duration, bool, any) ( bool) { = true := fmtDuration()varstring := strings.TrimSpace() := strings.TrimSpace(.Output)if .Unordered {ifsortLines() != sortLines() && == nil { = fmt.Sprintf("got:\n%s\nwant (unordered):\n%s\n", , .Output) } } else {if != && == nil { = fmt.Sprintf("got:\n%s\nwant:\n%s\n", , ) } }if != "" || ! || != nil {fmt.Printf("%s--- FAIL: %s (%s)\n%s", chatty.prefix(), .Name, , ) = false } elseifchatty.on {fmt.Printf("%s--- PASS: %s (%s)\n", chatty.prefix(), .Name, ) }ifchatty.on && chatty.json {fmt.Printf("%s=== NAME %s\n", chatty.prefix(), "") }if != nil {// Propagate the previously recovered result, by panicking.panic() } elseif ! {panic(errNilPanicOrGoexit) }return}
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.