Skip to content

Commit 9287730

Browse files
committed
Simple execution test for go-clang-compdb
Fixes go-clang/gen#46
1 parent 731a231 commit 9287730

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

cmd/go-clang-compdb/main.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,25 @@ import (
1111
)
1212

1313
func main() {
14-
if len(os.Args) <= 1 {
14+
os.Exit(cmd(os.Args[1:]))
15+
}
16+
17+
func cmd(args []string) int {
18+
if len(args) == 0 {
1519
fmt.Printf("**error: you need to give a directory containing a 'compile_commands.json' file\n")
1620

17-
os.Exit(1)
21+
return 1
1822
}
1923

20-
dir := os.ExpandEnv(os.Args[1])
24+
dir := os.ExpandEnv(args[0])
2125
fmt.Printf(":: inspecting [%s]...\n", dir)
2226

2327
fname := filepath.Join(dir, "compile_commands.json")
2428
f, err := os.Open(fname)
2529
if err != nil {
2630
fmt.Printf("**error: could not open file [%s]: %v\n", fname, err)
2731

28-
os.Exit(1)
32+
return 1
2933
}
3034
f.Close()
3135

@@ -68,4 +72,6 @@ func main() {
6872
}
6973
}
7074
fmt.Printf(":: inspecting [%s]... [done]\n", dir)
75+
76+
return 0
7177
}

cmd/go-clang-compdb/main_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestGoClangCompDB(t *testing.T) {
10+
for _, path := range []string{
11+
"../../testdata",
12+
} {
13+
assert.Equal(t, 0, cmd([]string{path}))
14+
}
15+
}

0 commit comments

Comments
 (0)