[JS] BasicBoxTest.kt: cleanup
This commit is contained in:
@@ -67,15 +67,15 @@ import java.util.regex.Matcher
|
|||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
|
|
||||||
abstract class BasicBoxTest(
|
abstract class BasicBoxTest(
|
||||||
protected val pathToTestDir: String,
|
protected val pathToTestDir: String,
|
||||||
testGroupOutputDirPrefix: String,
|
testGroupOutputDirPrefix: String,
|
||||||
pathToRootOutputDir: String = BasicBoxTest.TEST_DATA_DIR_PATH,
|
pathToRootOutputDir: String = TEST_DATA_DIR_PATH,
|
||||||
private val typedArraysEnabled: Boolean = true,
|
private val typedArraysEnabled: Boolean = true,
|
||||||
private val generateSourceMap: Boolean = false,
|
private val generateSourceMap: Boolean = false,
|
||||||
private val generateNodeJsRunner: Boolean = true,
|
private val generateNodeJsRunner: Boolean = true,
|
||||||
private val targetBackend: TargetBackend = TargetBackend.JS
|
private val targetBackend: TargetBackend = TargetBackend.JS
|
||||||
) : KotlinTestWithEnvironment() {
|
) : KotlinTestWithEnvironment() {
|
||||||
val additionalCommonFileDirectories = mutableListOf<String>()
|
private val additionalCommonFileDirectories = mutableListOf<String>()
|
||||||
|
|
||||||
private val testGroupOutputDirForCompilation = File(pathToRootOutputDir + "out/" + testGroupOutputDirPrefix)
|
private val testGroupOutputDirForCompilation = File(pathToRootOutputDir + "out/" + testGroupOutputDirPrefix)
|
||||||
private val testGroupOutputDirForMinification = File(pathToRootOutputDir + "out-min/" + testGroupOutputDirPrefix)
|
private val testGroupOutputDirForMinification = File(pathToRootOutputDir + "out-min/" + testGroupOutputDirPrefix)
|
||||||
@@ -145,8 +145,8 @@ abstract class BasicBoxTest(
|
|||||||
coroutinesPackage
|
coroutinesPackage
|
||||||
)
|
)
|
||||||
val modules = inputFiles
|
val modules = inputFiles
|
||||||
.map { it.module }.distinct()
|
.map { it.module }.distinct()
|
||||||
.map { it.name to it }.toMap()
|
.map { it.name to it }.toMap()
|
||||||
|
|
||||||
fun TestModule.allTransitiveDependencies(): Set<String> {
|
fun TestModule.allTransitiveDependencies(): Set<String> {
|
||||||
return dependenciesSymbols.toSet() + dependenciesSymbols.flatMap { modules[it]!!.allTransitiveDependencies() }
|
return dependenciesSymbols.toSet() + dependenciesSymbols.flatMap { modules[it]!!.allTransitiveDependencies() }
|
||||||
@@ -218,13 +218,13 @@ abstract class BasicBoxTest(
|
|||||||
JsTestUtils.getFilesInDirectoryByExtension(baseDir + "/", JavaScript.EXTENSION)
|
JsTestUtils.getFilesInDirectoryByExtension(baseDir + "/", JavaScript.EXTENSION)
|
||||||
}
|
}
|
||||||
val inputJsFiles = inputFiles
|
val inputJsFiles = inputFiles
|
||||||
.filter { it.fileName.endsWith(".js") }
|
.filter { it.fileName.endsWith(".js") }
|
||||||
.map { inputJsFile ->
|
.map { inputJsFile ->
|
||||||
val sourceFile = File(inputJsFile.fileName)
|
val sourceFile = File(inputJsFile.fileName)
|
||||||
val targetFile = File(outputDir, inputJsFile.module.outputFileSimpleName() + "-js-" + sourceFile.name)
|
val targetFile = File(outputDir, inputJsFile.module.outputFileSimpleName() + "-js-" + sourceFile.name)
|
||||||
FileUtil.copy(File(inputJsFile.fileName), targetFile)
|
FileUtil.copy(File(inputJsFile.fileName), targetFile)
|
||||||
targetFile.absolutePath
|
targetFile.absolutePath
|
||||||
}
|
}
|
||||||
|
|
||||||
val additionalFiles = mutableListOf<String>()
|
val additionalFiles = mutableListOf<String>()
|
||||||
|
|
||||||
@@ -562,21 +562,10 @@ abstract class BasicBoxTest(
|
|||||||
val recompiledOutputFile = File(outputFile.parentFile, outputFile.nameWithoutExtension + "-recompiled.js")
|
val recompiledOutputFile = File(outputFile.parentFile, outputFile.nameWithoutExtension + "-recompiled.js")
|
||||||
|
|
||||||
translateFiles(
|
translateFiles(
|
||||||
translationUnits,
|
translationUnits, recompiledOutputFile, recompiledOutputFile, recompiledOutputFile, recompiledConfig,
|
||||||
recompiledOutputFile,
|
outputPrefixFile, outputPostfixFile,
|
||||||
recompiledOutputFile,
|
mainCallParameters, incrementalData, remap, testPackage, testFunction, needsFullIrRuntime,
|
||||||
recompiledOutputFile,
|
isMainModule = false, skipDceDriven = true,
|
||||||
recompiledConfig,
|
|
||||||
outputPrefixFile,
|
|
||||||
outputPostfixFile,
|
|
||||||
mainCallParameters,
|
|
||||||
incrementalData,
|
|
||||||
remap,
|
|
||||||
testPackage,
|
|
||||||
testFunction,
|
|
||||||
needsFullIrRuntime,
|
|
||||||
isMainModule = false,
|
|
||||||
skipDceDriven = true,
|
|
||||||
splitPerModule = false,
|
splitPerModule = false,
|
||||||
propertyLazyInitialization = false,
|
propertyLazyInitialization = false,
|
||||||
)
|
)
|
||||||
@@ -586,23 +575,27 @@ abstract class BasicBoxTest(
|
|||||||
assertEquals("Output file changed after recompilation", originalOutput, recompiledOutput)
|
assertEquals("Output file changed after recompilation", originalOutput, recompiledOutput)
|
||||||
|
|
||||||
val originalSourceMap = FileUtil.loadFile(File(outputFile.parentFile, outputFile.name + ".map"))
|
val originalSourceMap = FileUtil.loadFile(File(outputFile.parentFile, outputFile.name + ".map"))
|
||||||
val recompiledSourceMap = removeRecompiledSuffix(
|
val recompiledSourceMap =
|
||||||
FileUtil.loadFile(File(recompiledOutputFile.parentFile, recompiledOutputFile.name + ".map")))
|
removeRecompiledSuffix(FileUtil.loadFile(File(recompiledOutputFile.parentFile, recompiledOutputFile.name + ".map")))
|
||||||
if (originalSourceMap != recompiledSourceMap) {
|
if (originalSourceMap != recompiledSourceMap) {
|
||||||
val originalSourceMapParse = SourceMapParser.parse(originalSourceMap)
|
val originalSourceMapParse = SourceMapParser.parse(originalSourceMap)
|
||||||
val recompiledSourceMapParse = SourceMapParser.parse(recompiledSourceMap)
|
val recompiledSourceMapParse = SourceMapParser.parse(recompiledSourceMap)
|
||||||
if (originalSourceMapParse is SourceMapSuccess && recompiledSourceMapParse is SourceMapSuccess) {
|
if (originalSourceMapParse is SourceMapSuccess && recompiledSourceMapParse is SourceMapSuccess) {
|
||||||
assertEquals("Source map file changed after recompilation",
|
assertEquals(
|
||||||
originalSourceMapParse.toDebugString(),
|
"Source map file changed after recompilation",
|
||||||
recompiledSourceMapParse.toDebugString())
|
originalSourceMapParse.toDebugString(),
|
||||||
|
recompiledSourceMapParse.toDebugString()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
assertEquals("Source map file changed after recompilation", originalSourceMap, recompiledSourceMap)
|
assertEquals("Source map file changed after recompilation", originalSourceMap, recompiledSourceMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (multiModule) {
|
if (multiModule) {
|
||||||
val originalMetadata = FileUtil.loadFile(File(outputFile.parentFile, outputFile.nameWithoutExtension + ".meta.js"))
|
val originalMetadata = FileUtil.loadFile(File(outputFile.parentFile, outputFile.nameWithoutExtension + ".meta.js"))
|
||||||
val recompiledMetadata = removeRecompiledSuffix(
|
val recompiledMetadata =
|
||||||
FileUtil.loadFile(File(recompiledOutputFile.parentFile, recompiledOutputFile.nameWithoutExtension + ".meta.js")))
|
removeRecompiledSuffix(
|
||||||
|
FileUtil.loadFile(File(recompiledOutputFile.parentFile, recompiledOutputFile.nameWithoutExtension + ".meta.js"))
|
||||||
|
)
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Metadata file changed after recompilation",
|
"Metadata file changed after recompilation",
|
||||||
metadataAsString(originalMetadata),
|
metadataAsString(originalMetadata),
|
||||||
@@ -775,13 +768,11 @@ abstract class BasicBoxTest(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun createPsiFile(fileName: String): KtFile {
|
private fun createPsiFile(fileName: String): KtFile {
|
||||||
val psiManager = PsiManager.getInstance(project)
|
val psiManager = PsiManager.getInstance(project)
|
||||||
val fileSystem = VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.FILE_PROTOCOL)
|
val fileSystem = VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.FILE_PROTOCOL)
|
||||||
|
|
||||||
val file = fileSystem.findFileByPath(fileName)
|
val file = fileSystem.findFileByPath(fileName) ?: error("File not found: ${fileName}")
|
||||||
if (file == null)
|
|
||||||
error("File not found: ${fileName}")
|
|
||||||
|
|
||||||
return psiManager.findFile(file) as KtFile
|
return psiManager.findFile(file) as KtFile
|
||||||
}
|
}
|
||||||
@@ -1061,10 +1052,10 @@ abstract class BasicBoxTest(
|
|||||||
@JvmStatic
|
@JvmStatic
|
||||||
protected val runTestInNashorn = getBoolean("kotlin.js.useNashorn")
|
protected val runTestInNashorn = getBoolean("kotlin.js.useNashorn")
|
||||||
|
|
||||||
val TEST_MODULE = "JS_TESTS"
|
const val TEST_MODULE = "JS_TESTS"
|
||||||
private val DEFAULT_MODULE = "main"
|
private const val DEFAULT_MODULE = "main"
|
||||||
private val TEST_FUNCTION = "box"
|
private const val TEST_FUNCTION = "box"
|
||||||
private val OLD_MODULE_SUFFIX = "-old"
|
private const val OLD_MODULE_SUFFIX = "-old"
|
||||||
|
|
||||||
const val KOTLIN_TEST_INTERNAL = "\$kotlin_test_internal\$"
|
const val KOTLIN_TEST_INTERNAL = "\$kotlin_test_internal\$"
|
||||||
private val engineForMinifier =
|
private val engineForMinifier =
|
||||||
@@ -1084,4 +1075,4 @@ fun KotlinTestWithEnvironment.createPsiFile(fileName: String): KtFile {
|
|||||||
return psiManager.findFile(file) as KtFile
|
return psiManager.findFile(file) as KtFile
|
||||||
}
|
}
|
||||||
|
|
||||||
fun KotlinTestWithEnvironment.createPsiFiles(fileNames: List<String>): List<KtFile> = fileNames.map(this::createPsiFile)
|
fun KotlinTestWithEnvironment.createPsiFiles(fileNames: List<String>): List<KtFile> = fileNames.map(this::createPsiFile)
|
||||||
|
|||||||
Reference in New Issue
Block a user