diff --git a/go/codeql-extractor.yml b/go/codeql-extractor.yml index 20cfe987ef3..e3333ec7c06 100644 --- a/go/codeql-extractor.yml +++ b/go/codeql-extractor.yml @@ -19,3 +19,11 @@ file_types: extensions: - .go legacy_qltest_extraction: true +options: + extract_tests: + title: Whether to include Go test files and functions in the CodeQL database. + description: > + A value indicating whether Go test files and functions should be included in the CodeQL database. + The default is 'false'. + type: string + pattern: "^(false|true)$" diff --git a/go/extractor/cli/go-extractor/go-extractor.go b/go/extractor/cli/go-extractor/go-extractor.go index 2f40d2980cf..142a950d9f1 100644 --- a/go/extractor/cli/go-extractor/go-extractor.go +++ b/go/extractor/cli/go-extractor/go-extractor.go @@ -94,7 +94,7 @@ func parseFlags(args []string, mimic bool, extractTests bool) ([]string, []strin } func main() { - extractTestsDefault := os.Getenv("CODEQL_EXTRACTOR_GO_EXTRACT_TESTS") == "true" + extractTestsDefault := os.Getenv("CODEQL_EXTRACTOR_GO_OPTION_EXTRACT_TESTS") == "true" buildFlags, patterns, extractTests := parseFlags(os.Args[1:], false, extractTestsDefault) if cpuprofile != "" { diff --git a/go/extractor/extractor.go b/go/extractor/extractor.go index 68e64d46f90..448bb83deee 100644 --- a/go/extractor/extractor.go +++ b/go/extractor/extractor.go @@ -88,7 +88,7 @@ func ExtractWithFlags(buildFlags []string, patterns []string, extractTests bool) log.Printf("Running packages.Load%s.", testMessage) // This includes test packages if either we're tracing a `go test` command, - // or if CODEQL_EXTRACTOR_GO_EXTRACT_TESTS is set to "true". + // or if CODEQL_EXTRACTOR_GO_OPTION_EXTRACT_TESTS is set to "true". cfg := &packages.Config{ Mode: packages.NeedName | packages.NeedFiles | packages.NeedCompiledGoFiles | diff --git a/go/ql/integration-tests/test-extraction-autobuild/test.py b/go/ql/integration-tests/test-extraction-autobuild/test.py index 417b1e8bb04..0dc91b5212c 100644 --- a/go/ql/integration-tests/test-extraction-autobuild/test.py +++ b/go/ql/integration-tests/test-extraction-autobuild/test.py @@ -1,5 +1,4 @@ import os def test(codeql, go): - os.environ["CODEQL_EXTRACTOR_GO_EXTRACT_TESTS"] = "true" - codeql.database.create(source_root="src") + codeql.database.create(source_root="src", extractor_option = ["extract_tests=true"])