Skip to content

Commit

Permalink
Merge pull request github#17637 from smowton/smowton/admin/go-test-ex…
Browse files Browse the repository at this point in the history
…traction-tests

Go: augment test-extraction tests
  • Loading branch information
smowton authored Oct 3, 2024
2 parents 64720ad + 05d2e16 commit 321eb34
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go/ql/integration-tests/test-extraction/src/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
go 1.14
go 1.18

module testsample
7 changes: 7 additions & 0 deletions go/ql/integration-tests/test-extraction/src/pkg1/def.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package pkg1

type Generic[T any] struct {
element T
}

func TestMe() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package pkg1_test

import (
"testsample/pkg1"
)

func UsePkg1() {
pkg1.TestMe()
}
5 changes: 5 additions & 0 deletions go/ql/integration-tests/test-extraction/src/pkg1/def_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package pkg1

func UsePkg1() {
TestMe()
}
12 changes: 12 additions & 0 deletions go/ql/integration-tests/test-extraction/src/pkg2/use.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package pkg2

import (
"testsample/pkg1"
)

// This tests the case of cross-package generic type references
// in the presence of test extraction. We need to make sure we
// extract packages, including test variants, in the right order
// such that we've seen pkg1.Generic before we try to use it here.

type Specialised = pkg1.Generic[string]
6 changes: 6 additions & 0 deletions go/ql/integration-tests/test-extraction/test.expected
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#select
| src/pkg1/def.go:0:0:0:0 | src/pkg1/def.go |
| src/pkg1/def_blackbox_test.go:0:0:0:0 | src/pkg1/def_blackbox_test.go |
| src/pkg1/def_test.go:0:0:0:0 | src/pkg1/def_test.go |
| src/pkg2/use.go:0:0:0:0 | src/pkg2/use.go |
| src/testme.go:0:0:0:0 | src/testme.go |
| src/testme_blackbox_test.go:0:0:0:0 | src/testme_blackbox_test.go |
| src/testme_test.go:0:0:0:0 | src/testme_test.go |
calls
| src/pkg1/def_blackbox_test.go:8:2:8:14 | call to TestMe | src/pkg1/def.go:7:1:7:16 | function declaration |
| src/pkg1/def_test.go:4:2:4:9 | call to TestMe | src/pkg1/def.go:7:1:7:16 | function declaration |
| src/testme_blackbox_test.go:10:18:10:44 | call to PublicFunction | src/testme.go:3:1:3:38 | function declaration |
| src/testme_test.go:9:18:9:33 | call to PublicFunction | src/testme.go:3:1:3:38 | function declaration |
| src/testme_test.go:14:19:14:35 | call to privateFunction | src/testme.go:5:1:5:39 | function declaration |
Expand Down
2 changes: 1 addition & 1 deletion go/ql/integration-tests/test-extraction/test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

def test_traced(codeql, go):
codeql.database.create(source_root="src", command="go test -c")
codeql.database.create(source_root="src", command="go test -c ./...")

def test_autobuild(codeql, go):
codeql.database.create(source_root="src", extractor_option = ["extract_tests=true"])

0 comments on commit 321eb34

Please sign in to comment.