Run JS box tests for JS IR BE

This commit is contained in:
Zalim Bashorov
2018-03-12 22:27:45 +03:00
parent bef7b5389b
commit 4404c6dd2c
8 changed files with 15946 additions and 106 deletions
@@ -8,5 +8,5 @@ package org.jetbrains.kotlin.test
import java.io.File import java.io.File
val JS_IR_BACKEND_TEST_WHITELIST = listOf( val JS_IR_BACKEND_TEST_WHITELIST = listOf(
"js/js.translator/testData/box/annotation" "js/js.translator/testData/box/package/nestedPackage.kt"
).map { File(it) } ).map { File(it) }
@@ -1,17 +1,6 @@
/* /*
* Copyright 2010-2017 JetBrains s.r.o. * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* * that can be found in the license/LICENSE.txt file.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package org.jetbrains.kotlin.generators.tests package org.jetbrains.kotlin.generators.tests
@@ -33,6 +22,10 @@ fun main(args: Array<String>) {
model("box/", pattern = "^([^_](.+))\\.kt$", targetBackend = TargetBackend.JS) model("box/", pattern = "^([^_](.+))\\.kt$", targetBackend = TargetBackend.JS)
} }
testClass<AbstractIrBoxJsTest> {
model("box/", pattern = "^([^_](.+))\\.kt$", targetBackend = TargetBackend.JS_IR)
}
testClass<AbstractSourceMapGenerationSmokeTest> { testClass<AbstractSourceMapGenerationSmokeTest> {
model("sourcemap/", pattern = "^([^_](.+))\\.kt$", targetBackend = TargetBackend.JS) model("sourcemap/", pattern = "^([^_](.+))\\.kt$", targetBackend = TargetBackend.JS)
} }
@@ -1,17 +1,6 @@
/* /*
* Copyright 2010-2017 JetBrains s.r.o. * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* * that can be found in the license/LICENSE.txt file.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package org.jetbrains.kotlin.js.test package org.jetbrains.kotlin.js.test
@@ -93,6 +82,7 @@ abstract class BasicBoxTest(
protected open fun getOutputPostfixFile(testFilePath: String): File? = null protected open fun getOutputPostfixFile(testFilePath: String): File? = null
protected open val runMinifierByDefault: Boolean = false protected open val runMinifierByDefault: Boolean = false
protected open val skipMinification = System.getProperty("kotlin.js.skipMinificationTest", "false")!!.toBoolean()
fun doTest(filePath: String) { fun doTest(filePath: String) {
doTest(filePath, "OK", MainCallParameters.noCall()) doTest(filePath, "OK", MainCallParameters.noCall())
@@ -114,14 +104,19 @@ abstract class BasicBoxTest(
val orderedModules = DFS.topologicalOrder(modules.values) { module -> module.dependencies.mapNotNull { modules[it] } } val orderedModules = DFS.topologicalOrder(modules.values) { module -> module.dependencies.mapNotNull { modules[it] } }
val testPackage = testFactory.testPackage
val testFunction = TEST_FUNCTION
val generatedJsFiles = orderedModules.asReversed().mapNotNull { module -> val generatedJsFiles = orderedModules.asReversed().mapNotNull { module ->
val dependencies = module.dependencies.map { modules[it]?.outputFileName(outputDir) + ".meta.js" } val dependencies = module.dependencies.map { modules[it]?.outputFileName(outputDir) + ".meta.js" }
val friends = module.friends.map { modules[it]?.outputFileName(outputDir) + ".meta.js" } val friends = module.friends.map { modules[it]?.outputFileName(outputDir) + ".meta.js" }
val outputFileName = module.outputFileName(outputDir) + ".js" val outputFileName = module.outputFileName(outputDir) + ".js"
generateJavaScriptFile(file.parent, module, outputFileName, dependencies, friends, modules.size > 1, generateJavaScriptFile(
!SKIP_SOURCEMAP_REMAPPING.matcher(fileContent).find(), file.parent, module, outputFileName, dependencies, friends, modules.size > 1,
outputPrefixFile, outputPostfixFile, mainCallParameters) !SKIP_SOURCEMAP_REMAPPING.matcher(fileContent).find(),
outputPrefixFile, outputPostfixFile, mainCallParameters, testPackage, testFunction
)
if (!module.name.endsWith(OLD_MODULE_SUFFIX)) Pair(outputFileName, module) else null if (!module.name.endsWith(OLD_MODULE_SUFFIX)) Pair(outputFileName, module) else null
} }
@@ -168,17 +163,17 @@ abstract class BasicBoxTest(
if (generateNodeJsRunner && !SKIP_NODE_JS.matcher(fileContent).find()) { if (generateNodeJsRunner && !SKIP_NODE_JS.matcher(fileContent).find()) {
val nodeRunnerName = mainModule.outputFileName(outputDir) + ".node.js" val nodeRunnerName = mainModule.outputFileName(outputDir) + ".node.js"
val ignored = InTextDirectivesUtils.isIgnoredTarget(TargetBackend.JS, file) val ignored = InTextDirectivesUtils.isIgnoredTarget(TargetBackend.JS, file)
val nodeRunnerText = generateNodeRunner(allJsFiles, outputDir, mainModuleName, ignored, testFactory.testPackage) val nodeRunnerText = generateNodeRunner(allJsFiles, outputDir, mainModuleName, ignored, testPackage)
FileUtil.writeToFile(File(nodeRunnerName), nodeRunnerText) FileUtil.writeToFile(File(nodeRunnerName), nodeRunnerText)
} }
runGeneratedCode(allJsFiles, mainModuleName, testFactory.testPackage, TEST_FUNCTION, expectedResult, withModuleSystem) runGeneratedCode(allJsFiles, mainModuleName, testPackage, testFunction, expectedResult, withModuleSystem)
performAdditionalChecks(generatedJsFiles.map { it.first }, outputPrefixFile, outputPostfixFile) performAdditionalChecks(generatedJsFiles.map { it.first }, outputPrefixFile, outputPostfixFile)
val expectedReachableNodesMatcher = EXPECTED_REACHABLE_NODES.matcher(fileContent) val expectedReachableNodesMatcher = EXPECTED_REACHABLE_NODES.matcher(fileContent)
val expectedReachableNodesFound = expectedReachableNodesMatcher.find() val expectedReachableNodesFound = expectedReachableNodesMatcher.find()
val skipMinification = System.getProperty("kotlin.js.skipMinificationTest", "false").toBoolean()
if (!skipMinification && if (!skipMinification &&
(runMinifierByDefault || expectedReachableNodesFound) && (runMinifierByDefault || expectedReachableNodesFound) &&
!SKIP_MINIFICATION.matcher(fileContent).find() !SKIP_MINIFICATION.matcher(fileContent).find()
@@ -207,22 +202,22 @@ abstract class BasicBoxTest(
val outputDirForMinification = getOutputDir(file, testGroupOutputDirForMinification) val outputDirForMinification = getOutputDir(file, testGroupOutputDirForMinification)
minifyAndRun( minifyAndRun(
workDir = File(outputDirForMinification, file.nameWithoutExtension), workDir = File(outputDirForMinification, file.nameWithoutExtension),
allJsFiles = allJsFiles, allJsFiles = allJsFiles,
generatedJsFiles = generatedJsFiles, generatedJsFiles = generatedJsFiles,
expectedResult = expectedResult, expectedResult = expectedResult,
testModuleName = mainModuleName, testModuleName = mainModuleName,
testPackage = testFactory.testPackage, testPackage = testPackage,
testFunction = TEST_FUNCTION, testFunction = testFunction,
withModuleSystem = withModuleSystem, withModuleSystem = withModuleSystem,
minificationThresholdChecker = thresholdChecker) minificationThresholdChecker = thresholdChecker)
} }
} }
} }
protected open fun runGeneratedCode( protected open fun runGeneratedCode(
jsFiles: List<String>, jsFiles: List<String>,
testModuleName: String, testModuleName: String?,
testPackage: String?, testPackage: String?,
testFunction: String, testFunction: String,
expectedResult: String, expectedResult: String,
@@ -290,7 +285,9 @@ abstract class BasicBoxTest(
remap: Boolean, remap: Boolean,
outputPrefixFile: File?, outputPrefixFile: File?,
outputPostfixFile: File?, outputPostfixFile: File?,
mainCallParameters: MainCallParameters mainCallParameters: MainCallParameters,
testPackage: String?,
testFunction: String
) { ) {
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 }
@@ -310,12 +307,16 @@ abstract class BasicBoxTest(
val outputFile = File(outputFileName) val outputFile = File(outputFileName)
val incrementalData = IncrementalData() val incrementalData = IncrementalData()
translateFiles(psiFiles.map(TranslationUnit::SourceFile), outputFile, config, outputPrefixFile, outputPostfixFile, translateFiles(
mainCallParameters, incrementalData, remap) psiFiles.map(TranslationUnit::SourceFile), outputFile, config, outputPrefixFile, outputPostfixFile,
mainCallParameters, incrementalData, remap, testPackage, testFunction
)
if (module.hasFilesToRecompile) { if (module.hasFilesToRecompile) {
checkIncrementalCompilation(sourceDirs, module, kotlinFiles, dependencies, friends, multiModule, remap, checkIncrementalCompilation(
outputFile, outputPrefixFile, outputPostfixFile, mainCallParameters, incrementalData) sourceDirs, module, kotlinFiles, dependencies, friends, multiModule, remap,
outputFile, outputPrefixFile, outputPostfixFile, mainCallParameters, incrementalData, testPackage, testFunction
)
} }
} }
@@ -331,7 +332,9 @@ abstract class BasicBoxTest(
outputPrefixFile: File?, outputPrefixFile: File?,
outputPostfixFile: File?, outputPostfixFile: File?,
mainCallParameters: MainCallParameters, mainCallParameters: MainCallParameters,
incrementalData: IncrementalData incrementalData: IncrementalData,
testPackage: String?,
testFunction: String
) { ) {
val sourceToTranslationUnit = hashMapOf<File, TranslationUnit>() val sourceToTranslationUnit = hashMapOf<File, TranslationUnit>()
for (testFile in kotlinFiles) { for (testFile in kotlinFiles) {
@@ -351,8 +354,10 @@ abstract class BasicBoxTest(
val recompiledConfig = createConfig(sourceDirs, module, dependencies, friends, multiModule, incrementalData) val recompiledConfig = createConfig(sourceDirs, module, dependencies, friends, multiModule, incrementalData)
val recompiledOutputFile = File(outputFile.parentFile, outputFile.nameWithoutExtension + "-recompiled.js") val recompiledOutputFile = File(outputFile.parentFile, outputFile.nameWithoutExtension + "-recompiled.js")
translateFiles(translationUnits, recompiledOutputFile, recompiledConfig, outputPrefixFile, outputPostfixFile, translateFiles(
mainCallParameters, incrementalData, remap) translationUnits, recompiledOutputFile, recompiledConfig, outputPrefixFile, outputPostfixFile,
mainCallParameters, incrementalData, remap, testPackage, testFunction
)
val originalOutput = FileUtil.loadFile(outputFile) val originalOutput = FileUtil.loadFile(outputFile)
val recompiledOutput = removeRecompiledSuffix(FileUtil.loadFile(recompiledOutputFile)) val recompiledOutput = removeRecompiledSuffix(FileUtil.loadFile(recompiledOutputFile))
@@ -402,15 +407,17 @@ abstract class BasicBoxTest(
class IncrementalData(var header: ByteArray? = null, val translatedFiles: MutableMap<File, TranslationResultValue> = hashMapOf()) class IncrementalData(var header: ByteArray? = null, val translatedFiles: MutableMap<File, TranslationResultValue> = hashMapOf())
private fun translateFiles( protected open fun translateFiles(
units: List<TranslationUnit>, units: List<TranslationUnit>,
outputFile: File, outputFile: File,
config: JsConfig, config: JsConfig,
outputPrefixFile: File?, outputPrefixFile: File?,
outputPostfixFile: File?, outputPostfixFile: File?,
mainCallParameters: MainCallParameters, mainCallParameters: MainCallParameters,
incrementalData: IncrementalData, incrementalData: IncrementalData,
remap: Boolean remap: Boolean,
testPackage: String?,
testFunction: String
) { ) {
val translator = K2JSTranslator(config) val translator = K2JSTranslator(config)
val translationResult = translator.translateUnits(ExceptionThrowingReporter, units, mainCallParameters) val translationResult = translator.translateUnits(ExceptionThrowingReporter, units, mainCallParameters)
@@ -0,0 +1,53 @@
/*
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.js.test
import org.jetbrains.kotlin.ir.backend.js.compile
import org.jetbrains.kotlin.js.config.JsConfig
import org.jetbrains.kotlin.js.facade.MainCallParameters
import org.jetbrains.kotlin.js.facade.TranslationUnit
import java.io.File
abstract class BasicIrBoxTest(
pathToTestDir: String,
testGroupOutputDirPrefix: String,
pathToRootOutputDir: String = BasicBoxTest.TEST_DATA_DIR_PATH,
generateSourceMap: Boolean = false,
generateNodeJsRunner: Boolean = false
) : BasicBoxTest(pathToTestDir, testGroupOutputDirPrefix, pathToRootOutputDir, generateSourceMap, generateNodeJsRunner) {
override var skipMinification = true
override fun translateFiles(
units: List<TranslationUnit>,
outputFile: File,
config: JsConfig,
outputPrefixFile: File?,
outputPostfixFile: File?,
mainCallParameters: MainCallParameters,
incrementalData: IncrementalData,
remap: Boolean,
testPackage: String?,
testFunction: String
) {
val code = compile(units.map { (it as TranslationUnit.SourceFile).file })
outputFile.parentFile.mkdirs()
outputFile.writeText(code)
}
override fun runGeneratedCode(
jsFiles: List<String>,
testModuleName: String?,
testPackage: String?,
testFunction: String,
expectedResult: String,
withModuleSystem: Boolean
) {
// TODO: should we do anything special for module systems?
super.runGeneratedCode(jsFiles, null, null, testFunction, expectedResult, false)
}
}
@@ -1,17 +1,6 @@
/* /*
* Copyright 2010-2017 JetBrains s.r.o. * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* * that can be found in the license/LICENSE.txt file.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package org.jetbrains.kotlin.js.test package org.jetbrains.kotlin.js.test
@@ -32,13 +21,17 @@ fun ScriptEngine.overrideAsserter() {
} }
fun ScriptEngine.runTestFunction( fun ScriptEngine.runTestFunction(
testModuleName: String, testPackageName: String?, testFunctionName: String, testModuleName: String?,
withModuleSystem: Boolean testPackageName: String?,
testFunctionName: String,
withModuleSystem: Boolean
): Any? { ): Any? {
val testModule = val testModule =
when { when {
withModuleSystem -> withModuleSystem ->
eval(BasicBoxTest.Companion.KOTLIN_TEST_INTERNAL + ".require('" + testModuleName + "')") eval(BasicBoxTest.Companion.KOTLIN_TEST_INTERNAL + ".require('" + testModuleName!! + "')")
testModuleName == null ->
eval("this")
else -> else ->
get(testModuleName) get(testModuleName)
} }
@@ -90,7 +83,7 @@ object NashornJsTestChecker {
fun check( fun check(
files: List<String>, files: List<String>,
testModuleName: String, testModuleName: String?,
testPackageName: String?, testPackageName: String?,
testFunctionName: String, testFunctionName: String,
expectedResult: String, expectedResult: String,
@@ -112,7 +105,7 @@ object NashornJsTestChecker {
private fun run( private fun run(
files: List<String>, files: List<String>,
testModuleName: String, testModuleName: String?,
testPackageName: String?, testPackageName: String?,
testFunctionName: String, testFunctionName: String,
withModuleSystem: Boolean withModuleSystem: Boolean
@@ -1,17 +1,6 @@
/* /*
* Copyright 2010-2017 JetBrains s.r.o. * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* * that can be found in the license/LICENSE.txt file.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package org.jetbrains.kotlin.js.test.semantics package org.jetbrains.kotlin.js.test.semantics
@@ -31,7 +20,7 @@ abstract class AbstractWebDemoExamplesTest(relativePath: String) : BasicBoxTest(
) { ) {
override fun runGeneratedCode( override fun runGeneratedCode(
jsFiles: List<String>, jsFiles: List<String>,
testModuleName: String, testModuleName: String?,
testPackage: String?, testPackage: String?,
testFunction: String, testFunction: String,
expectedResult: String, expectedResult: String,
File diff suppressed because it is too large Load Diff
@@ -1,22 +1,12 @@
/* /*
* Copyright 2010-2016 JetBrains s.r.o. * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* * that can be found in the license/LICENSE.txt file.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package org.jetbrains.kotlin.js.test.semantics package org.jetbrains.kotlin.js.test.semantics
import org.jetbrains.kotlin.js.test.BasicBoxTest import org.jetbrains.kotlin.js.test.BasicBoxTest
import org.jetbrains.kotlin.js.test.BasicIrBoxTest
abstract class BorrowedInlineTest(relativePath: String) : BasicBoxTest( abstract class BorrowedInlineTest(relativePath: String) : BasicBoxTest(
"compiler/testData/codegen/boxInline/$relativePath", "compiler/testData/codegen/boxInline/$relativePath",
@@ -57,3 +47,5 @@ abstract class AbstractSourceMapGenerationSmokeTest : BasicBoxTest(
generateSourceMap = true, generateSourceMap = true,
generateNodeJsRunner = false generateNodeJsRunner = false
) )
abstract class AbstractIrBoxJsTest : BasicIrBoxTest(BasicBoxTest.TEST_DATA_DIR_PATH + "box/", "irBox/")