Skip to content

Commit 3045eec

Browse files
author
Sauyon Lee
authored
Merge pull request #518 from smowton/smowton/fix/restore-extraction-under-codeql
Tolerate empty-string CODEQL_PLATFORM, and add smoke tests
2 parents a8422ff + 87d8bc8 commit 3045eec

File tree

7 files changed

+53
-3
lines changed

7 files changed

+53
-3
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ test: all build/testdb/check-upgrade-path
118118
# use GOOS=linux because GOOS=darwin GOARCH=386 is no longer supported
119119
env GOOS=linux GOARCH=386 codeql$(EXE) test run ql/test/query-tests/Security/CWE-681 --search-path . --consistency-queries ql/test/consistency
120120
cd extractor; go test -mod=vendor ./... | grep -vF "[no test files]"
121+
bash extractor-smoke-test/test.sh || (echo "Extractor smoke test FAILED"; exit 1)
121122

122123
.PHONY: build/testdb/check-upgrade-path
123124
build/testdb/check-upgrade-path : build/testdb/go.dbscheme ql/src/go.dbscheme

extractor-smoke-test/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.bqrs
2+
tracing-out.csv
3+
notracing-out.csv
4+
testdb

extractor-smoke-test/expected.csv

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"nd","col1"
2+
"entry","skip"
3+
"entry","skip"
4+
"function declaration","exit"
5+
"assignment to i","selection of Println"
6+
"skip","skip"
7+
"skip","function declaration"
8+
"skip","1"
9+
"1","assignment to i"
10+
"call to Println","exit"
11+
"selection of Println","i"
12+
"i","call to Println"

extractor-smoke-test/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/codeql-go-extractor-smoke-test
2+
3+
go 1.14

extractor-smoke-test/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
var i int = 1
7+
fmt.Println(i)
8+
}

extractor-smoke-test/test.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
6+
cd $DIR
7+
8+
rm -rf testdb
9+
10+
codeql database create --language=go testdb --search-path ..
11+
codeql query run ../ql/test/library-tests/semmle/go/controlflow/ControlFlowGraph/ControlFlowNode_getASuccessor.ql --database=testdb --output=notracing-out.bqrs --search-path ..
12+
codeql bqrs decode notracing-out.bqrs --format=csv --output=notracing-out.csv
13+
diff -w -u notracing-out.csv expected.csv
14+
15+
# Now do it again with tracing enabled
16+
17+
export CODEQL_EXTRACTOR_GO_BUILD_TRACING=on
18+
19+
rm -rf testdb
20+
21+
codeql database create --language=go testdb --search-path ..
22+
codeql query run ../ql/test/library-tests/semmle/go/controlflow/ControlFlowGraph/ControlFlowNode_getASuccessor.ql --database=testdb --output=tracing-out.bqrs --search-path ..
23+
codeql bqrs decode tracing-out.bqrs --format=csv --output=tracing-out.csv
24+
diff -w -u tracing-out.csv expected.csv

extractor/util/util.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,7 @@ func RunCmd(cmd *exec.Cmd) bool {
145145

146146
func getOsToolsSubdir() (string, error) {
147147
platform, set := os.LookupEnv("CODEQL_PLATFORM")
148-
if !set {
149-
log.Print("CODEQL_PLATFORM not set; this binary should be run from the `codeql` CLI. Falling back to use `runtime.GOOS`.\n")
150-
} else {
148+
if set && platform != "" {
151149
return platform, nil
152150
}
153151

0 commit comments

Comments
 (0)