Skip to content

Commit ce5c481

Browse files
committed
Swift: Make file checking in tests more strict
With Swift 6.1 the extractor will start to extract files outside of the test directory. These files and their elements we do not want to see in our tests.
1 parent 53bd236 commit ce5c481

File tree

8 files changed

+9
-7
lines changed

8 files changed

+9
-7
lines changed

swift/ql/test/TestUtils.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import codeql.swift.elements.expr.internal.DotSyntaxCallExpr
66

77
cached
88
predicate toBeTested(Element e) {
9-
e instanceof File
9+
e instanceof File and
10+
(exists(e.(File).getRelativePath()) or e instanceof UnknownFile)
1011
or
1112
e instanceof ParameterizedProtocolType
1213
or

swift/ql/test/library-tests/elements/decl/enumdecl/enumdecl.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ string describe(Decl d) {
2121
}
2222

2323
from Decl d
24-
where d.getLocation().getFile().getName() != ""
24+
where exists(d.getLocation().getFile().getRelativePath())
2525
select d, strictconcat(describe(d), ", ")

swift/ql/test/library-tests/elements/decl/function/function.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ string describe(Function f) {
2727

2828
from Function f
2929
where
30-
not f.getFile() instanceof UnknownFile and
30+
exists(f.getFile().getRelativePath()) and
3131
not f.getName().matches("%init%")
3232
select f, concat(describe(f), ", ")

swift/ql/test/library-tests/elements/type/nominaltype/nominaltype.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ string describe(Type t) {
1616

1717
from VarDecl v, Type t
1818
where
19-
v.getLocation().getFile().getBaseName() != "" and
19+
exists(v.getLocation().getFile().getRelativePath()) and
2020
not v.getName() = "self" and
2121
t = v.getType()
2222
select v, t.toString(), concat(describe(t), ", ")

swift/ql/test/library-tests/elements/type/nominaltype/nominaltypedecl.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ string describe(TypeDecl td) {
1414

1515
from VarDecl v, TypeDecl td
1616
where
17-
v.getLocation().getFile().getBaseName() != "" and
17+
exists(v.getLocation().getFile().getRelativePath()) and
1818
not v.getName() = "self" and
1919
(
2020
td = v.getType().(NominalType).getDeclaration() or

swift/ql/test/library-tests/elements/type/numerictype/numerictype.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ string describe(Type t) {
1414

1515
from VarDecl v, Type t
1616
where
17-
v.getLocation().getFile().getBaseName() != "" and
17+
exists(v.getLocation().getFile().getRelativePath()) and
1818
t = v.getType()
1919
select v, t.toString(), concat(describe(t), ", ")

swift/ql/test/library-tests/elements/type/pointertypes/pointertypes.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ string describe(Type t) {
2222

2323
from VarDecl v, Type t
2424
where
25-
v.getLocation().getFile().getBaseName() != "" and
25+
exists(v.getLocation().getFile().getRelativePath()) and
2626
t = v.getType()
2727
select v, t.toString(), strictconcat(describe(t), ", ")

swift/ql/test/query-tests/Diagnostics/Info.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ import swift
33
string describe(File f) { (f.isSuccessfullyExtracted() and result = "isSuccessfullyExtracted") }
44

55
from File f
6+
where exists(f.getRelativePath()) or f instanceof UnknownFile
67
select f, concat(f.getRelativePath(), ", "), concat(describe(f), ", ")

0 commit comments

Comments
 (0)