mirror of
https://github.com/github/codeql.git
synced 2026-01-30 14:52:57 +01:00
Merge pull request #518 from smowton/smowton/fix/restore-extraction-under-codeql
Tolerate empty-string CODEQL_PLATFORM, and add smoke tests
This commit is contained in:
1
Makefile
1
Makefile
@@ -118,6 +118,7 @@ test: all build/testdb/check-upgrade-path
|
||||
# use GOOS=linux because GOOS=darwin GOARCH=386 is no longer supported
|
||||
env GOOS=linux GOARCH=386 codeql$(EXE) test run ql/test/query-tests/Security/CWE-681 --search-path . --consistency-queries ql/test/consistency
|
||||
cd extractor; go test -mod=vendor ./... | grep -vF "[no test files]"
|
||||
bash extractor-smoke-test/test.sh || (echo "Extractor smoke test FAILED"; exit 1)
|
||||
|
||||
.PHONY: build/testdb/check-upgrade-path
|
||||
build/testdb/check-upgrade-path : build/testdb/go.dbscheme ql/src/go.dbscheme
|
||||
|
||||
4
extractor-smoke-test/.gitignore
vendored
Normal file
4
extractor-smoke-test/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
*.bqrs
|
||||
tracing-out.csv
|
||||
notracing-out.csv
|
||||
testdb
|
||||
12
extractor-smoke-test/expected.csv
Normal file
12
extractor-smoke-test/expected.csv
Normal file
@@ -0,0 +1,12 @@
|
||||
"nd","col1"
|
||||
"entry","skip"
|
||||
"entry","skip"
|
||||
"function declaration","exit"
|
||||
"assignment to i","selection of Println"
|
||||
"skip","skip"
|
||||
"skip","function declaration"
|
||||
"skip","1"
|
||||
"1","assignment to i"
|
||||
"call to Println","exit"
|
||||
"selection of Println","i"
|
||||
"i","call to Println"
|
||||
|
3
extractor-smoke-test/go.mod
Normal file
3
extractor-smoke-test/go.mod
Normal file
@@ -0,0 +1,3 @@
|
||||
module github.com/codeql-go-extractor-smoke-test
|
||||
|
||||
go 1.14
|
||||
8
extractor-smoke-test/main.go
Normal file
8
extractor-smoke-test/main.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
var i int = 1
|
||||
fmt.Println(i)
|
||||
}
|
||||
24
extractor-smoke-test/test.sh
Executable file
24
extractor-smoke-test/test.sh
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||
cd $DIR
|
||||
|
||||
rm -rf testdb
|
||||
|
||||
codeql database create --language=go testdb --search-path ..
|
||||
codeql query run ../ql/test/library-tests/semmle/go/controlflow/ControlFlowGraph/ControlFlowNode_getASuccessor.ql --database=testdb --output=notracing-out.bqrs --search-path ..
|
||||
codeql bqrs decode notracing-out.bqrs --format=csv --output=notracing-out.csv
|
||||
diff -w -u notracing-out.csv expected.csv
|
||||
|
||||
# Now do it again with tracing enabled
|
||||
|
||||
export CODEQL_EXTRACTOR_GO_BUILD_TRACING=on
|
||||
|
||||
rm -rf testdb
|
||||
|
||||
codeql database create --language=go testdb --search-path ..
|
||||
codeql query run ../ql/test/library-tests/semmle/go/controlflow/ControlFlowGraph/ControlFlowNode_getASuccessor.ql --database=testdb --output=tracing-out.bqrs --search-path ..
|
||||
codeql bqrs decode tracing-out.bqrs --format=csv --output=tracing-out.csv
|
||||
diff -w -u tracing-out.csv expected.csv
|
||||
@@ -145,9 +145,7 @@ func RunCmd(cmd *exec.Cmd) bool {
|
||||
|
||||
func getOsToolsSubdir() (string, error) {
|
||||
platform, set := os.LookupEnv("CODEQL_PLATFORM")
|
||||
if !set {
|
||||
log.Print("CODEQL_PLATFORM not set; this binary should be run from the `codeql` CLI. Falling back to use `runtime.GOOS`.\n")
|
||||
} else {
|
||||
if set && platform != "" {
|
||||
return platform, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user