Build: Setup inputs and outputs for :js:js-tests:test task properly
All task inputs should be declared and separated from outputs produced by it (e.g. node modules and js compile outputs) to make gradle test distribution work
This commit is contained in:
@@ -188,14 +188,22 @@ fun Test.setUpJsBoxTests(jsEnabled: Boolean, jsIrEnabled: Boolean) {
|
|||||||
setupV8()
|
setupV8()
|
||||||
|
|
||||||
dependsOn(":dist")
|
dependsOn(":dist")
|
||||||
if (jsEnabled) dependsOn(testJsRuntime)
|
if (jsEnabled) {
|
||||||
|
dependsOn(testJsRuntime)
|
||||||
|
inputs.files(testJsRuntime)
|
||||||
|
}
|
||||||
if (jsIrEnabled) {
|
if (jsIrEnabled) {
|
||||||
dependsOn(":kotlin-stdlib-js-ir:compileKotlinJs")
|
dependsOn(":kotlin-stdlib-js-ir:compileKotlinJs")
|
||||||
systemProperty("kotlin.js.full.stdlib.path", "libraries/stdlib/js-ir/build/classes/kotlin/js/main")
|
systemProperty("kotlin.js.full.stdlib.path", "libraries/stdlib/js-ir/build/classes/kotlin/js/main")
|
||||||
|
inputs.dir(rootDir.resolve("libraries/stdlib/js-ir/build/classes/kotlin/js/main"))
|
||||||
|
|
||||||
dependsOn(":kotlin-stdlib-js-ir-minimal-for-test:compileKotlinJs")
|
dependsOn(":kotlin-stdlib-js-ir-minimal-for-test:compileKotlinJs")
|
||||||
systemProperty("kotlin.js.reduced.stdlib.path", "libraries/stdlib/js-ir-minimal-for-test/build/classes/kotlin/js/main")
|
systemProperty("kotlin.js.reduced.stdlib.path", "libraries/stdlib/js-ir-minimal-for-test/build/classes/kotlin/js/main")
|
||||||
|
inputs.dir(rootDir.resolve("libraries/stdlib/js-ir-minimal-for-test/build/classes/kotlin/js/main"))
|
||||||
|
|
||||||
dependsOn(":kotlin-test:kotlin-test-js-ir:compileKotlinJs")
|
dependsOn(":kotlin-test:kotlin-test-js-ir:compileKotlinJs")
|
||||||
systemProperty("kotlin.js.kotlin.test.path", "libraries/kotlin.test/js-ir/build/classes/kotlin/js/main")
|
systemProperty("kotlin.js.kotlin.test.path", "libraries/kotlin.test/js-ir/build/classes/kotlin/js/main")
|
||||||
|
inputs.dir(rootDir.resolve("libraries/kotlin.test/js-ir/build/classes/kotlin/js/main"))
|
||||||
}
|
}
|
||||||
|
|
||||||
exclude("org/jetbrains/kotlin/js/test/wasm/semantics/*")
|
exclude("org/jetbrains/kotlin/js/test/wasm/semantics/*")
|
||||||
@@ -210,6 +218,8 @@ fun Test.setUpJsBoxTests(jsEnabled: Boolean, jsIrEnabled: Boolean) {
|
|||||||
|
|
||||||
fun Test.setUpBoxTests() {
|
fun Test.setUpBoxTests() {
|
||||||
workingDir = rootDir
|
workingDir = rootDir
|
||||||
|
dependsOn(antLauncherJar)
|
||||||
|
inputs.files(antLauncherJar)
|
||||||
doFirst {
|
doFirst {
|
||||||
systemProperty("kotlin.ant.classpath", antLauncherJar.asPath)
|
systemProperty("kotlin.ant.classpath", antLauncherJar.asPath)
|
||||||
systemProperty("kotlin.ant.launcher.class", "org.apache.tools.ant.Main")
|
systemProperty("kotlin.ant.launcher.class", "org.apache.tools.ant.Main")
|
||||||
@@ -225,8 +235,23 @@ fun Test.setUpBoxTests() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val testDataDir = project(":js:js.translator").projectDir.resolve("testData")
|
||||||
|
|
||||||
projectTest(parallel = true) {
|
projectTest(parallel = true) {
|
||||||
setUpJsBoxTests(jsEnabled = true, jsIrEnabled = true)
|
setUpJsBoxTests(jsEnabled = true, jsIrEnabled = true)
|
||||||
|
|
||||||
|
inputs.dir(rootDir.resolve("compiler/cli/cli-common/resources")) // compiler.xml
|
||||||
|
|
||||||
|
inputs.dir(testDataDir)
|
||||||
|
inputs.dir(rootDir.resolve("dist"))
|
||||||
|
inputs.dir(rootDir.resolve("compiler/testData"))
|
||||||
|
inputs.dir(rootDir.resolve("libraries/stdlib/api/js"))
|
||||||
|
inputs.dir(rootDir.resolve("libraries/stdlib/api/js-v1"))
|
||||||
|
|
||||||
|
systemProperty("kotlin.js.test.root.out.dir", "$buildDir/")
|
||||||
|
outputs.dir("$buildDir/out")
|
||||||
|
outputs.dir("$buildDir/out-min")
|
||||||
|
outputs.dir("$buildDir/out-pir")
|
||||||
}
|
}
|
||||||
|
|
||||||
projectTest("jsTest", true) {
|
projectTest("jsTest", true) {
|
||||||
@@ -276,16 +301,23 @@ val generateTests by generator("org.jetbrains.kotlin.generators.tests.GenerateJs
|
|||||||
dependsOn(":compiler:generateTestData")
|
dependsOn(":compiler:generateTestData")
|
||||||
}
|
}
|
||||||
|
|
||||||
val testDataDir = project(":js:js.translator").projectDir.resolve("testData")
|
extensions.getByType(NodeExtension::class.java).nodeModulesDir = buildDir
|
||||||
|
|
||||||
extensions.getByType(NodeExtension::class.java).nodeModulesDir = testDataDir
|
val prepareMochaTestData by tasks.registering(Copy::class) {
|
||||||
|
from(testDataDir) {
|
||||||
|
include("package.json")
|
||||||
|
include("test.js")
|
||||||
|
}
|
||||||
|
into(buildDir)
|
||||||
|
}
|
||||||
|
|
||||||
val npmInstall by tasks.getting(NpmTask::class) {
|
val npmInstall by tasks.getting(NpmTask::class) {
|
||||||
setWorkingDir(testDataDir)
|
dependsOn(prepareMochaTestData)
|
||||||
|
setWorkingDir(buildDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
val runMocha by task<NpmTask> {
|
val runMocha by task<NpmTask> {
|
||||||
setWorkingDir(testDataDir)
|
setWorkingDir(buildDir)
|
||||||
|
|
||||||
val target = if (project.hasProperty("teamcity")) "runOnTeamcity" else "test"
|
val target = if (project.hasProperty("teamcity")) "runOnTeamcity" else "test"
|
||||||
setArgs(listOf("run", target))
|
setArgs(listOf("run", target))
|
||||||
@@ -296,6 +328,15 @@ val runMocha by task<NpmTask> {
|
|||||||
|
|
||||||
val check by tasks
|
val check by tasks
|
||||||
check.dependsOn(this)
|
check.dependsOn(this)
|
||||||
|
|
||||||
|
doFirst {
|
||||||
|
setEnvironment(
|
||||||
|
mapOf(
|
||||||
|
"KOTLIN_JS_LOCATION" to rootDir.resolve("dist/js/kotlin.js"),
|
||||||
|
"KOTLIN_JS_TEST_LOCATION" to rootDir.resolve("dist/js/kotlin-test.js")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
projectTest("wasmTest", true) {
|
projectTest("wasmTest", true) {
|
||||||
|
|||||||
@@ -68,7 +68,6 @@ 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 = 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,
|
||||||
@@ -76,6 +75,7 @@ abstract class BasicBoxTest(
|
|||||||
) : KotlinTestWithEnvironment() {
|
) : KotlinTestWithEnvironment() {
|
||||||
private val additionalCommonFileDirectories = mutableListOf<String>()
|
private val additionalCommonFileDirectories = mutableListOf<String>()
|
||||||
|
|
||||||
|
val pathToRootOutputDir = System.getProperty("kotlin.js.test.root.out.dir") ?: error("'kotlin.js.test.root.out.dir' is not set")
|
||||||
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)
|
||||||
private val testGroupOutputDirForPir = File(pathToRootOutputDir + "out-pir/" + testGroupOutputDirPrefix)
|
private val testGroupOutputDirForPir = File(pathToRootOutputDir + "out-pir/" + testGroupOutputDirPrefix)
|
||||||
@@ -116,7 +116,10 @@ abstract class BasicBoxTest(
|
|||||||
val needsFullIrRuntime = KJS_WITH_FULL_RUNTIME.matcher(fileContent).find() || WITH_RUNTIME.matcher(fileContent).find()
|
val needsFullIrRuntime = KJS_WITH_FULL_RUNTIME.matcher(fileContent).find() || WITH_RUNTIME.matcher(fileContent).find()
|
||||||
|
|
||||||
|
|
||||||
val actualMainCallParameters = if (CALL_MAIN_PATTERN.matcher(fileContent).find()) MainCallParameters.mainWithArguments(listOf("testArg")) else mainCallParameters
|
val actualMainCallParameters = if (CALL_MAIN_PATTERN.matcher(fileContent).find())
|
||||||
|
MainCallParameters.mainWithArguments(listOf("testArg"))
|
||||||
|
else
|
||||||
|
mainCallParameters
|
||||||
|
|
||||||
val outputPrefixFile = getOutputPrefixFile(filePath)
|
val outputPrefixFile = getOutputPrefixFile(filePath)
|
||||||
val outputPostfixFile = getOutputPostfixFile(filePath)
|
val outputPostfixFile = getOutputPostfixFile(filePath)
|
||||||
@@ -246,16 +249,26 @@ abstract class BasicBoxTest(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val allJsFiles = additionalFiles + inputJsFiles + generatedJsFiles.map { it.first } + globalCommonFiles + localCommonFiles +
|
val allJsFiles = additionalFiles + inputJsFiles + generatedJsFiles.map { it.first } + globalCommonFiles + localCommonFiles +
|
||||||
additionalCommonFiles + additionalMainFiles
|
additionalCommonFiles + additionalMainFiles
|
||||||
|
|
||||||
val dceAllJsFiles = additionalFiles + inputJsFiles + generatedJsFiles.map { it.first.replace(outputDir.absolutePath, dceOutputDir.absolutePath) } +
|
val dceAllJsFiles = additionalFiles + inputJsFiles + generatedJsFiles.map {
|
||||||
globalCommonFiles + localCommonFiles + additionalCommonFiles + additionalMainFiles
|
it.first.replace(
|
||||||
|
outputDir.absolutePath,
|
||||||
|
dceOutputDir.absolutePath
|
||||||
|
)
|
||||||
|
} + globalCommonFiles + localCommonFiles + additionalCommonFiles + additionalMainFiles
|
||||||
|
|
||||||
val pirAllJsFiles = additionalFiles + inputJsFiles + generatedJsFiles.map { it.first.replace(outputDir.absolutePath, pirOutputDir.absolutePath) } +
|
val pirAllJsFiles = additionalFiles + inputJsFiles + generatedJsFiles.map {
|
||||||
|
it.first.replace(
|
||||||
|
outputDir.absolutePath,
|
||||||
|
pirOutputDir.absolutePath
|
||||||
|
)
|
||||||
|
} +
|
||||||
globalCommonFiles + localCommonFiles + additionalCommonFiles + additionalMainFiles
|
globalCommonFiles + localCommonFiles + additionalCommonFiles + additionalMainFiles
|
||||||
|
|
||||||
|
|
||||||
val dontRunGeneratedCode = InTextDirectivesUtils.dontRunGeneratedCode(targetBackend, file)
|
val dontRunGeneratedCode =
|
||||||
|
InTextDirectivesUtils.dontRunGeneratedCode(targetBackend, file)
|
||||||
|
|
||||||
if (!dontRunGeneratedCode && generateNodeJsRunner && !SKIP_NODE_JS.matcher(fileContent).find()) {
|
if (!dontRunGeneratedCode && generateNodeJsRunner && !SKIP_NODE_JS.matcher(fileContent).find()) {
|
||||||
val nodeRunnerName = mainModule.outputFileName(outputDir) + ".node.js"
|
val nodeRunnerName = mainModule.outputFileName(outputDir) + ".node.js"
|
||||||
@@ -306,7 +319,8 @@ abstract class BasicBoxTest(
|
|||||||
testPackage = testPackage,
|
testPackage = testPackage,
|
||||||
testFunction = testFunction,
|
testFunction = testFunction,
|
||||||
withModuleSystem = withModuleSystem,
|
withModuleSystem = withModuleSystem,
|
||||||
minificationThresholdChecker = thresholdChecker)
|
minificationThresholdChecker = thresholdChecker
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -369,11 +383,11 @@ abstract class BasicBoxTest(
|
|||||||
protected open fun performAdditionalChecks(inputFile: File, outputFile: File) {}
|
protected open fun performAdditionalChecks(inputFile: File, outputFile: File) {}
|
||||||
|
|
||||||
private fun generateNodeRunner(
|
private fun generateNodeRunner(
|
||||||
files: Collection<String>,
|
files: Collection<String>,
|
||||||
dir: File,
|
dir: File,
|
||||||
moduleName: String,
|
moduleName: String,
|
||||||
ignored: Boolean,
|
ignored: Boolean,
|
||||||
testPackage: String?
|
testPackage: String?
|
||||||
): String {
|
): String {
|
||||||
val filesToLoad = files.map { FileUtil.getRelativePath(dir, File(it))!!.replace(File.separatorChar, '/') }.map { "\"$it\"" }
|
val filesToLoad = files.map { FileUtil.getRelativePath(dir, File(it))!!.replace(File.separatorChar, '/') }.map { "\"$it\"" }
|
||||||
val fqn = testPackage?.let { ".$it" } ?: ""
|
val fqn = testPackage?.let { ".$it" } ?: ""
|
||||||
@@ -390,8 +404,7 @@ abstract class BasicBoxTest(
|
|||||||
sb.append(" catch (e) {\n")
|
sb.append(" catch (e) {\n")
|
||||||
sb.append(" return 'OK';\n")
|
sb.append(" return 'OK';\n")
|
||||||
sb.append("}\n")
|
sb.append("}\n")
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
sb.append(" return $loadAndRun;\n")
|
sb.append(" return $loadAndRun;\n")
|
||||||
}
|
}
|
||||||
sb.append("};\n")
|
sb.append("};\n")
|
||||||
@@ -402,10 +415,10 @@ abstract class BasicBoxTest(
|
|||||||
protected fun getOutputDir(file: File, testGroupOutputDir: File = testGroupOutputDirForCompilation): File {
|
protected fun getOutputDir(file: File, testGroupOutputDir: File = testGroupOutputDirForCompilation): File {
|
||||||
val stopFile = File(pathToTestDir)
|
val stopFile = File(pathToTestDir)
|
||||||
return generateSequence(file.parentFile) { it.parentFile }
|
return generateSequence(file.parentFile) { it.parentFile }
|
||||||
.takeWhile { it != stopFile }
|
.takeWhile { it != stopFile }
|
||||||
.map { it.name }
|
.map { it.name }
|
||||||
.toList().asReversed()
|
.toList().asReversed()
|
||||||
.fold(testGroupOutputDir, ::File)
|
.fold(testGroupOutputDir, ::File)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun TestModule.outputFileSimpleName(): String {
|
private fun TestModule.outputFileSimpleName(): String {
|
||||||
@@ -440,7 +453,7 @@ abstract class BasicBoxTest(
|
|||||||
errorIgnorancePolicy: ErrorTolerancePolicy,
|
errorIgnorancePolicy: ErrorTolerancePolicy,
|
||||||
propertyLazyInitialization: Boolean,
|
propertyLazyInitialization: Boolean,
|
||||||
) {
|
) {
|
||||||
val kotlinFiles = module.files.filter { it.fileName.endsWith(".kt") }
|
val kotlinFiles = module.files.filter { it.fileName.endsWith(".kt") }
|
||||||
val testFiles = kotlinFiles.map { it.fileName }
|
val testFiles = kotlinFiles.map { it.fileName }
|
||||||
val globalCommonFiles = JsTestUtils.getFilesInDirectoryByExtension(COMMON_FILES_DIR_PATH, KotlinFileType.EXTENSION)
|
val globalCommonFiles = JsTestUtils.getFilesInDirectoryByExtension(COMMON_FILES_DIR_PATH, KotlinFileType.EXTENSION)
|
||||||
val localCommonFile = directory + "/" + COMMON_FILES_NAME + "." + KotlinFileType.EXTENSION
|
val localCommonFile = directory + "/" + COMMON_FILES_NAME + "." + KotlinFileType.EXTENSION
|
||||||
@@ -464,7 +477,7 @@ abstract class BasicBoxTest(
|
|||||||
tmpDir,
|
tmpDir,
|
||||||
incrementalData = null,
|
incrementalData = null,
|
||||||
expectActualLinker = expectActualLinker,
|
expectActualLinker = expectActualLinker,
|
||||||
errorIgnorancePolicy,
|
errorIgnorancePolicy
|
||||||
)
|
)
|
||||||
val outputFile = File(outputFileName)
|
val outputFile = File(outputFileName)
|
||||||
val dceOutputFile = File(dceOutputFileName)
|
val dceOutputFile = File(dceOutputFileName)
|
||||||
@@ -493,8 +506,24 @@ abstract class BasicBoxTest(
|
|||||||
|
|
||||||
if (incrementalCompilationChecksEnabled && module.hasFilesToRecompile) {
|
if (incrementalCompilationChecksEnabled && module.hasFilesToRecompile) {
|
||||||
checkIncrementalCompilation(
|
checkIncrementalCompilation(
|
||||||
sourceDirs, module, kotlinFiles, dependencies, allDependencies, friends, multiModule, tmpDir, remap,
|
sourceDirs,
|
||||||
outputFile, outputPrefixFile, outputPostfixFile, mainCallParameters, incrementalData, testPackage, testFunction, needsFullIrRuntime, expectActualLinker
|
module,
|
||||||
|
kotlinFiles,
|
||||||
|
dependencies,
|
||||||
|
allDependencies,
|
||||||
|
friends,
|
||||||
|
multiModule,
|
||||||
|
tmpDir,
|
||||||
|
remap,
|
||||||
|
outputFile,
|
||||||
|
outputPrefixFile,
|
||||||
|
outputPostfixFile,
|
||||||
|
mainCallParameters,
|
||||||
|
incrementalData,
|
||||||
|
testPackage,
|
||||||
|
testFunction,
|
||||||
|
needsFullIrRuntime,
|
||||||
|
expectActualLinker
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -532,8 +561,8 @@ abstract class BasicBoxTest(
|
|||||||
sourceToTranslationUnit[sourceFile] = TranslationUnit.BinaryAst(data.binaryAst, data.inlineData)
|
sourceToTranslationUnit[sourceFile] = TranslationUnit.BinaryAst(data.binaryAst, data.inlineData)
|
||||||
}
|
}
|
||||||
val translationUnits = sourceToTranslationUnit.keys
|
val translationUnits = sourceToTranslationUnit.keys
|
||||||
.sortedBy { it.canonicalPath }
|
.sortedBy { it.canonicalPath }
|
||||||
.map { sourceToTranslationUnit[it]!! }
|
.map { sourceToTranslationUnit[it]!! }
|
||||||
|
|
||||||
val recompiledConfig = createConfig(
|
val recompiledConfig = createConfig(
|
||||||
sourceDirs,
|
sourceDirs,
|
||||||
@@ -545,16 +574,27 @@ abstract class BasicBoxTest(
|
|||||||
tmpDir,
|
tmpDir,
|
||||||
incrementalData,
|
incrementalData,
|
||||||
expectActualLinker,
|
expectActualLinker,
|
||||||
ErrorTolerancePolicy.DEFAULT,
|
ErrorTolerancePolicy.DEFAULT
|
||||||
)
|
)
|
||||||
val recompiledOutputFile = File(outputFile.parentFile, outputFile.nameWithoutExtension + "-recompiled.js")
|
val recompiledOutputFile = File(outputFile.parentFile, outputFile.nameWithoutExtension + "-recompiled.js")
|
||||||
|
|
||||||
translateFiles(
|
translateFiles(
|
||||||
translationUnits, recompiledOutputFile, recompiledOutputFile, recompiledOutputFile, recompiledConfig,
|
translationUnits,
|
||||||
outputPrefixFile, outputPostfixFile,
|
recompiledOutputFile,
|
||||||
mainCallParameters, incrementalData, remap, testPackage, testFunction, needsFullIrRuntime,
|
recompiledOutputFile,
|
||||||
isMainModule = false, skipDceDriven = true,
|
recompiledOutputFile,
|
||||||
splitPerModule = false,
|
recompiledConfig,
|
||||||
|
outputPrefixFile,
|
||||||
|
outputPostfixFile,
|
||||||
|
mainCallParameters,
|
||||||
|
incrementalData,
|
||||||
|
remap,
|
||||||
|
testPackage,
|
||||||
|
testFunction,
|
||||||
|
needsFullIrRuntime,
|
||||||
|
isMainModule = false,
|
||||||
|
skipDceDriven = true,
|
||||||
|
splitPerModule = false,
|
||||||
propertyLazyInitialization = false,
|
propertyLazyInitialization = false,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -564,7 +604,8 @@ abstract class BasicBoxTest(
|
|||||||
|
|
||||||
val originalSourceMap = FileUtil.loadFile(File(outputFile.parentFile, outputFile.name + ".map"))
|
val originalSourceMap = FileUtil.loadFile(File(outputFile.parentFile, outputFile.name + ".map"))
|
||||||
val recompiledSourceMap =
|
val recompiledSourceMap =
|
||||||
removeRecompiledSuffix(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)
|
||||||
@@ -580,10 +621,9 @@ abstract class BasicBoxTest(
|
|||||||
|
|
||||||
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 =
|
val recompiledMetadata = removeRecompiledSuffix(
|
||||||
removeRecompiledSuffix(
|
FileUtil.loadFile(File(recompiledOutputFile.parentFile, recompiledOutputFile.nameWithoutExtension + ".meta.js"))
|
||||||
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),
|
||||||
@@ -697,8 +737,8 @@ abstract class BasicBoxTest(
|
|||||||
|
|
||||||
private fun processJsProgram(program: JsProgram, psiFiles: List<KtFile>) {
|
private fun processJsProgram(program: JsProgram, psiFiles: List<KtFile>) {
|
||||||
psiFiles.asSequence()
|
psiFiles.asSequence()
|
||||||
.map { it.text }
|
.map { it.text }
|
||||||
.forEach { DirectiveTestUtils.processDirectives(program, it) }
|
.forEach { DirectiveTestUtils.processDirectives(program, it) }
|
||||||
program.verifyAst()
|
program.verifyAst()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -710,6 +750,7 @@ abstract class BasicBoxTest(
|
|||||||
super.visitObjectLiteral(x)
|
super.visitObjectLiteral(x)
|
||||||
x.isMultiline = false
|
x.isMultiline = false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitVars(x: JsVars) {
|
override fun visitVars(x: JsVars) {
|
||||||
x.isMultiline = false
|
x.isMultiline = false
|
||||||
super.visitVars(x)
|
super.visitVars(x)
|
||||||
@@ -721,8 +762,11 @@ abstract class BasicBoxTest(
|
|||||||
val output = TextOutputImpl()
|
val output = TextOutputImpl()
|
||||||
val pathResolver = SourceFilePathResolver(mutableListOf(File(".")), null)
|
val pathResolver = SourceFilePathResolver(mutableListOf(File(".")), null)
|
||||||
val sourceMapBuilder = SourceMap3Builder(outputFile, output, "")
|
val sourceMapBuilder = SourceMap3Builder(outputFile, output, "")
|
||||||
generatedProgram.accept(JsToStringGenerationVisitor(
|
generatedProgram.accept(
|
||||||
output, SourceMapBuilderConsumer(File("."), sourceMapBuilder, pathResolver, false, false)))
|
JsToStringGenerationVisitor(
|
||||||
|
output, SourceMapBuilderConsumer(File("."), sourceMapBuilder, pathResolver, false, false)
|
||||||
|
)
|
||||||
|
)
|
||||||
val code = output.toString()
|
val code = output.toString()
|
||||||
val generatedSourceMap = sourceMapBuilder.build()
|
val generatedSourceMap = sourceMapBuilder.build()
|
||||||
|
|
||||||
@@ -813,7 +857,13 @@ abstract class BasicBoxTest(
|
|||||||
if (header != null) {
|
if (header != null) {
|
||||||
configuration.put(
|
configuration.put(
|
||||||
JSConfigurationKeys.INCREMENTAL_DATA_PROVIDER,
|
JSConfigurationKeys.INCREMENTAL_DATA_PROVIDER,
|
||||||
IncrementalDataProviderImpl(header, incrementalData.translatedFiles, JsMetadataVersion.INSTANCE.toArray(), incrementalData.packageMetadata, emptyMap())
|
IncrementalDataProviderImpl(
|
||||||
|
header,
|
||||||
|
incrementalData.translatedFiles,
|
||||||
|
JsMetadataVersion.INSTANCE.toArray(),
|
||||||
|
incrementalData.packageMetadata,
|
||||||
|
emptyMap()
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -841,9 +891,9 @@ abstract class BasicBoxTest(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun minifyAndRun(
|
private fun minifyAndRun(
|
||||||
workDir: File, allJsFiles: List<String>, generatedJsFiles: List<Pair<String, TestModule>>,
|
workDir: File, allJsFiles: List<String>, generatedJsFiles: List<Pair<String, TestModule>>,
|
||||||
expectedResult: String, testModuleName: String?, testPackage: String?, testFunction: String, withModuleSystem: Boolean,
|
expectedResult: String, testModuleName: String?, testPackage: String?, testFunction: String, withModuleSystem: Boolean,
|
||||||
minificationThresholdChecker: (Int) -> Unit
|
minificationThresholdChecker: (Int) -> Unit
|
||||||
) {
|
) {
|
||||||
val kotlinJsLib = DIST_DIR_JS_PATH + "kotlin.js"
|
val kotlinJsLib = DIST_DIR_JS_PATH + "kotlin.js"
|
||||||
val kotlinTestJsLib = DIST_DIR_JS_PATH + "kotlin-test.js"
|
val kotlinTestJsLib = DIST_DIR_JS_PATH + "kotlin-test.js"
|
||||||
@@ -860,9 +910,9 @@ abstract class BasicBoxTest(
|
|||||||
|
|
||||||
val testFunctionFqn = testModuleName + (if (testPackage.isNullOrEmpty()) "" else ".$testPackage") + ".$testFunction"
|
val testFunctionFqn = testModuleName + (if (testPackage.isNullOrEmpty()) "" else ".$testPackage") + ".$testFunction"
|
||||||
val additionalReachableNodes = setOf(
|
val additionalReachableNodes = setOf(
|
||||||
testFunctionFqn, "kotlin.kotlin.io.BufferedOutput", "kotlin.kotlin.io.output.flush",
|
testFunctionFqn, "kotlin.kotlin.io.BufferedOutput", "kotlin.kotlin.io.output.flush",
|
||||||
"kotlin.kotlin.io.output.buffer", "kotlin-test.kotlin.test.overrideAsserter_wbnzx$",
|
"kotlin.kotlin.io.output.buffer", "kotlin-test.kotlin.test.overrideAsserter_wbnzx$",
|
||||||
"kotlin-test.kotlin.test.DefaultAsserter"
|
"kotlin-test.kotlin.test.DefaultAsserter"
|
||||||
)
|
)
|
||||||
val allFilesToMinify = filesToMinify.values + kotlinJsInputFile + kotlinTestJsInputFile
|
val allFilesToMinify = filesToMinify.values + kotlinJsInputFile + kotlinTestJsInputFile
|
||||||
val dceResult = DeadCodeElimination.run(allFilesToMinify, additionalReachableNodes) { _, _ -> }
|
val dceResult = DeadCodeElimination.run(allFilesToMinify, additionalReachableNodes) { _, _ -> }
|
||||||
@@ -895,7 +945,7 @@ abstract class BasicBoxTest(
|
|||||||
val currentModule = module ?: defaultModule
|
val currentModule = module ?: defaultModule
|
||||||
|
|
||||||
val ktFile = KtPsiFactory(project).createFile(text)
|
val ktFile = KtPsiFactory(project).createFile(text)
|
||||||
val boxFunction = ktFile.declarations.find { it is KtNamedFunction && it.name == TEST_FUNCTION }
|
val boxFunction = ktFile.declarations.find { it is KtNamedFunction && it.name == TEST_FUNCTION }
|
||||||
if (boxFunction != null) {
|
if (boxFunction != null) {
|
||||||
testPackage = ktFile.packageFqName.asString()
|
testPackage = ktFile.packageFqName.asString()
|
||||||
if (testPackage?.isEmpty() == true) {
|
if (testPackage?.isEmpty() == true) {
|
||||||
@@ -962,7 +1012,7 @@ abstract class BasicBoxTest(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun createModule(name: String, dependencies: List<String>, friends: List<String>) =
|
override fun createModule(name: String, dependencies: List<String>, friends: List<String>) =
|
||||||
TestModule(name, dependencies, friends)
|
TestModule(name, dependencies, friends)
|
||||||
|
|
||||||
override fun close() {
|
override fun close() {
|
||||||
FileUtil.delete(tmpDir)
|
FileUtil.delete(tmpDir)
|
||||||
@@ -976,10 +1026,10 @@ abstract class BasicBoxTest(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class TestModule(
|
private class TestModule(
|
||||||
name: String,
|
name: String,
|
||||||
dependencies: List<String>,
|
dependencies: List<String>,
|
||||||
friends: List<String>
|
friends: List<String>
|
||||||
): KotlinBaseTest.TestModule(name, dependencies, friends) {
|
) : KotlinBaseTest.TestModule(name, dependencies, friends) {
|
||||||
var moduleKind = ModuleKind.PLAIN
|
var moduleKind = ModuleKind.PLAIN
|
||||||
var inliningDisabled = false
|
var inliningDisabled = false
|
||||||
val files = mutableListOf<TestFile>()
|
val files = mutableListOf<TestFile>()
|
||||||
@@ -990,7 +1040,7 @@ abstract class BasicBoxTest(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun createEnvironment() =
|
override fun createEnvironment() =
|
||||||
KotlinCoreEnvironment.createForTests(testRootDisposable, CompilerConfiguration(), EnvironmentConfigFiles.JS_CONFIG_FILES)
|
KotlinCoreEnvironment.createForTests(testRootDisposable, CompilerConfiguration(), EnvironmentConfigFiles.JS_CONFIG_FILES)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val METADATA_CACHE = (JsConfig.JS_STDLIB + JsConfig.JS_KOTLIN_TEST).flatMap { path ->
|
val METADATA_CACHE = (JsConfig.JS_STDLIB + JsConfig.JS_KOTLIN_TEST).flatMap { path ->
|
||||||
|
|||||||
@@ -30,14 +30,12 @@ private val kotlinTestKLib = System.getProperty("kotlin.js.kotlin.test.path")
|
|||||||
abstract class BasicIrBoxTest(
|
abstract class BasicIrBoxTest(
|
||||||
pathToTestDir: String,
|
pathToTestDir: String,
|
||||||
testGroupOutputDirPrefix: String,
|
testGroupOutputDirPrefix: String,
|
||||||
pathToRootOutputDir: String = TEST_DATA_DIR_PATH,
|
|
||||||
generateSourceMap: Boolean = false,
|
generateSourceMap: Boolean = false,
|
||||||
generateNodeJsRunner: Boolean = false,
|
generateNodeJsRunner: Boolean = false,
|
||||||
targetBackend: TargetBackend = TargetBackend.JS_IR
|
targetBackend: TargetBackend = TargetBackend.JS_IR
|
||||||
) : BasicBoxTest(
|
) : BasicBoxTest(
|
||||||
pathToTestDir,
|
pathToTestDir,
|
||||||
testGroupOutputDirPrefix,
|
testGroupOutputDirPrefix,
|
||||||
pathToRootOutputDir = pathToRootOutputDir,
|
|
||||||
typedArraysEnabled = true,
|
typedArraysEnabled = true,
|
||||||
generateSourceMap = generateSourceMap,
|
generateSourceMap = generateSourceMap,
|
||||||
generateNodeJsRunner = generateNodeJsRunner,
|
generateNodeJsRunner = generateNodeJsRunner,
|
||||||
|
|||||||
-1
@@ -18,7 +18,6 @@ abstract class AbstractIrJsTypeScriptExportTest(
|
|||||||
) : BasicIrBoxTest(
|
) : BasicIrBoxTest(
|
||||||
pathToTestDir = TEST_DATA_DIR_PATH + "typescript-export/",
|
pathToTestDir = TEST_DATA_DIR_PATH + "typescript-export/",
|
||||||
testGroupOutputDirPrefix = "typescript-export/",
|
testGroupOutputDirPrefix = "typescript-export/",
|
||||||
pathToRootOutputDir = TEST_DATA_DIR_PATH,
|
|
||||||
targetBackend = targetBackend
|
targetBackend = targetBackend
|
||||||
) {
|
) {
|
||||||
override val generateDts = true
|
override val generateDts = true
|
||||||
|
|||||||
+1
-2
@@ -9,6 +9,5 @@ import org.jetbrains.kotlin.js.test.BasicBoxTest
|
|||||||
|
|
||||||
abstract class AbstractLegacyJsTypeScriptExportTest : BasicBoxTest(
|
abstract class AbstractLegacyJsTypeScriptExportTest : BasicBoxTest(
|
||||||
pathToTestDir = TEST_DATA_DIR_PATH + "typescript-export/",
|
pathToTestDir = TEST_DATA_DIR_PATH + "typescript-export/",
|
||||||
testGroupOutputDirPrefix = "legacy-typescript-export/",
|
testGroupOutputDirPrefix = "legacy-typescript-export/"
|
||||||
pathToRootOutputDir = TEST_DATA_DIR_PATH
|
|
||||||
)
|
)
|
||||||
Reference in New Issue
Block a user