Kotlin: Provide a way for tests to cause an exception

This commit is contained in:
Ian Lynagh
2022-01-25 16:25:59 +00:00
parent 89eae2407b
commit 16a27f5258

View File

@@ -50,6 +50,15 @@ open class KotlinFileExtractor(
val pkgId = extractPackage(pkg)
tw.writeHasLocation(id, locId)
tw.writeCupackage(id, pkgId)
val exceptionOnFile = System.getenv("CODEQL_KOTLIN_INTERNAL_EXCEPTION_WHILE_EXTRACTING_FILE")
if(exceptionOnFile != null) {
@OptIn(kotlin.ExperimentalStdlibApi::class) // Annotation required by kotlin versions < 1.5
if(exceptionOnFile.lowercase() == file.name.lowercase()) {
throw Exception("Internal testing exception")
}
}
file.declarations.map { extractDeclaration(it) }
CommentExtractor(this, file, tw.fileId).extract()
}