去测试从 VS 代码到终端的不可重现的输出

标签 go visual-studio-code

在 VScode 中使用 go 扩展,对方法进行基准测试只需单击 [run benchmark] 即可立即在 vscode 控制台中获得它的输出,然后是运行的命令加上输出:

Running tool: /usr/local/bin/go test -benchmem -run=^$ github.com/zyxan/benchmarks -bench ^BenchmarkRandomStringGeneration2$

goos: darwin
goarch: amd64
pkg: github.com/zyxan/benchmarks
BenchmarkRandomStringGeneration2-4      10000000           147 ns/op          80 B/op          3 allocs/op
PASS
ok      github.com/zyxan/benchmarks 1.654s
Success: Benchmarks passed.

现在如果我想在我的终端上重现这样的命令,我真的只是复制它

/usr/local/bin/go test -benchmem -run=^$ github.com/zyxan/benchmarks -bench ^BenchmarkRandomStringGeneration2$

将其粘贴到我的终端 session 中会产生以下输出:

❯ /usr/local/bin/go test -benchmem -run=^$ github.com/zyxan/benchmarks -bench ^BenchmarkRandomStringGeneration2$
zsh: no matches found: -run=^$

为什么会造成这种差异?

最佳答案

如果您使用的是 vs-code,那么您可以使用 same 提供的 vs-code 终端来运行该命令,它将显示使用相同命令的基准测试的输出。它将解析命令。

go test -benchmem -run=^$ github.com/zyxan/benchmarks -bench ^BenchmarkParsingJSON$

以上命令在windows安装的vs-code终端中使用。

正如@Peter 在 linux 终端上建议的那样,您应该使用单个引号来解析 shell 命令

go test -benchmem -run='^$' github.com/zyxan/benchmarks -bench '^BenchmarkRandomStringGeneration2$'

-run 标志内,您需要传递正则表达式标志。

关于去测试从 VS 代码到终端的不可重现的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51765768/

相关文章:

docker - 容器中的 Go API 不返回任何响应

visual-studio-code - 如何在VS Code中运行scheme程序

typescript - 如何在VsCode中加速Typescript Intellisense?

go - 无法在 Go 中替换 csv 文件的内容

go - 将 google-apis 用于 google 表格,如何根据条件更新特定单元格

python - DLL 加载失败 : The specific module could not be found (VSCode, Numpy)

javascript - 如何设置 VSCode 来调试 webpack 捆绑的 nodejs 服务器

android - VS Code/Flutter/Android - keystore 文件未设置用于签署配置版本

使用pubkey的golang ssh登录失败

json - 将 JSON 或映射从 map[string]interface{} 插入到 MongoDB 集合将 int 和 float 设置为字符串