-
Notifications
You must be signed in to change notification settings - Fork 0
/
gir_test.go
87 lines (75 loc) · 2.29 KB
/
gir_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
// +build amd64
package main
import (
"bufio"
"os"
"path/filepath"
"testing"
"github.com/bjwbell/gir/codegen"
"github.com/bjwbell/gir/config"
"github.com/bjwbell/gir/ctx"
"github.com/bjwbell/gir/parse"
"github.com/bjwbell/gir/scan"
"github.com/bjwbell/gir/testdata"
"github.com/bjwbell/gir/value"
)
func runTest(t *testing.T, filename string) {
context := ctx.NewContext(&conf)
fd, err := os.Open(filepath.Join("testdata", filename))
defer fd.Close()
if err != nil {
t.Fatalf("gir: %s\n", err)
}
scanner := scan.New(context, filename, bufio.NewReader(fd))
parser := parse.NewParser(filename, scanner, context)
fileDecl := parser.ParseFile()
for _, fnDecl := range fileDecl.Decls {
ssafn, ok := codegen.BuildSSA(&fnDecl, fileDecl.PkgName, false)
if ssafn == nil || !ok {
t.Fatalf("gir: Error building SSA form")
return
} else {
t.Log("ssa:\n", ssafn)
}
}
}
// TestEmptyFile tests lexing and parsing of an empty gir file"
func TestEmptyFile(t *testing.T) { runTest(t, "empty.gir") }
// TestT1 tests calling generated *_amd64.s function
func TestT1(t *testing.T) { testdata.T1() }
// TestT2 tests calling generated *_amd64.s function
func TestT2(t *testing.T) { testdata.T2() }
// TestT3 tests calling generated *_amd64.s function
func TestT3(t *testing.T) { testdata.T3() }
// TestT4 tests calling generated *_amd64.s function
func TestT4(t *testing.T) { testdata.T4() }
func TestGir(t *testing.T) {
var (
conf config.Config
context value.Context
fd *os.File
err error
)
context = ctx.NewContext(&conf)
for _, file := range []string{filepath.Join("testdata", "test.gir"), filepath.Join("testdata", "test1.gir"), filepath.Join("testdata", "test2.gir"), filepath.Join("testdata", "test3.gir"), filepath.Join("testdata", "test4.gir")} {
fd, err = os.Open(file)
defer fd.Close()
if err != nil {
t.Fatalf("gir: %s\n", err)
}
scanner := scan.New(context, file, bufio.NewReader(fd))
parser := parse.NewParser(file, scanner, context)
fileDecl := parser.ParseFile()
t.Log("tree(exprs): ", parse.Tree(fileDecl))
for _, fnDecl := range fileDecl.Decls {
ssafn, ok := codegen.BuildSSA(&fnDecl, fileDecl.PkgName, false)
if ssafn == nil || !ok {
t.Fatalf("gir: Error building SSA form")
return
} else {
t.Log("ssa:\n", ssafn)
}
}
}
return
}