(t *testing.T)
| 7 | ) |
| 8 | |
| 9 | func TestIsProbablyGoRun(t *testing.T) { |
| 10 | scenarios := []struct { |
| 11 | arg0 string |
| 12 | runDirs []string |
| 13 | expected bool |
| 14 | }{ |
| 15 | {"", nil, false}, |
| 16 | {"/a/b", nil, false}, |
| 17 | {"/a/b", []string{""}, false}, |
| 18 | {"/a/b", []string{"/b/"}, false}, |
| 19 | {"/a/b", []string{"/a/"}, true}, |
| 20 | {"/a/b", []string{"", "/b/", "/a/"}, true}, |
| 21 | } |
| 22 | |
| 23 | originalArgs := os.Args |
| 24 | defer func() { |
| 25 | os.Args = originalArgs |
| 26 | }() |
| 27 | |
| 28 | originalRunDirs := runDirs |
| 29 | defer func() { |
| 30 | runDirs = originalRunDirs |
| 31 | }() |
| 32 | |
| 33 | for i, s := range scenarios { |
| 34 | t.Run(strconv.Itoa(i)+"_"+s.arg0, func(t *testing.T) { |
| 35 | os.Args = []string{s.arg0} |
| 36 | runDirs = s.runDirs |
| 37 | |
| 38 | result := IsProbablyGoRun() |
| 39 | |
| 40 | if result != s.expected { |
| 41 | t.Fatalf("Expected %v, got %v", s.expected, result) |
| 42 | } |
| 43 | }) |
| 44 | } |
| 45 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…