Files
codeql/swift/ql/test/TestUtils.qll
Jeroen Ketema ce5c48192e 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.
2025-04-22 10:41:12 +02:00

53 lines
1.3 KiB
Plaintext

private import codeql.swift.elements
private import codeql.swift.generated.ParentChild
// Internal classes are not imported by the tests:
import codeql.swift.elements.expr.internal.InitializerRefCallExpr
import codeql.swift.elements.expr.internal.DotSyntaxCallExpr
cached
predicate toBeTested(Element e) {
e instanceof File and
(exists(e.(File).getRelativePath()) or e instanceof UnknownFile)
or
e instanceof ParameterizedProtocolType
or
e instanceof PackType
or
e instanceof PackElementType
or
e instanceof PackArchetypeType
or
e instanceof MacroRole
or
exists(ModuleDecl m |
m = e and
not m.isBuiltinModule() and
not m.isSystemModule()
)
or
e.(Locatable).getLocation().getFile().getName().matches("%swift/ql/test%")
or
exists(Element tested |
toBeTested(tested) and
(
e = tested.(ValueDecl).getInterfaceType()
or
e = tested.(NominalTypeDecl).getType()
or
e = tested.(VarDecl).getType()
or
e = tested.(Expr).getType()
or
e = tested.(Type).getCanonicalType()
or
e = tested.(ExistentialType).getConstraint()
or
e.(UnspecifiedElement).getParent() = tested
or
e.(OpaqueTypeDecl).getNamingDeclaration() = tested
or
tested = getImmediateParent(e)
)
)
}