[Wasm] Test infra: support _commonFiles and additional .mjs

Use custom `evalToBoolean` as `eval` and `unsafeCast` are not
 available in Wasm stdlib
This commit is contained in:
Svyatoslav Kuzmich
2023-01-11 12:59:52 +01:00
committed by Space Team
parent 80e07d628b
commit fd67464d14
3 changed files with 13 additions and 3 deletions
@@ -47,6 +47,7 @@ abstract class BasicWasmBoxTest(
private val testGroupOutputDirForCompilation = File(pathToRootOutputDir + "out/" + testGroupOutputDirPrefix) private val testGroupOutputDirForCompilation = File(pathToRootOutputDir + "out/" + testGroupOutputDirPrefix)
private val COMMON_FILES_NAME = "_common" private val COMMON_FILES_NAME = "_common"
private val COMMON_FILES_DIR = "_commonFiles"
private val extraLanguageFeatures = mapOf( private val extraLanguageFeatures = mapOf(
LanguageFeature.JsAllowImplementingFunctionInterface to LanguageFeature.State.ENABLED, LanguageFeature.JsAllowImplementingFunctionInterface to LanguageFeature.State.ENABLED,
@@ -98,11 +99,18 @@ abstract class BasicWasmBoxTest(
if (File(additionalJsFile).exists()) { if (File(additionalJsFile).exists()) {
jsFilesBefore += additionalJsFile jsFilesBefore += additionalJsFile
} }
val additionalMjsFile = filePath.removeSuffix(".kt") + ".mjs"
if (File(additionalMjsFile).exists()) {
mjsFiles += additionalMjsFile
}
val localCommonFile = file.parent + "/" + COMMON_FILES_NAME + "." + KotlinFileType.EXTENSION val localCommonFile = file.parent + "/" + COMMON_FILES_NAME + "." + KotlinFileType.EXTENSION
val localCommonFiles = if (File(localCommonFile).exists()) listOf(localCommonFile) else emptyList() val localCommonFiles = if (File(localCommonFile).exists()) listOf(localCommonFile) else emptyList()
val allSourceFiles = kotlinFiles + localCommonFiles val globalCommonFilesDir = File(File(pathToTestDir).parent, COMMON_FILES_DIR)
val globalCommonFiles = globalCommonFilesDir.listFiles().orEmpty().map { it.absolutePath }
val allSourceFiles = kotlinFiles + localCommonFiles + globalCommonFiles
val psiFiles = createPsiFiles(allSourceFiles.map { File(it).canonicalPath }.sorted()) val psiFiles = createPsiFiles(allSourceFiles.map { File(it).canonicalPath }.sorted())
val config = createConfig(languageVersionSettings) val config = createConfig(languageVersionSettings)
+4 -1
View File
@@ -1,6 +1,9 @@
package testUtils package testUtils
@JsName("eval")
private external fun evalToBoolean(code: String): Boolean
fun isLegacyBackend(): Boolean = fun isLegacyBackend(): Boolean =
// Using eval to prevent DCE from thinking that following code depends on Kotlin module. // Using eval to prevent DCE from thinking that following code depends on Kotlin module.
eval("(typeof Kotlin != \"undefined\" && typeof Kotlin.kotlin != \"undefined\")").unsafeCast<Boolean>() evalToBoolean("(typeof Kotlin != \"undefined\" && typeof Kotlin.kotlin != \"undefined\")")
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: WASM
// EXPECTED_REACHABLE_NODES: 1285 // EXPECTED_REACHABLE_NODES: 1285
package foo package foo