Skip to content

Commit 3acd448

Browse files
committed
Swift: add tests for RUN_UNDER support
While I would have preferred to add a proper unit test, this required more infrastructure for mocking system calls. Instead I made `qltest.sh` accept a `//codeql-extractor-env` header and used that to write a QL test exercising the `RUN_UNDER` functionality.
1 parent 82998ce commit 3acd448

File tree

12 files changed

+38
-2
lines changed

12 files changed

+38
-2
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| run_under: $CODEQL_EXTRACTOR_SWIFT_ROOT/tools/$CODEQL_PLATFORM/extractor -sdk $CODEQL_EXTRACTOR_SWIFT_ROOT/qltest/$CODEQL_PLATFORM/sdk -c -primary-file filtered_in.swift |
2+
| run_under: $CODEQL_EXTRACTOR_SWIFT_ROOT/tools/$CODEQL_PLATFORM/extractor -sdk $CODEQL_EXTRACTOR_SWIFT_ROOT/qltest/$CODEQL_PLATFORM/sdk -c -primary-file unfiltered.swift |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import swift
2+
3+
from StringLiteralExpr s
4+
select s.getValue()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//codeql-extractor-env: CODEQL_EXTRACTOR_SWIFT_RUN_UNDER=./run_under.sh CODEQL_EXTRACTOR_SWIFT_RUN_UNDER_FILTER=filtered_in\.swift
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//codeql-extractor-env: CODEQL_EXTRACTOR_SWIFT_RUN_UNDER=./run_under.sh CODEQL_EXTRACTOR_SWIFT_RUN_UNDER_FILTER=filtered_in\.swift

swift/ql/test/extractor-tests/run_under/normal.swift

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ARGS=$(echo $@ | sed 's='$CODEQL_EXTRACTOR_SWIFT_ROOT'=$CODEQL_EXTRACTOR_SWIFT_ROOT=g; s/'$CODEQL_PLATFORM'/$CODEQL_PLATFORM/g')
2+
3+
cat > $CODEQL_EXTRACTOR_SWIFT_TRAP_DIR/$$.trap << EOF
4+
string_literal_exprs(*, "run_under: $ARGS")
5+
EOF
6+
7+
"$@"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//codeql-extractor-env: CODEQL_EXTRACTOR_SWIFT_RUN_UNDER=./run_under.sh

swift/tools/qltest.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ EXTRACTOR="$CODEQL_EXTRACTOR_SWIFT_ROOT/tools/$CODEQL_PLATFORM/extractor"
1010
SDK="$CODEQL_EXTRACTOR_SWIFT_ROOT/qltest/$CODEQL_PLATFORM/sdk"
1111

1212
for src in *.swift; do
13+
env=()
1314
opts=(-sdk "$SDK" -c -primary-file "$src")
1415
opts+=($(sed -n '1 s=//codeql-extractor-options:==p' $src))
16+
env+=($(sed -n '1 s=//codeql-extractor-env:==p' $src))
1517
echo -e "calling extractor with flags: ${opts[@]}\n" >> $QLTEST_LOG
16-
if ! "$EXTRACTOR" "${opts[@]}" >> $QLTEST_LOG 2>&1; then
18+
if ! env "${env[@]}" "$EXTRACTOR" "${opts[@]}" >> $QLTEST_LOG 2>&1; then
1719
FAILED=1
1820
fi
1921
done
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//codeql-extractor-env: VAR1=foo
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//codeql-extractor-env: VAR1=bar VAR2=baz

0 commit comments

Comments
 (0)