Merge pull request #19344 from jketema/swift-files

Swift: Make file checking in tests more strict
This commit is contained in:
Jeroen Ketema
2025-04-22 15:33:15 +02:00
committed by GitHub
8 changed files with 9 additions and 7 deletions

View File

@@ -6,7 +6,8 @@ import codeql.swift.elements.expr.internal.DotSyntaxCallExpr
cached
predicate toBeTested(Element e) {
e instanceof File
e instanceof File and
(exists(e.(File).getRelativePath()) or e instanceof UnknownFile)
or
e instanceof ParameterizedProtocolType
or

View File

@@ -21,5 +21,5 @@ string describe(Decl d) {
}
from Decl d
where d.getLocation().getFile().getName() != ""
where exists(d.getLocation().getFile().getRelativePath())
select d, strictconcat(describe(d), ", ")

View File

@@ -27,6 +27,6 @@ string describe(Function f) {
from Function f
where
not f.getFile() instanceof UnknownFile and
exists(f.getFile().getRelativePath()) and
not f.getName().matches("%init%")
select f, concat(describe(f), ", ")

View File

@@ -16,7 +16,7 @@ string describe(Type t) {
from VarDecl v, Type t
where
v.getLocation().getFile().getBaseName() != "" and
exists(v.getLocation().getFile().getRelativePath()) and
not v.getName() = "self" and
t = v.getType()
select v, t.toString(), concat(describe(t), ", ")

View File

@@ -14,7 +14,7 @@ string describe(TypeDecl td) {
from VarDecl v, TypeDecl td
where
v.getLocation().getFile().getBaseName() != "" and
exists(v.getLocation().getFile().getRelativePath()) and
not v.getName() = "self" and
(
td = v.getType().(NominalType).getDeclaration() or

View File

@@ -14,6 +14,6 @@ string describe(Type t) {
from VarDecl v, Type t
where
v.getLocation().getFile().getBaseName() != "" and
exists(v.getLocation().getFile().getRelativePath()) and
t = v.getType()
select v, t.toString(), concat(describe(t), ", ")

View File

@@ -22,6 +22,6 @@ string describe(Type t) {
from VarDecl v, Type t
where
v.getLocation().getFile().getBaseName() != "" and
exists(v.getLocation().getFile().getRelativePath()) and
t = v.getType()
select v, t.toString(), strictconcat(describe(t), ", ")

View File

@@ -3,4 +3,5 @@ import swift
string describe(File f) { (f.isSuccessfullyExtracted() and result = "isSuccessfullyExtracted") }
from File f
where exists(f.getRelativePath()) or f instanceof UnknownFile
select f, concat(f.getRelativePath(), ", "), concat(describe(f), ", ")