Skip to content

Commit cccd2f9

Browse files
committed
gitbase: add integration test for uast functions
Signed-off-by: Miguel Molina <[email protected]>
1 parent e1635f4 commit cccd2f9

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ install:
3333

3434
before_script:
3535
- docker run -d --name bblfshd --privileged -p 9432:9432 -v /var/lib/bblfshd:/var/lib/bblfshd bblfsh/bblfshd
36-
- docker exec -it bblfshd bblfshctl driver install --all
36+
- docker exec -it bblfshd bblfshctl driver install python bblfsh/python-driver
37+
- docker exec -it bblfshd bblfshctl driver install php bblfsh/php-driver
3738

3839
script:
3940
- make test-coverage codecov

integration_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,38 @@ func TestIntegration(t *testing.T) {
157157
t.Run("with squash", runTests)
158158
}
159159

160+
func TestUastQueries(t *testing.T) {
161+
require := require.New(t)
162+
engine := sqle.New()
163+
require.NoError(fixtures.Init())
164+
defer func() {
165+
require.NoError(fixtures.Clean())
166+
}()
167+
168+
pool := gitbase.NewRepositoryPool()
169+
for _, f := range fixtures.ByTag("worktree") {
170+
pool.AddGit(f.Worktree().Root())
171+
}
172+
173+
engine.AddDatabase(gitbase.NewDatabase("foo"))
174+
engine.Catalog.RegisterFunctions(function.Functions)
175+
176+
session := gitbase.NewSession(&pool)
177+
ctx := sql.NewContext(context.TODO(), sql.WithSession(session))
178+
_, iter, err := engine.Query(ctx, `
179+
SELECT uast_xpath(uast(content, 'php'), '//*[@roleIdentifier]') as uast, name
180+
FROM tree_entries te
181+
INNER JOIN blobs b
182+
ON b.hash = te.entry_hash
183+
WHERE te.name = 'php/crappy.php'`,
184+
)
185+
require.NoError(err)
186+
187+
rows, err := sql.RowIterToRows(iter)
188+
require.NoError(err)
189+
require.Len(rows, 3)
190+
}
191+
160192
func BenchmarkQueries(b *testing.B) {
161193
queries := []struct {
162194
name string

internal/function/uast_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"testing"
66

7-
opentracing "github.com/opentracing/opentracing-go"
87
"github.com/src-d/gitbase"
98
"github.com/stretchr/testify/require"
109
"gopkg.in/bblfsh/client-go.v2/tools"
@@ -166,7 +165,7 @@ func bblfshFixtures(t *testing.T, ctx *sql.Context) (uast []interface{}, filtere
166165
Language("python").
167166
Do()
168167
require.NoError(t, err)
169-
require.Equal(t, protocol.Ok, resp.Status)
168+
require.Equal(t, protocol.Ok, resp.Status, "errors: %v", resp.Errors)
170169
testUAST, err := resp.UAST.Marshal()
171170
require.NoError(t, err)
172171

@@ -193,7 +192,7 @@ func setup(t *testing.T) (*sql.Context, func()) {
193192
}
194193

195194
session := gitbase.NewSession(&pool)
196-
ctx := sql.NewContext(context.TODO(), session, opentracing.NoopTracer{})
195+
ctx := sql.NewContext(context.TODO(), sql.WithSession(session))
197196

198197
return ctx, func() {
199198
require.NoError(t, fixtures.Clean())

0 commit comments

Comments
 (0)