rogpeppe/go-internal
GitHub: rogpeppe/go-internal
从 Go 标准库和工具链中提取的精选内部包集合,提供脚本化测试、并行执行、import 解析等能力,供外部 Go 项目复用。
Stars: 988 | Forks: 89
这个仓库提取了来自 Go 标准库的一系列精选的内部包和功能。目前这主要包括来自 Go 工具实现内部的包和测试代码。
这个仓库主要由资深的 [Go 贡献者](https://github.com/golang/go/contributors) [主要维护](https://github.com/rogpeppe/go-internal/graphs/contributors),他们也同时[维护着 CUE](https://github.com/cue-lang/cue/graphs/contributors)(CUE 主要使用 Go 编写,并依赖于这里的一些包)。
## 包
包含以下内容:
- goproxytest:专为测试用途设计的 GOPROXY 实现。
- gotooltest:在测试脚本中使用 Go 工具(参见下文的 testscript)。
- imports:已知的架构和操作系统列表,以及读取 import 语句的支持。
- par:并行执行工作。
- testenv:有关当前测试环境的信息。
- testscript:基于 txtar 文件的脚本化测试。
- txtar:用于测试的简单基于文本的文件归档。
请注意,大多数 `txtar` 的用户应该改用 https://pkg.go.dev/golang.org/x/tools/txtar。一旦 https://github.com/golang/go/issues/59264 被修复,我们的包将被它取代。
### 测试脚本
这里最受欢迎的包是 [testscript](https://pkg.go.dev/github.com/rogpeppe/go-internal/testscript) 包:
* 提供了一个类 shell 的测试环境,非常适合用于测试 Go CLI 命令。
* 提取自 Go 核心团队的内部 testscript 包([cmd/go/internal/script](https://github.com/golang/go/tree/master/src/cmd/go/internal/script)),该包被[广泛使用](https://github.com/golang/go/tree/master/src/cmd/go/testdata/script)于测试 `go` 命令。
* 支持检查 stderr/stdout、命令成功/失败断言等模式。
* 与 `go test` 良好集成,包括覆盖率支持。
* 输入和示例输出文件可以使用简单的 [txtar](https://pkg.go.dev/golang.org/x/tools/txtar) 文本归档格式,这也是 Go playground 所使用的格式。
* 允许[自动更新](https://pkg.go.dev/github.com/rogpeppe/go-internal/testscript#Params) golden 文件。
* 内置支持诸如 build tags 之类的 Go 概念。
* 附带了一个 [testscript](https://github.com/rogpeppe/go-internal/tree/master/cmd/testscript) 命令,用于运行嵌入在 txtar 格式文件中的独立脚本。
关于使用 testscript 的一个很好的入门介绍是这个[博客文章](https://bitfieldconsulting.com/golang/test-scripts)系列。
testscript 和 txtar 最初均由 Russ Cox [创建](https://github.com/golang/go/commit/5890e25b7ccb2d2249b2f8a02ef5dbc36047868b)。
标签:EVTX分析, Go, Ruby工具, SOC Prime, 并行处理, 开发工具, 日志审计, 标准库, 测试框架, 测试脚本