我正在尝试在 vs-code 上配置调试器以进行一些测试。我必须向它传递一些标志,但效果不佳。主程序package mainimport ( "flag" "fmt")func DoTheThing() { flag1Ptr := flag.Bool("flag1", false, "flag1 is a flag") flag.Parse() fmt.Println(*flag1Ptr) fmt.Println("Hello, world")}func main() { DoTheThing()}main_test.gopackage mainimport "testing"func TestDoTheThing(t *testing.T) { DoTheThing()}启动.json{ "name": "Launch app", "type": "go", "request": "launch", "mode": "auto", "program": "${workspaceFolder}", "args": [ "-flag1" ]},{ "name": "Run Tests", "type": "go", "request": "launch", "mode": "test", "program": "${workspaceFolder}", "args": [ "--", "-flag1" ]}如果我使用 Launch app config 运行它,它会以正确的方式传递值,但使用测试时它不会设置参数使用 Launch app config 输出trueHello, world使用运行测试配置输出falseHello, world
1 回答
森林海
TA贡献2011条经验 获得超2个赞
package main
import (
"flag"
"fmt"
)
var flag1Ptr *bool
func init(){
flag1Ptr = flag.Bool("flag1", false, "flag1 is a flag")
}
func DoTheThing() {
flag.Parse()
fmt.Println(*flag1Ptr)
fmt.Println("Hello, world")
}
func main() {
DoTheThing()
}
启动.json
{
"name": "Launch app",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}",
"args": [
"-flag1"
]
},
{
"name": "Run Tests",
"type": "go",
"request": "launch",
"mode": "test",
"program": "${workspaceFolder}",
"args": ["-flag1"]
}
- 1 回答
- 0 关注
- 78 浏览
添加回答
举报
0/150
提交
取消