-
Notifications
You must be signed in to change notification settings - Fork 11
/
compilationdb_test.go
76 lines (67 loc) · 1.75 KB
/
compilationdb_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
package clang_test
import (
"testing"
clang "github.com/sbinet/go-clang"
)
func TestCompilationDatabaseError(t *testing.T) {
_, err := clang.NewCompilationDatabase("testdata-not-there")
if err == nil {
t.Fatalf("expected an error")
}
if err.(clang.CompilationDatabaseError) != clang.CompilationDatabase_CanNotLoadDatabase {
t.Fatalf("expected %v", clang.CompilationDatabase_CanNotLoadDatabase)
}
}
func TestCompilationDatabase(t *testing.T) {
db, err := clang.NewCompilationDatabase("testdata")
if err != nil {
t.Fatalf("error loading compilation database: %v", err)
}
defer db.Dispose()
table := []struct {
directory string
args []string
}{
{
directory: "/home/user/llvm/build",
args: []string{
"/usr/bin/clang++",
"-Irelative",
//FIXME: bug in clang ?
//`-DSOMEDEF="With spaces, quotes and \-es.`,
"-DSOMEDEF=With spaces, quotes and -es.",
"-c",
"-o",
"file.o",
"file.cc",
},
},
{
directory: "@TESTDIR@",
args: []string{"g++", "-c", "-DMYMACRO=a", "subdir/a.cpp"},
},
}
cmds := db.GetAllCompileCommands()
if cmds.GetSize() != len(table) {
t.Errorf("expected #cmds=%d. got=%d", len(table), cmds.GetSize())
}
for i := 0; i < cmds.GetSize(); i++ {
cmd := cmds.GetCommand(i)
if cmd.GetDirectory() != table[i].directory {
t.Errorf("expected dir=%q. got=%q", table[i].directory, cmd.GetDirectory())
}
nargs := cmd.GetNumArgs()
if nargs != len(table[i].args) {
t.Errorf("expected #args=%d. got=%d", len(table[i].args), nargs)
}
if nargs > len(table[i].args) {
nargs = len(table[i].args)
}
for j := 0; j < nargs; j++ {
arg := cmd.GetArg(j)
if arg != table[i].args[j] {
t.Errorf("expected arg[%d]=%q. got=%q", j, table[i].args[j], arg)
}
}
}
}