-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathpreprocess.go
More file actions
82 lines (73 loc) · 1.7 KB
/
preprocess.go
File metadata and controls
82 lines (73 loc) · 1.7 KB
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
package main
import (
"fmt"
"strings"
"github.com/goplus/lib/c"
"github.com/goplus/llcppg/_xtool/llcppsigfetch/parse"
test "github.com/goplus/llcppg/_xtool/llcppsigfetch/parse/cvt_test"
"github.com/goplus/llcppg/llcppg"
)
func main() {
TestDefine()
TestSystemHeader()
TestInclusionMap()
TestMacroExpansionOtherFile()
}
func TestDefine() {
testCases := []string{
`#define DEBUG`,
`#define OK 1`,
`#define SQUARE(x) ((x) * (x))`,
}
test.RunTest("TestDefine", testCases)
}
func TestInclusionMap() {
fmt.Println("=== TestInclusionMap ===")
cvt, err := parse.Do(&parse.ParseConfig{
Conf: &llcppg.Config{
Include: []string{"sys.h"},
CFlags: "-I./testdata/sysinc",
},
})
if err != nil {
panic(err)
}
found := false
for path, info := range cvt.Pkg.FileMap {
if strings.HasSuffix(path, "sys/types.h") && info.FileType == llcppg.Third {
found = true
}
}
if !found {
panic("sys/types.h not found")
} else {
fmt.Println("sys/types.h include path found")
}
}
func TestSystemHeader() {
fmt.Println("=== TestSystemHeader ===")
cvt, err := parse.Do(&parse.ParseConfig{
Conf: &llcppg.Config{
Include: []string{"inc.h"},
CFlags: "-I./testdata/sysinc",
},
})
if err != nil {
panic(err)
}
for path, info := range cvt.Pkg.FileMap {
if path != "./testdata/sysinc/inc.h" && info.FileType != llcppg.Third {
panic(fmt.Errorf("include file is not third header: %s", path))
}
}
fmt.Println("include files are all system headers")
}
func TestMacroExpansionOtherFile() {
c.Printf(c.Str("=== TestMacroExpansionOtherFile ===\n"))
test.RunTestWithConfig(&parse.ParseConfig{
Conf: &llcppg.Config{
Include: []string{"ref.h"},
CFlags: "-I./testdata/macroexpan",
},
})
}