Source file
src/cmd/go/chdir_test.go
1
2
3
4
5 package main
6
7 import (
8 "cmd/go/internal/base"
9 "os"
10 "strings"
11 "testing"
12 )
13
14 func TestChdir(t *testing.T) {
15 t.Parallel()
16
17
18
19
20
21 script, err := os.ReadFile("testdata/script/chdir.txt")
22 if err != nil {
23 t.Fatal(err)
24 }
25
26 var walk func(string, *base.Command)
27 walk = func(name string, cmd *base.Command) {
28 if len(cmd.Commands) > 0 {
29 for _, sub := range cmd.Commands {
30 walk(name+" "+sub.Name(), sub)
31 }
32 return
33 }
34 if !cmd.Runnable() {
35 return
36 }
37 if cmd.CustomFlags {
38 if !strings.Contains(string(script), "# "+name+"\n") {
39 t.Errorf("%s has custom flags, not tested in testdata/script/chdir.txt", name)
40 }
41 return
42 }
43 f := cmd.Flag.Lookup("C")
44 if f == nil {
45 t.Errorf("%s has no -C flag", name)
46 } else if f.Usage != "AddChdirFlag" {
47 t.Errorf("%s has -C flag but not from AddChdirFlag", name)
48 }
49 }
50 walk("go", base.Go)
51 }
52
View as plain text