| 1 | This repository factors out an opinionated selection of internal packages and functionality from the Go standard |
| 2 | library. Currently this consists mostly of packages and testing code from within the Go tool implementation. |
| 3 | |
| 4 | This repo is [primarily maintained](https://github.com/rogpeppe/go-internal/graphs/contributors) by long-time |
| 5 | [Go contributors](https://github.com/golang/go/contributors) who are also currently |
| 6 | [maintaining CUE](https://github.com/cue-lang/cue/graphs/contributors) (which is primarily written in Go |
| 7 | and which relies upon several of the packages here). |
| 8 | |
| 9 | Contributions are welcome, but please open an issue for discussion first. |
| 10 | |
| 11 | ## Packages |
| 12 | |
| 13 | Included are the following: |
| 14 | |
| 15 | - goproxytest: a GOPROXY implementation designed for test use. |
| 16 | - gotooltest: Use the Go tool inside test scripts (see testscript below) |
| 17 | - imports: list of known architectures and OSs, and support for reading import statements. |
| 18 | - par: do work in parallel. |
| 19 | - testenv: information on the current testing environment. |
| 20 | - testscript: script-based testing based on txtar files |
| 21 | - txtar: simple text-based file archives for testing. |
| 22 | |
| 23 | Note that most users of `txtar` should use https://pkg.go.dev/golang.org/x/tools/txtar instead. |
| 24 | Our package will be replaced by it once https://github.com/golang/go/issues/59264 is fixed. |
| 25 | |
| 26 | ### testscript |
| 27 | |
| 28 | The most popular package here is the [testscript](https://pkg.go.dev/github.com/rogpeppe/go-internal/testscript) package: |
| 29 | * Provides a shell-like test environment that is very nicely tuned for testing Go CLI commands. |
| 30 | * Extracted from the core Go team's internal testscript package ([cmd/go/internal/script](https://github.com/golang/go/tree/master/src/cmd/go/internal/script)), |
| 31 | which is [heavily used](https://github.com/golang/go/tree/master/src/cmd/go/testdata/script) to test the `go` command. |
| 32 | * Supports patterns for checking stderr/stdout, command pass/fail assertions, and so on. |
| 33 | * Integrates well with `go test`, including coverage support. |
| 34 | * Inputs and sample output files can use the simple [txtar](https://pkg.go.dev/golang.org/x/tools/txtar) |
| 35 | text archive format, also used by the Go playground. |
| 36 | * Allows [automatically updating](https://pkg.go.dev/github.com/rogpeppe/go-internal/testscript#Params) |
| 37 | golden files. |
| 38 | * Built-in support for Go concepts like build tags. |
| 39 | * Accompanied by a [testscript](https://github.com/rogpeppe/go-internal/tree/master/cmd/testscript) command |
| 40 | for running standalone scripts with files embedded in txtar format. |
| 41 | |
| 42 | A nice introduction to using testscripts is this [blog post](https://bitfieldconsulting.com/golang/test-scripts) series. |
| 43 | Both testscript and txtar were [originally created](https://github.com/golang/go/commit/5890e25b7ccb2d2249b2f8a02ef5dbc36047868b) |
| 44 | by Russ Cox. |