-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkspace_hugo_test.go
97 lines (77 loc) · 2.12 KB
/
workspace_hugo_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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package langd
import (
"bytes"
"fmt"
"go/token"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"testing"
"github.com/object88/langd/log"
)
var hugoIsAccessible = false
func init() {
fi, err := os.Stat("../../gohugoio/hugo")
if err != nil {
return
}
if !fi.IsDir() {
return
}
hugoIsAccessible = true
}
func Test_Workspace_Hugo(t *testing.T) {
if testing.Short() || !hugoIsAccessible {
t.Skip("skipping in short mode")
}
path := "../../gohugoio/hugo"
logger := log.Stdout()
logger.SetLevel(log.Debug)
le := NewLoaderEngine()
defer le.Close()
l := NewLoader(le, runtime.GOOS, runtime.GOARCH, runtime.GOROOT())
w := CreateWorkspace(le, logger)
w.AssignLoader(l)
err := l.LoadDirectory(path)
if err != nil {
t.Fatalf("Failed to load directory '%s':\n\t%s\n", path, err.Error())
}
t.Log("Load directory started; blocking...\n")
l.Wait()
t.Log("Load directory done\n")
errCount := 0
var buf bytes.Buffer
l.Errors(func(file string, errs []FileError) {
if len(errs) == 0 {
return
}
buf.WriteString(fmt.Sprintf("Loading error in %s:\n", file))
for k, err := range errs {
buf.WriteString(fmt.Sprintf("\t%02d: %s:%d %s\n", k, err.Filename, err.Line, err.Message))
}
errCount += len(errs)
})
if errCount != 0 {
buf.WriteString(fmt.Sprintf("Total: %d errors\n", errCount))
t.Fatal(buf.String())
}
csvPath, _ := filepath.Abs(filepath.Join(path, "vendor/github.com/olekukonko/tablewriter/csv.go"))
tablePath, _ := filepath.Abs(filepath.Join(path, "vendor/github.com/olekukonko/tablewriter/table.go"))
processingStatePath, _ := filepath.Abs(filepath.Join(path, "helpers/processing_stats.go"))
byteContents, err := ioutil.ReadFile(csvPath)
if err != nil {
t.Fatal(err)
}
contents := string(byteContents)
w.OpenFile(csvPath, contents)
declPosition := &token.Position{Filename: tablePath, Line: 85, Column: 6}
p := &token.Position{Filename: csvPath, Line: 33, Column: 7}
testDeclaration(t, w, p, declPosition)
testReferences(t, w, p, []*token.Position{
declPosition,
p,
{Filename: processingStatePath, Line: 74, Column: 23},
{Filename: processingStatePath, Line: 109, Column: 23},
})
}