From 5fa76f921006ff7d47956b96a6cea333681444e4 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 17 Feb 2026 15:43:11 +0100 Subject: pkg/aflow/tool/codesearcher: add end-to-end tests Update #6811 --- pkg/codesearch/codesearch.go | 7 +++++++ pkg/codesearch/codesearch_test.go | 3 +-- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'pkg/codesearch') diff --git a/pkg/codesearch/codesearch.go b/pkg/codesearch/codesearch.go index 0e8fe6014..4243f1013 100644 --- a/pkg/codesearch/codesearch.go +++ b/pkg/codesearch/codesearch.go @@ -13,8 +13,10 @@ import ( "strconv" "strings" "syscall" + "testing" "github.com/google/syzkaller/pkg/aflow" + "github.com/google/syzkaller/pkg/clangtool/tooltest" "github.com/google/syzkaller/pkg/osutil" ) @@ -153,6 +155,11 @@ func NewIndex(databaseFile string, srcDirs []string) (*Index, error) { }, nil } +func NewTestIndex(t *testing.T, dir string) *Index { + db := tooltest.LoadOutput[Database](t, dir) + return &Index{db, []string{dir}} +} + func (index *Index) Command(cmd string, args []string) (string, error) { for _, meta := range Commands { if cmd == meta.Name { diff --git a/pkg/codesearch/codesearch_test.go b/pkg/codesearch/codesearch_test.go index 5deed53bb..9163330ba 100644 --- a/pkg/codesearch/codesearch_test.go +++ b/pkg/codesearch/codesearch_test.go @@ -20,8 +20,7 @@ func TestClangTool(t *testing.T) { } func TestCommands(t *testing.T) { - db := tooltest.LoadOutput[Database](t) - index := &Index{db, []string{"testdata"}} + index := NewTestIndex(t, "testdata") files, err := filepath.Glob(filepath.Join(osutil.Abs("testdata"), "query*")) if err != nil { t.Fatal(err) -- cgit mrf-deployment