...
Source file src/pkg/cmd/go/internal/base/path.go
1
2
3
4
5 package base
6
7 import (
8 "os"
9 "path/filepath"
10 "strings"
11 )
12
13 func getwd() string {
14 wd, err := os.Getwd()
15 if err != nil {
16 Fatalf("cannot determine current directory: %v", err)
17 }
18 return wd
19 }
20
21 var Cwd = getwd()
22
23
24 func ShortPath(path string) string {
25 if rel, err := filepath.Rel(Cwd, path); err == nil && len(rel) < len(path) {
26 return rel
27 }
28 return path
29 }
30
31
32
33 func RelPaths(paths []string) []string {
34 var out []string
35
36 pwd, _ := os.Getwd()
37 for _, p := range paths {
38 rel, err := filepath.Rel(pwd, p)
39 if err == nil && len(rel) < len(p) {
40 p = rel
41 }
42 out = append(out, p)
43 }
44 return out
45 }
46
47
48
49 func IsTestFile(file string) bool {
50
51 return strings.HasSuffix(file, "_test.go")
52 }
53
View as plain text