github.com/varialus/godfly@v0.0.0-20130904042352-1934f9f095ab/src/cmd/go/doc.go (about) 1 // Copyright 2011 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // DO NOT EDIT THIS FILE. GENERATED BY mkdoc.sh. 6 // Edit the documentation in other files and rerun mkdoc.sh to generate this one. 7 8 /* 9 Go is a tool for managing Go source code. 10 11 Usage: 12 13 go command [arguments] 14 15 The commands are: 16 17 build compile packages and dependencies 18 clean remove object files 19 env print Go environment information 20 fix run go tool fix on packages 21 fmt run gofmt on package sources 22 get download and install packages and dependencies 23 install compile and install packages and dependencies 24 list list packages 25 run compile and run Go program 26 test test packages 27 tool run specified go tool 28 version print Go version 29 vet run go tool vet on packages 30 31 Use "go help [command]" for more information about a command. 32 33 Additional help topics: 34 35 gopath GOPATH environment variable 36 packages description of package lists 37 remote remote import path syntax 38 testflag description of testing flags 39 testfunc description of testing functions 40 41 Use "go help [topic]" for more information about that topic. 42 43 44 Compile packages and dependencies 45 46 Usage: 47 48 go build [-o output] [build flags] [packages] 49 50 Build compiles the packages named by the import paths, 51 along with their dependencies, but it does not install the results. 52 53 If the arguments are a list of .go files, build treats them as a list 54 of source files specifying a single package. 55 56 When the command line specifies a single main package, 57 build writes the resulting executable to output. 58 Otherwise build compiles the packages but discards the results, 59 serving only as a check that the packages can be built. 60 61 The -o flag specifies the output file name. If not specified, the 62 output file name depends on the arguments and derives from the name 63 of the package, such as p.a for package p, unless p is 'main'. If 64 the package is main and file names are provided, the file name 65 derives from the first file name mentioned, such as f1 for 'go build 66 f1.go f2.go'; with no files provided ('go build'), the output file 67 name is the base name of the containing directory. 68 69 The build flags are shared by the build, install, run, and test commands: 70 71 -a 72 force rebuilding of packages that are already up-to-date. 73 -n 74 print the commands but do not run them. 75 -p n 76 the number of builds that can be run in parallel. 77 The default is the number of CPUs available. 78 -race 79 enable data race detection. 80 Supported only on linux/amd64, darwin/amd64 and windows/amd64. 81 -v 82 print the names of packages as they are compiled. 83 -work 84 print the name of the temporary work directory and 85 do not delete it when exiting. 86 -x 87 print the commands. 88 89 -ccflags 'arg list' 90 arguments to pass on each 5c, 6c, or 8c compiler invocation. 91 -compiler name 92 name of compiler to use, as in runtime.Compiler (gccgo or gc). 93 -gccgoflags 'arg list' 94 arguments to pass on each gccgo compiler/linker invocation. 95 -gcflags 'arg list' 96 arguments to pass on each 5g, 6g, or 8g compiler invocation. 97 -installsuffix suffix 98 a suffix to use in the name of the package installation directory, 99 in order to keep output separate from default builds. 100 If using the -race flag, the install suffix is automatically set to race 101 or, if set explicitly, has _race appended to it. 102 -ldflags 'flag list' 103 arguments to pass on each 5l, 6l, or 8l linker invocation. 104 -tags 'tag list' 105 a list of build tags to consider satisfied during the build. 106 See the documentation for the go/build package for 107 more information about build tags. 108 109 The list flags accept a space-separated list of strings. To embed spaces 110 in an element in the list, surround it with either single or double quotes. 111 112 For more about specifying packages, see 'go help packages'. 113 For more about where packages and binaries are installed, 114 see 'go help gopath'. 115 116 See also: go install, go get, go clean. 117 118 119 Remove object files 120 121 Usage: 122 123 go clean [-i] [-r] [-n] [-x] [packages] 124 125 Clean removes object files from package source directories. 126 The go command builds most objects in a temporary directory, 127 so go clean is mainly concerned with object files left by other 128 tools or by manual invocations of go build. 129 130 Specifically, clean removes the following files from each of the 131 source directories corresponding to the import paths: 132 133 _obj/ old object directory, left from Makefiles 134 _test/ old test directory, left from Makefiles 135 _testmain.go old gotest file, left from Makefiles 136 test.out old test log, left from Makefiles 137 build.out old test log, left from Makefiles 138 *.[568ao] object files, left from Makefiles 139 140 DIR(.exe) from go build 141 DIR.test(.exe) from go test -c 142 MAINFILE(.exe) from go build MAINFILE.go 143 *.so from SWIG 144 145 In the list, DIR represents the final path element of the 146 directory, and MAINFILE is the base name of any Go source 147 file in the directory that is not included when building 148 the package. 149 150 The -i flag causes clean to remove the corresponding installed 151 archive or binary (what 'go install' would create). 152 153 The -n flag causes clean to print the remove commands it would execute, 154 but not run them. 155 156 The -r flag causes clean to be applied recursively to all the 157 dependencies of the packages named by the import paths. 158 159 The -x flag causes clean to print remove commands as it executes them. 160 161 For more about specifying packages, see 'go help packages'. 162 163 164 Print Go environment information 165 166 Usage: 167 168 go env [var ...] 169 170 Env prints Go environment information. 171 172 By default env prints information as a shell script 173 (on Windows, a batch file). If one or more variable 174 names is given as arguments, env prints the value of 175 each named variable on its own line. 176 177 178 Run go tool fix on packages 179 180 Usage: 181 182 go fix [packages] 183 184 Fix runs the Go fix command on the packages named by the import paths. 185 186 For more about fix, see 'godoc fix'. 187 For more about specifying packages, see 'go help packages'. 188 189 To run fix with specific options, run 'go tool fix'. 190 191 See also: go fmt, go vet. 192 193 194 Run gofmt on package sources 195 196 Usage: 197 198 go fmt [-n] [-x] [packages] 199 200 Fmt runs the command 'gofmt -l -w' on the packages named 201 by the import paths. It prints the names of the files that are modified. 202 203 For more about gofmt, see 'godoc gofmt'. 204 For more about specifying packages, see 'go help packages'. 205 206 The -n flag prints commands that would be executed. 207 The -x flag prints commands as they are executed. 208 209 To run gofmt with specific options, run gofmt itself. 210 211 See also: go fix, go vet. 212 213 214 Download and install packages and dependencies 215 216 Usage: 217 218 go get [-d] [-fix] [-t] [-u] [build flags] [packages] 219 220 Get downloads and installs the packages named by the import paths, 221 along with their dependencies. 222 223 The -d flag instructs get to stop after downloading the packages; that is, 224 it instructs get not to install the packages. 225 226 The -fix flag instructs get to run the fix tool on the downloaded packages 227 before resolving dependencies or building the code. 228 229 The -t flag instructs get to also download the packages required to build 230 the tests for the specified packages. 231 232 The -u flag instructs get to use the network to update the named packages 233 and their dependencies. By default, get uses the network to check out 234 missing packages but does not use it to look for updates to existing packages. 235 236 Get also accepts all the flags in the 'go build' and 'go install' commands, 237 to control the installation. See 'go help build'. 238 239 When checking out or updating a package, get looks for a branch or tag 240 that matches the locally installed version of Go. The most important 241 rule is that if the local installation is running version "go1", get 242 searches for a branch or tag named "go1". If no such version exists it 243 retrieves the most recent version of the package. 244 245 For more about specifying packages, see 'go help packages'. 246 247 For more about how 'go get' finds source code to 248 download, see 'go help remote'. 249 250 See also: go build, go install, go clean. 251 252 253 Compile and install packages and dependencies 254 255 Usage: 256 257 go install [build flags] [packages] 258 259 Install compiles and installs the packages named by the import paths, 260 along with their dependencies. 261 262 For more about the build flags, see 'go help build'. 263 For more about specifying packages, see 'go help packages'. 264 265 See also: go build, go get, go clean. 266 267 268 List packages 269 270 Usage: 271 272 go list [-e] [-f format] [-json] [-tags 'tag list'] [packages] 273 274 List lists the packages named by the import paths, one per line. 275 276 The default output shows the package import path: 277 278 code.google.com/p/google-api-go-client/books/v1 279 code.google.com/p/goauth2/oauth 280 code.google.com/p/sqlite 281 282 The -f flag specifies an alternate format for the list, using the 283 syntax of package template. The default output is equivalent to -f 284 '{{.ImportPath}}'. One extra template function is available, "join", 285 which calls strings.Join. The struct being passed to the template is: 286 287 type Package struct { 288 Dir string // directory containing package sources 289 ImportPath string // import path of package in dir 290 Name string // package name 291 Doc string // package documentation string 292 Target string // install path 293 Goroot bool // is this package in the Go root? 294 Standard bool // is this package part of the standard Go library? 295 Stale bool // would 'go install' do anything for this package? 296 Root string // Go root or Go path dir containing this package 297 298 // Source files 299 GoFiles []string // .go source files (excluding CgoFiles, TestGoFiles, XTestGoFiles) 300 CgoFiles []string // .go sources files that import "C" 301 IgnoredGoFiles []string // .go sources ignored due to build constraints 302 CFiles []string // .c source files 303 CXXFiles []string // .cc, .cxx and .cpp source files 304 HFiles []string // .h, .hh, .hpp and .hxx source files 305 SFiles []string // .s source files 306 SwigFiles []string // .swig files 307 SwigCXXFiles []string // .swigcxx files 308 SysoFiles []string // .syso object files to add to archive 309 310 // Cgo directives 311 CgoCFLAGS []string // cgo: flags for C compiler 312 CgoCPPFLAGS []string // cgo: flags for C preprocessor 313 CgoCXXFLAGS []string // cgo: flags for C++ compiler 314 CgoLDFLAGS []string // cgo: flags for linker 315 CgoPkgConfig []string // cgo: pkg-config names 316 317 // Dependency information 318 Imports []string // import paths used by this package 319 Deps []string // all (recursively) imported dependencies 320 321 // Error information 322 Incomplete bool // this package or a dependency has an error 323 Error *PackageError // error loading package 324 DepsErrors []*PackageError // errors loading dependencies 325 326 TestGoFiles []string // _test.go files in package 327 TestImports []string // imports from TestGoFiles 328 XTestGoFiles []string // _test.go files outside package 329 XTestImports []string // imports from XTestGoFiles 330 } 331 332 The -json flag causes the package data to be printed in JSON format 333 instead of using the template format. 334 335 The -e flag changes the handling of erroneous packages, those that 336 cannot be found or are malformed. By default, the list command 337 prints an error to standard error for each erroneous package and 338 omits the packages from consideration during the usual printing. 339 With the -e flag, the list command never prints errors to standard 340 error and instead processes the erroneous packages with the usual 341 printing. Erroneous packages will have a non-empty ImportPath and 342 a non-nil Error field; other information may or may not be missing 343 (zeroed). 344 345 The -tags flag specifies a list of build tags, like in the 'go build' 346 command. 347 348 For more about specifying packages, see 'go help packages'. 349 350 351 Compile and run Go program 352 353 Usage: 354 355 go run [build flags] gofiles... [arguments...] 356 357 Run compiles and runs the main package comprising the named Go source files. 358 A Go source file is defined to be a file ending in a literal ".go" suffix. 359 360 For more about build flags, see 'go help build'. 361 362 See also: go build. 363 364 365 Test packages 366 367 Usage: 368 369 go test [-c] [-i] [build and test flags] [packages] [flags for test binary] 370 371 'Go test' automates testing the packages named by the import paths. 372 It prints a summary of the test results in the format: 373 374 ok archive/tar 0.011s 375 FAIL archive/zip 0.022s 376 ok compress/gzip 0.033s 377 ... 378 379 followed by detailed output for each failed package. 380 381 'Go test' recompiles each package along with any files with names matching 382 the file pattern "*_test.go". 383 Files whose names begin with "_" (including "_test.go") or "." are ignored. 384 These additional files can contain test functions, benchmark functions, and 385 example functions. See 'go help testfunc' for more. 386 Each listed package causes the execution of a separate test binary. 387 388 Test files that declare a package with the suffix "_test" will be compiled as a 389 separate package, and then linked and run with the main test binary. 390 391 By default, go test needs no arguments. It compiles and tests the package 392 with source in the current directory, including tests, and runs the tests. 393 394 The package is built in a temporary directory so it does not interfere with the 395 non-test installation. 396 397 In addition to the build flags, the flags handled by 'go test' itself are: 398 399 -c Compile the test binary to pkg.test but do not run it. 400 (Where pkg is the last element of the package's import path.) 401 402 -i 403 Install packages that are dependencies of the test. 404 Do not run the test. 405 406 The test binary also accepts flags that control execution of the test; these 407 flags are also accessible by 'go test'. See 'go help testflag' for details. 408 409 If the test binary needs any other flags, they should be presented after the 410 package names. The go tool treats as a flag the first argument that begins with 411 a minus sign that it does not recognize itself; that argument and all subsequent 412 arguments are passed as arguments to the test binary. 413 414 For more about build flags, see 'go help build'. 415 For more about specifying packages, see 'go help packages'. 416 417 See also: go build, go vet. 418 419 420 Run specified go tool 421 422 Usage: 423 424 go tool [-n] command [args...] 425 426 Tool runs the go tool command identified by the arguments. 427 With no arguments it prints the list of known tools. 428 429 The -n flag causes tool to print the command that would be 430 executed but not execute it. 431 432 For more about each tool command, see 'go tool command -h'. 433 434 435 Print Go version 436 437 Usage: 438 439 go version 440 441 Version prints the Go version, as reported by runtime.Version. 442 443 444 Run go tool vet on packages 445 446 Usage: 447 448 go vet [-n] [-x] [packages] 449 450 Vet runs the Go vet command on the packages named by the import paths. 451 452 For more about vet, see 'godoc code.google.com/p/go.tools/cmd/vet'. 453 For more about specifying packages, see 'go help packages'. 454 455 To run the vet tool with specific options, run 'go tool vet'. 456 457 The -n flag prints commands that would be executed. 458 The -x flag prints commands as they are executed. 459 460 See also: go fmt, go fix. 461 462 463 GOPATH environment variable 464 465 The Go path is used to resolve import statements. 466 It is implemented by and documented in the go/build package. 467 468 The GOPATH environment variable lists places to look for Go code. 469 On Unix, the value is a colon-separated string. 470 On Windows, the value is a semicolon-separated string. 471 On Plan 9, the value is a list. 472 473 GOPATH must be set to get, build and install packages outside the 474 standard Go tree. 475 476 Each directory listed in GOPATH must have a prescribed structure: 477 478 The src/ directory holds source code. The path below 'src' 479 determines the import path or executable name. 480 481 The pkg/ directory holds installed package objects. 482 As in the Go tree, each target operating system and 483 architecture pair has its own subdirectory of pkg 484 (pkg/GOOS_GOARCH). 485 486 If DIR is a directory listed in the GOPATH, a package with 487 source in DIR/src/foo/bar can be imported as "foo/bar" and 488 has its compiled form installed to "DIR/pkg/GOOS_GOARCH/foo/bar.a". 489 490 The bin/ directory holds compiled commands. 491 Each command is named for its source directory, but only 492 the final element, not the entire path. That is, the 493 command with source in DIR/src/foo/quux is installed into 494 DIR/bin/quux, not DIR/bin/foo/quux. The foo/ is stripped 495 so that you can add DIR/bin to your PATH to get at the 496 installed commands. If the GOBIN environment variable is 497 set, commands are installed to the directory it names instead 498 of DIR/bin. 499 500 Here's an example directory layout: 501 502 GOPATH=/home/user/gocode 503 504 /home/user/gocode/ 505 src/ 506 foo/ 507 bar/ (go code in package bar) 508 x.go 509 quux/ (go code in package main) 510 y.go 511 bin/ 512 quux (installed command) 513 pkg/ 514 linux_amd64/ 515 foo/ 516 bar.a (installed package object) 517 518 Go searches each directory listed in GOPATH to find source code, 519 but new packages are always downloaded into the first directory 520 in the list. 521 522 523 Description of package lists 524 525 Many commands apply to a set of packages: 526 527 go action [packages] 528 529 Usually, [packages] is a list of import paths. 530 531 An import path that is a rooted path or that begins with 532 a . or .. element is interpreted as a file system path and 533 denotes the package in that directory. 534 535 Otherwise, the import path P denotes the package found in 536 the directory DIR/src/P for some DIR listed in the GOPATH 537 environment variable (see 'go help gopath'). 538 539 If no import paths are given, the action applies to the 540 package in the current directory. 541 542 The special import path "all" expands to all package directories 543 found in all the GOPATH trees. For example, 'go list all' 544 lists all the packages on the local system. 545 546 The special import path "std" is like all but expands to just the 547 packages in the standard Go library. 548 549 An import path is a pattern if it includes one or more "..." wildcards, 550 each of which can match any string, including the empty string and 551 strings containing slashes. Such a pattern expands to all package 552 directories found in the GOPATH trees with names matching the 553 patterns. As a special case, x/... matches x as well as x's subdirectories. 554 For example, net/... expands to net and packages in its subdirectories. 555 556 An import path can also name a package to be downloaded from 557 a remote repository. Run 'go help remote' for details. 558 559 Every package in a program must have a unique import path. 560 By convention, this is arranged by starting each path with a 561 unique prefix that belongs to you. For example, paths used 562 internally at Google all begin with 'google', and paths 563 denoting remote repositories begin with the path to the code, 564 such as 'code.google.com/p/project'. 565 566 As a special case, if the package list is a list of .go files from a 567 single directory, the command is applied to a single synthesized 568 package made up of exactly those files, ignoring any build constraints 569 in those files and ignoring any other files in the directory. 570 571 File names that begin with "." or "_" are ignored by the go tool. 572 573 574 Remote import path syntax 575 576 An import path (see 'go help packages') denotes a package 577 stored in the local file system. Certain import paths also 578 describe how to obtain the source code for the package using 579 a revision control system. 580 581 A few common code hosting sites have special syntax: 582 583 Bitbucket (Git, Mercurial) 584 585 import "bitbucket.org/user/project" 586 import "bitbucket.org/user/project/sub/directory" 587 588 GitHub (Git) 589 590 import "github.com/user/project" 591 import "github.com/user/project/sub/directory" 592 593 Google Code Project Hosting (Git, Mercurial, Subversion) 594 595 import "code.google.com/p/project" 596 import "code.google.com/p/project/sub/directory" 597 598 import "code.google.com/p/project.subrepository" 599 import "code.google.com/p/project.subrepository/sub/directory" 600 601 Launchpad (Bazaar) 602 603 import "launchpad.net/project" 604 import "launchpad.net/project/series" 605 import "launchpad.net/project/series/sub/directory" 606 607 import "launchpad.net/~user/project/branch" 608 import "launchpad.net/~user/project/branch/sub/directory" 609 610 For code hosted on other servers, import paths may either be qualified 611 with the version control type, or the go tool can dynamically fetch 612 the import path over https/http and discover where the code resides 613 from a <meta> tag in the HTML. 614 615 To declare the code location, an import path of the form 616 617 repository.vcs/path 618 619 specifies the given repository, with or without the .vcs suffix, 620 using the named version control system, and then the path inside 621 that repository. The supported version control systems are: 622 623 Bazaar .bzr 624 Git .git 625 Mercurial .hg 626 Subversion .svn 627 628 For example, 629 630 import "example.org/user/foo.hg" 631 632 denotes the root directory of the Mercurial repository at 633 example.org/user/foo or foo.hg, and 634 635 import "example.org/repo.git/foo/bar" 636 637 denotes the foo/bar directory of the Git repository at 638 example.com/repo or repo.git. 639 640 When a version control system supports multiple protocols, 641 each is tried in turn when downloading. For example, a Git 642 download tries git://, then https://, then http://. 643 644 If the import path is not a known code hosting site and also lacks a 645 version control qualifier, the go tool attempts to fetch the import 646 over https/http and looks for a <meta> tag in the document's HTML 647 <head>. 648 649 The meta tag has the form: 650 651 <meta name="go-import" content="import-prefix vcs repo-root"> 652 653 The import-prefix is the import path corresponding to the repository 654 root. It must be a prefix or an exact match of the package being 655 fetched with "go get". If it's not an exact match, another http 656 request is made at the prefix to verify the <meta> tags match. 657 658 The vcs is one of "git", "hg", "svn", etc, 659 660 The repo-root is the root of the version control system 661 containing a scheme and not containing a .vcs qualifier. 662 663 For example, 664 665 import "example.org/pkg/foo" 666 667 will result in the following request(s): 668 669 https://example.org/pkg/foo?go-get=1 (preferred) 670 http://example.org/pkg/foo?go-get=1 (fallback) 671 672 If that page contains the meta tag 673 674 <meta name="go-import" content="example.org git https://code.org/r/p/exproj"> 675 676 the go tool will verify that https://example.org/?go-get=1 contains the 677 same meta tag and then git clone https://code.org/r/p/exproj into 678 GOPATH/src/example.org. 679 680 New downloaded packages are written to the first directory 681 listed in the GOPATH environment variable (see 'go help gopath'). 682 683 The go command attempts to download the version of the 684 package appropriate for the Go release being used. 685 Run 'go help install' for more. 686 687 688 Description of testing flags 689 690 The 'go test' command takes both flags that apply to 'go test' itself 691 and flags that apply to the resulting test binary. 692 693 Several of the flags control profiling and write an execution profile 694 suitable for "go tool pprof"; run "go tool pprof help" for more 695 information. The --alloc_space, --alloc_objects, and --show_bytes 696 options of pprof control how the information is presented. 697 698 The following flags are recognized by the 'go test' command and 699 control the execution of any test: 700 701 -bench regexp 702 Run benchmarks matching the regular expression. 703 By default, no benchmarks run. To run all benchmarks, 704 use '-bench .' or '-bench=.'. 705 706 -benchmem 707 Print memory allocation statistics for benchmarks. 708 709 -benchtime t 710 Run enough iterations of each benchmark to take t, specified 711 as a time.Duration (for example, -benchtime 1h30s). 712 The default is 1 second (1s). 713 714 -blockprofile block.out 715 Write a goroutine blocking profile to the specified file 716 when all tests are complete. 717 718 -blockprofilerate n 719 Control the detail provided in goroutine blocking profiles by 720 calling runtime.SetBlockProfileRate with n. 721 See 'godoc runtime SetBlockProfileRate'. 722 The profiler aims to sample, on average, one blocking event every 723 n nanoseconds the program spends blocked. By default, 724 if -test.blockprofile is set without this flag, all blocking events 725 are recorded, equivalent to -test.blockprofilerate=1. 726 727 -cover 728 Enable coverage analysis. 729 730 -covermode set,count,atomic 731 Set the mode for coverage analysis for the package[s] 732 being tested. The default is "set". 733 The values: 734 set: bool: does this statement run? 735 count: int: how many times does this statement run? 736 atomic: int: count, but correct in multithreaded tests; 737 significantly more expensive. 738 Sets -cover. 739 740 -coverpkg pkg1,pkg2,pkg3 741 Apply coverage analysis in each test to the given list of packages. 742 The default is for each test to analyze only the package being tested. 743 Packages are specified as import paths. 744 Sets -cover. 745 746 -coverprofile cover.out 747 Write a coverage profile to the specified file after all tests 748 have passed. 749 Sets -cover. 750 751 -cpu 1,2,4 752 Specify a list of GOMAXPROCS values for which the tests or 753 benchmarks should be executed. The default is the current value 754 of GOMAXPROCS. 755 756 -cpuprofile cpu.out 757 Write a CPU profile to the specified file before exiting. 758 759 -memprofile mem.out 760 Write a memory profile to the specified file after all tests 761 have passed. 762 763 -memprofilerate n 764 Enable more precise (and expensive) memory profiles by setting 765 runtime.MemProfileRate. See 'godoc runtime MemProfileRate'. 766 To profile all memory allocations, use -test.memprofilerate=1 767 and set the environment variable GOGC=off to disable the 768 garbage collector, provided the test can run in the available 769 memory without garbage collection. 770 771 -outputdir directory 772 Place output files from profiling in the specified directory, 773 by default the directory in which "go test" is running. 774 775 -parallel n 776 Allow parallel execution of test functions that call t.Parallel. 777 The value of this flag is the maximum number of tests to run 778 simultaneously; by default, it is set to the value of GOMAXPROCS. 779 780 -run regexp 781 Run only those tests and examples matching the regular 782 expression. 783 784 -short 785 Tell long-running tests to shorten their run time. 786 It is off by default but set during all.bash so that installing 787 the Go tree can run a sanity check but not spend time running 788 exhaustive tests. 789 790 -timeout t 791 If a test runs longer than t, panic. 792 793 -v 794 Verbose output: log all tests as they are run. Also print all 795 text from Log and Logf calls even if the test succeeds. 796 797 The test binary, called pkg.test where pkg is the name of the 798 directory containing the package sources, can be invoked directly 799 after building it with 'go test -c'. When invoking the test binary 800 directly, each of the standard flag names must be prefixed with 'test.', 801 as in -test.run=TestMyFunc or -test.v. 802 803 When running 'go test', flags not listed above are passed through 804 unaltered. For instance, the command 805 806 go test -x -v -cpuprofile=prof.out -dir=testdata -update 807 808 will compile the test binary and then run it as 809 810 pkg.test -test.v -test.cpuprofile=prof.out -dir=testdata -update 811 812 The test flags that generate profiles also leave the test binary in pkg.test 813 for use when analyzing the profiles. 814 815 Flags not recognized by 'go test' must be placed after any specified packages. 816 817 818 Description of testing functions 819 820 The 'go test' command expects to find test, benchmark, and example functions 821 in the "*_test.go" files corresponding to the package under test. 822 823 A test function is one named TestXXX (where XXX is any alphanumeric string 824 not starting with a lower case letter) and should have the signature, 825 826 func TestXXX(t *testing.T) { ... } 827 828 A benchmark function is one named BenchmarkXXX and should have the signature, 829 830 func BenchmarkXXX(b *testing.B) { ... } 831 832 An example function is similar to a test function but, instead of using 833 *testing.T to report success or failure, prints output to os.Stdout. 834 That output is compared against the function's "Output:" comment, which 835 must be the last comment in the function body (see example below). An 836 example with no such comment, or with no text after "Output:" is compiled 837 but not executed. 838 839 Godoc displays the body of ExampleXXX to demonstrate the use 840 of the function, constant, or variable XXX. An example of a method M with 841 receiver type T or *T is named ExampleT_M. There may be multiple examples 842 for a given function, constant, or variable, distinguished by a trailing _xxx, 843 where xxx is a suffix not beginning with an upper case letter. 844 845 Here is an example of an example: 846 847 func ExamplePrintln() { 848 Println("The output of\nthis example.") 849 // Output: The output of 850 // this example. 851 } 852 853 The entire test file is presented as the example when it contains a single 854 example function, at least one other function, type, variable, or constant 855 declaration, and no test or benchmark functions. 856 857 See the documentation of the testing package for more information. 858 859 860 */ 861 package main