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
val JS_IR_BACKEND_TEST_WHITELIST = listOf(
"js/js.translator/testData/box/annotation"
"js/js.translator/testData/box/package/nestedPackage.kt"
).map { File(it) }
@@ -1,17 +1,6 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* 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.
* 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.
*/
package org.jetbrains.kotlin.generators.tests
@@ -33,6 +22,10 @@ fun main(args: Array<String>) {
model("box/", pattern = "^([^_](.+))\\.kt$", targetBackend = TargetBackend.JS)
}
testClass<AbstractIrBoxJsTest> {
model("box/", pattern = "^([^_](.+))\\.kt$", targetBackend = TargetBackend.JS_IR)
}
testClass<AbstractSourceMapGenerationSmokeTest> {
model("sourcemap/", pattern = "^([^_](.+))\\.kt$", targetBackend = TargetBackend.JS)
}
@@ -1,17 +1,6 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* 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.
* 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.
*/
package org.jetbrains.kotlin.js.test
@@ -93,6 +82,7 @@ abstract class BasicBoxTest(
protected open fun getOutputPostfixFile(testFilePath: String): File? = null
protected open val runMinifierByDefault: Boolean = false
protected open val skipMinification = System.getProperty("kotlin.js.skipMinificationTest", "false")!!.toBoolean()
fun doTest(filePath: String) {
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 testPackage = testFactory.testPackage
val testFunction = TEST_FUNCTION
val generatedJsFiles = orderedModules.asReversed().mapNotNull { module ->
val dependencies = module.dependencies.map { modules[it]?.outputFileName(outputDir) + ".meta.js" }
val friends = module.friends.map { modules[it]?.outputFileName(outputDir) + ".meta.js" }
val outputFileName = module.outputFileName(outputDir) + ".js"
generateJavaScriptFile(file.parent, module, outputFileName, dependencies, friends, modules.size > 1,
!SKIP_SOURCEMAP_REMAPPING.matcher(fileContent).find(),
outputPrefixFile, outputPostfixFile, mainCallParameters)
generateJavaScriptFile(
file.parent, module, outputFileName, dependencies, friends, modules.size > 1,
!SKIP_SOURCEMAP_REMAPPING.matcher(fileContent).find(),
outputPrefixFile, outputPostfixFile, mainCallParameters, testPackage, testFunction
)
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()) {
val nodeRunnerName = mainModule.outputFileName(outputDir) + ".node.js"
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)
}
runGeneratedCode(allJsFiles, mainModuleName, testFactory.testPackage, TEST_FUNCTION, expectedResult, withModuleSystem)
runGeneratedCode(allJsFiles, mainModuleName, testPackage, testFunction, expectedResult, withModuleSystem)
performAdditionalChecks(generatedJsFiles.map { it.first }, outputPrefixFile, outputPostfixFile)
val expectedReachableNodesMatcher = EXPECTED_REACHABLE_NODES.matcher(fileContent)
val expectedReachableNodesFound = expectedReachableNodesMatcher.find()
val skipMinification = System.getProperty("kotlin.js.skipMinificationTest", "false").toBoolean()
if (!skipMinification &&
(runMinifierByDefault || expectedReachableNodesFound) &&
!SKIP_MINIFICATION.matcher(fileContent).find()
@@ -207,22 +202,22 @@ abstract class BasicBoxTest(
val outputDirForMinification = getOutputDir(file, testGroupOutputDirForMinification)
minifyAndRun(
workDir = File(outputDirForMinification, file.nameWithoutExtension),
allJsFiles = allJsFiles,
generatedJsFiles = generatedJsFiles,
expectedResult = expectedResult,
testModuleName = mainModuleName,
testPackage = testFactory.testPackage,
testFunction = TEST_FUNCTION,
withModuleSystem = withModuleSystem,
minificationThresholdChecker = thresholdChecker)
workDir = File(outputDirForMinification, file.nameWithoutExtension),
allJsFiles = allJsFiles,
generatedJsFiles = generatedJsFiles,
expectedResult = expectedResult,
testModuleName = mainModuleName,
testPackage = testPackage,
testFunction = testFunction,
withModuleSystem = withModuleSystem,
minificationThresholdChecker = thresholdChecker)
}
}
}
protected open fun runGeneratedCode(
jsFiles: List<String>,
testModuleName: String,
testModuleName: String?,
testPackage: String?,
testFunction: String,
expectedResult: String,
@@ -290,7 +285,9 @@ abstract class BasicBoxTest(
remap: Boolean,
outputPrefixFile: File?,
outputPostfixFile: File?,
mainCallParameters: MainCallParameters
mainCallParameters: MainCallParameters,
testPackage: String?,
testFunction: String
) {
val kotlinFiles = module.files.filter { it.fileName.endsWith(".kt") }
val testFiles = kotlinFiles.map { it.fileName }
@@ -310,12 +307,16 @@ abstract class BasicBoxTest(
val outputFile = File(outputFileName)
val incrementalData = IncrementalData()
translateFiles(psiFiles.map(TranslationUnit::SourceFile), outputFile, config, outputPrefixFile, outputPostfixFile,
mainCallParameters, incrementalData, remap)
translateFiles(
psiFiles.map(TranslationUnit::SourceFile), outputFile, config, outputPrefixFile, outputPostfixFile,
mainCallParameters, incrementalData, remap, testPackage, testFunction
)
if (module.hasFilesToRecompile) {
checkIncrementalCompilation(sourceDirs, module, kotlinFiles, dependencies, friends, multiModule, remap,
outputFile, outputPrefixFile, outputPostfixFile, mainCallParameters, incrementalData)
checkIncrementalCompilation(
sourceDirs, module, kotlinFiles, dependencies, friends, multiModule, remap,
outputFile, outputPrefixFile, outputPostfixFile, mainCallParameters, incrementalData, testPackage, testFunction
)
}
}
@@ -331,7 +332,9 @@ abstract class BasicBoxTest(
outputPrefixFile: File?,
outputPostfixFile: File?,
mainCallParameters: MainCallParameters,
incrementalData: IncrementalData
incrementalData: IncrementalData,
testPackage: String?,
testFunction: String
) {
val sourceToTranslationUnit = hashMapOf<File, TranslationUnit>()
for (testFile in kotlinFiles) {
@@ -351,8 +354,10 @@ abstract class BasicBoxTest(
val recompiledConfig = createConfig(sourceDirs, module, dependencies, friends, multiModule, incrementalData)
val recompiledOutputFile = File(outputFile.parentFile, outputFile.nameWithoutExtension + "-recompiled.js")
translateFiles(translationUnits, recompiledOutputFile, recompiledConfig, outputPrefixFile, outputPostfixFile,
mainCallParameters, incrementalData, remap)
translateFiles(
translationUnits, recompiledOutputFile, recompiledConfig, outputPrefixFile, outputPostfixFile,
mainCallParameters, incrementalData, remap, testPackage, testFunction
)
val originalOutput = FileUtil.loadFile(outputFile)
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())
private fun translateFiles(
units: List<TranslationUnit>,
outputFile: File,
config: JsConfig,
outputPrefixFile: File?,
outputPostfixFile: File?,
mainCallParameters: MainCallParameters,
incrementalData: IncrementalData,
remap: Boolean
protected open fun translateFiles(
units: List<TranslationUnit>,
outputFile: File,
config: JsConfig,
outputPrefixFile: File?,
outputPostfixFile: File?,
mainCallParameters: MainCallParameters,
incrementalData: IncrementalData,
remap: Boolean,
testPackage: String?,
testFunction: String
) {
val translator = K2JSTranslator(config)
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.
*
* 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.
* 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.
*/
package org.jetbrains.kotlin.js.test
@@ -32,13 +21,17 @@ fun ScriptEngine.overrideAsserter() {
}
fun ScriptEngine.runTestFunction(
testModuleName: String, testPackageName: String?, testFunctionName: String,
withModuleSystem: Boolean
testModuleName: String?,
testPackageName: String?,
testFunctionName: String,
withModuleSystem: Boolean
): Any? {
val testModule =
when {
withModuleSystem ->
eval(BasicBoxTest.Companion.KOTLIN_TEST_INTERNAL + ".require('" + testModuleName + "')")
eval(BasicBoxTest.Companion.KOTLIN_TEST_INTERNAL + ".require('" + testModuleName!! + "')")
testModuleName == null ->
eval("this")
else ->
get(testModuleName)
}
@@ -90,7 +83,7 @@ object NashornJsTestChecker {
fun check(
files: List<String>,
testModuleName: String,
testModuleName: String?,
testPackageName: String?,
testFunctionName: String,
expectedResult: String,
@@ -112,7 +105,7 @@ object NashornJsTestChecker {
private fun run(
files: List<String>,
testModuleName: String,
testModuleName: String?,
testPackageName: String?,
testFunctionName: String,
withModuleSystem: Boolean
@@ -1,17 +1,6 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* 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.
* 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.
*/
package org.jetbrains.kotlin.js.test.semantics
@@ -31,7 +20,7 @@ abstract class AbstractWebDemoExamplesTest(relativePath: String) : BasicBoxTest(
) {
override fun runGeneratedCode(
jsFiles: List<String>,
testModuleName: String,
testModuleName: String?,
testPackage: String?,
testFunction: String,
expectedResult: String,
File diff suppressed because it is too large Load Diff
@@ -1,22 +1,12 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* 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.
* 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.
*/
package org.jetbrains.kotlin.js.test.semantics
import org.jetbrains.kotlin.js.test.BasicBoxTest
import org.jetbrains.kotlin.js.test.BasicIrBoxTest
abstract class BorrowedInlineTest(relativePath: String) : BasicBoxTest(
"compiler/testData/codegen/boxInline/$relativePath",
@@ -56,4 +46,6 @@ abstract class AbstractSourceMapGenerationSmokeTest : BasicBoxTest(
"sourcemap/",
generateSourceMap = true,
generateNodeJsRunner = false
)
)
abstract class AbstractIrBoxJsTest : BasicIrBoxTest(BasicBoxTest.TEST_DATA_DIR_PATH + "box/", "irBox/")