Skip to content

Commit 4cfe11c

Browse files
committed
Swift: allow expecting failure in qltest.sh
1 parent 331b8c0 commit 4cfe11c

File tree

8 files changed

+29
-1
lines changed

8 files changed

+29
-1
lines changed

swift/tools/qltest.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ SDK="$CODEQL_EXTRACTOR_SWIFT_ROOT/qltest/$CODEQL_PLATFORM/sdk"
1212
for src in *.swift; do
1313
opts=(-sdk "$SDK" -c -primary-file "$src")
1414
opts+=($(sed -n '1 s=//codeql-extractor-options:==p' $src))
15+
expected_status=$(sed -n 's=//codeql-extractor-expected-status:\s*==p' $src)
16+
expected_status=${expected_status:-0}
1517
echo -e "calling extractor with flags: ${opts[@]}\n" >> $QLTEST_LOG
16-
if ! "$EXTRACTOR" "${opts[@]}" >> $QLTEST_LOG 2>&1; then
18+
"$EXTRACTOR" "${opts[@]}" >> $QLTEST_LOG 2>&1
19+
actual_status=$?
20+
if [[ $actual_status != $expected_status ]]; then
1721
FAILED=1
1822
fi
1923
done

swift/tools/test/qltest/expected_return_codes/a.swift

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//codeql-extractor-expected-status: 1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//codeql-extractor-expected-status: 42
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from swift.tools.test.qltest.utils import *
2+
3+
set_dummy_extractor()
4+
run_qltest(expected_returncode=1)
5+
assert_extractor_executed_with(
6+
"a.swift",
7+
"b.swift",
8+
"c.swift",
9+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//codeql-extractor-expected-status: 42
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//codeql-extractor-expected-status: 1
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from swift.tools.test.qltest.utils import *
2+
3+
set_dummy_extractor("""
4+
if [[ " $@ " =~ a.swift ]]; then exit 42; fi
5+
if [[ " $@ " =~ b.swift ]]; then exit 1; fi
6+
""")
7+
run_qltest()
8+
assert_extractor_executed_with(
9+
"a.swift",
10+
"b.swift",
11+
)

0 commit comments

Comments
 (0)