Skip to content

Commit 450a4a0

Browse files
committed
Swift: add incomplete ast test
The test was inspired by locally running the query against files in https://github.com/apple/swift/tree/main/test/Parse A query for missing elements was also added to the AST tests, expecting nothing to be found.
1 parent d6fb6bf commit 450a4a0

11 files changed

+76
-4
lines changed

swift/ql/test/TestUtils.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@ predicate toBeTested(Element e) {
2929
)
3030
)
3131
)
32+
or
33+
toBeTested(e.(UnspecifiedElement).getParent())
3234
}

swift/ql/test/extractor-tests/generated/UnspecifiedElement/MISSING_SOURCE.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
| wrong.swift:3:1:3:23 | missing extended_type_decl from ExtensionDecl | getProperty: | extended_type_decl | getError: | element was unspecified by the extractor |
2+
| wrong.swift:9:9:9:9 | missing fallthrough_dest from FallthroughStmt | getProperty: | fallthrough_dest | getError: | element was unspecified by the extractor |
3+
| wrong.swift:9:9:9:9 | missing fallthrough_source from FallthroughStmt | getProperty: | fallthrough_source | getError: | element was unspecified by the extractor |
4+
| wrong.swift:12:18:12:21 | missing element from EnumElementPattern | getProperty: | element | getError: | element was unspecified by the extractor |
5+
| wrong.swift:14:18:14:26 | missing element from EnumElementPattern | getProperty: | element | getError: | element was unspecified by the extractor |
6+
| wrong.swift:19:18:19:19 | missing element from EnumElementPattern | getProperty: | element | getError: | element was unspecified by the extractor |
7+
| wrong.swift:22:13:22:13 | missing fallthrough_dest from FallthroughStmt | getProperty: | fallthrough_dest | getError: | element was unspecified by the extractor |
8+
| wrong.swift:22:13:22:13 | missing fallthrough_source from FallthroughStmt | getProperty: | fallthrough_source | getError: | element was unspecified by the extractor |
9+
| wrong.swift:26:18:26:19 | missing element from EnumElementPattern | getProperty: | element | getError: | element was unspecified by the extractor |
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// generated by codegen/codegen.py
2+
import codeql.swift.elements
3+
import TestUtils
4+
5+
from UnspecifiedElement x, string getProperty, string getError
6+
where
7+
toBeTested(x) and
8+
not x.isUnknown() and
9+
getProperty = x.getProperty() and
10+
getError = x.getError()
11+
select x, "getProperty:", getProperty, "getError:", getError

swift/ql/test/extractor-tests/generated/UnspecifiedElement/UnspecifiedElement_getIndex.expected

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// generated by codegen/codegen.py
2+
import codeql.swift.elements
3+
import TestUtils
4+
5+
from UnspecifiedElement x
6+
where toBeTested(x) and not x.isUnknown()
7+
select x, x.getIndex()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
| wrong.swift:3:1:3:23 | missing extended_type_decl from ExtensionDecl | extension |
2+
| wrong.swift:9:9:9:9 | missing fallthrough_dest from FallthroughStmt | fallthrough |
3+
| wrong.swift:9:9:9:9 | missing fallthrough_source from FallthroughStmt | fallthrough |
4+
| wrong.swift:12:18:12:21 | missing element from EnumElementPattern | (no string representation) |
5+
| wrong.swift:14:18:14:26 | missing element from EnumElementPattern | (no string representation) |
6+
| wrong.swift:19:18:19:19 | missing element from EnumElementPattern | (no string representation) |
7+
| wrong.swift:22:13:22:13 | missing fallthrough_dest from FallthroughStmt | fallthrough |
8+
| wrong.swift:22:13:22:13 | missing fallthrough_source from FallthroughStmt | fallthrough |
9+
| wrong.swift:26:18:26:19 | missing element from EnumElementPattern | (no string representation) |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// generated by codegen/codegen.py
2+
import codeql.swift.elements
3+
import TestUtils
4+
5+
from UnspecifiedElement x
6+
where toBeTested(x) and not x.isUnknown()
7+
select x, x.getParent()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//codeql-extractor-expected-status: 1
2+
3+
extension Undefined { }
4+
5+
enum Enum {
6+
case A, B
7+
8+
func test(e: Enum) {
9+
fallthrough
10+
11+
switch e {
12+
case .A():
13+
break
14+
case .B(let x):
15+
let _ = x
16+
break
17+
case Int:
18+
break
19+
case .C:
20+
break
21+
default:
22+
fallthrough
23+
}
24+
25+
switch undefined {
26+
case .Whatever:
27+
break
28+
}
29+
}
30+
}

swift/ql/test/library-tests/ast/Missing.expected

Whitespace-only changes.

0 commit comments

Comments
 (0)