-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloader_different_roots_test.go
81 lines (65 loc) · 1.83 KB
/
loader_different_roots_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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package langd
import (
"fmt"
"os/exec"
"path/filepath"
"strings"
"sync"
"testing"
)
// Test_LoaderContext_Different_Root will require a different test context
// than FakeContext, which only allows one GOROOT. We will want to start to
// use Afero (https://github.com/spf13/afero) in the Loader, so that we can
// provide memory-mapped complex file systems.
func Test_LoaderContext_Different_Root(t *testing.T) {
cmd := exec.Command("which", "go")
out, err := cmd.Output()
if err != nil {
t.Fatalf("Failed to locate the `go` executable\n\t%s\n", err.Error())
}
goAbsPath, err := filepath.Abs(strings.TrimSpace(string(out)))
if err != nil {
t.Fatalf("Failed to get absolute path for `go`\n\t%s\n", err.Error())
}
goPath, err := filepath.EvalSymlinks(goAbsPath)
if err != nil {
t.Fatalf("Failed to evalulate symlinks for %s\n\t%s\n", goAbsPath, err.Error())
}
goRoot, _ := filepath.Split(filepath.Dir(goPath))
fmt.Printf("go path: %s\n", goPath)
fmt.Printf("go root: %s\n", goRoot)
le := NewLoaderEngine()
defer le.Close()
errCount := 0
path := "../langd-example"
fn := func(file string, errs []FileError) {
if len(errs) == 0 {
return
}
t.Errorf("Loading error in %s:\n", file)
for k, err := range errs {
t.Errorf("\t%d: [%d:%d] %s\n", k, err.Line, err.Column, err.Message)
}
errCount += len(errs)
}
var wg sync.WaitGroup
wg.Add(2)
procfn := func(root string) {
l := NewLoader(le, "darwin", "amd64", root)
fmt.Printf("Starting at goroot %s...\n", l.context.GOROOT)
err = l.LoadDirectory(path)
if err != nil {
t.Fatalf("Error while loading: %s", err.Error())
}
l.Wait()
l.Errors(fn)
wg.Done()
}
procfn(goRoot)
procfn("/usr/local/Cellar/go/1.9.4/libexec/")
wg.Wait()
if errCount != 0 {
t.Fatalf("Found %d errors", errCount)
}
// t.Error("Not implemented: final check of loaded ASTs")
}