forked from sirnewton01/godev
-
Notifications
You must be signed in to change notification settings - Fork 1
/
debug_test.go
39 lines (32 loc) · 894 Bytes
/
debug_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright 2013 Chris McGee <[email protected]>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"go/build"
"os"
"path/filepath"
"testing"
)
func TestCommandDetection(t *testing.T) {
srcDirs := build.Default.SrcDirs()
t.Logf("SRC DIRS: %v\n", srcDirs)
commands := make(map[string]string)
for _, srcDir := range srcDirs {
// Skip stuff that is in the GOROOT
if filepath.HasPrefix(srcDir, goroot) {
continue
}
filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error {
if info.IsDir() {
pkg, err := build.Default.ImportDir(path, 0)
if err == nil && pkg.IsCommand() {
t.Logf("PKG: %v\n", pkg.ImportPath)
commands[pkg.ImportPath] = filepath.Base(pkg.ImportPath)
}
}
return nil
})
}
t.Logf("MAP: %v\n", commands)
}