MCPcopy Create free account
hub / github.com/RainbowMango/GoExpertProgramming / TestArgs

Function TestArgs

source/gotest/unit_test.go:22–35  ·  view source on GitHub ↗

TestArgs 用于演示如何解析-args参数

(t *testing.T)

Source from the content-addressed store, hash-verified

20
21// TestArgs 用于演示如何解析-args参数
22func TestArgs(t *testing.T) {
23 if !flag.Parsed() {
24 flag.Parse()
25 }
26
27 argList := flag.Args() // flag.Args() 返回 -args 后面的所有参数,以切片表示,每个元素代表一个参数
28 for _, arg := range argList {
29 if arg == "cloud" {
30 t.Log("Running in cloud.")
31 } else {
32 t.Log("Running in other mode.")
33 }
34 }
35}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected