[JS TESTS] Rewrite web demo tests using new test infrastructure
This commit is contained in:
@@ -15,11 +15,11 @@ import org.jetbrains.kotlin.js.test.es6.semantics.AbstractIrJsCodegenBoxES6Test
|
||||
import org.jetbrains.kotlin.js.test.es6.semantics.AbstractIrJsCodegenInlineES6Test
|
||||
import org.jetbrains.kotlin.js.test.es6.semantics.AbstractIrJsTypeScriptExportES6Test
|
||||
import org.jetbrains.kotlin.js.test.ir.semantics.*
|
||||
import org.jetbrains.kotlin.js.test.semantics.*
|
||||
import org.jetbrains.kotlin.js.test.wasm.semantics.AbstractIrCodegenBoxWasmTest
|
||||
import org.jetbrains.kotlin.js.test.wasm.semantics.AbstractIrCodegenWasmJsInteropWasmTest
|
||||
import org.jetbrains.kotlin.js.test.wasm.semantics.AbstractJsTranslatorWasmTest
|
||||
import org.jetbrains.kotlin.js.testNew.*
|
||||
import org.jetbrains.kotlin.js.testNew.AbstractWebDemoExamplesTest
|
||||
import org.jetbrains.kotlin.test.TargetBackend
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
@@ -137,6 +137,10 @@ fun main(args: Array<String>) {
|
||||
testClass<AbstractMultiModuleOrderTest> {
|
||||
model("multiModuleOrder/")
|
||||
}
|
||||
|
||||
testClass<AbstractWebDemoExamplesTest> {
|
||||
model("webDemoExamples/")
|
||||
}
|
||||
}
|
||||
|
||||
testGroup("js/js.tests/tests-gen", "compiler/testData", testRunnerMethodName = "runTest0") {
|
||||
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* 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 com.google.common.collect.Lists
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import org.jetbrains.kotlin.js.facade.MainCallParameters
|
||||
import org.jetbrains.kotlin.js.test.BasicBoxTest
|
||||
import java.io.File
|
||||
import javax.script.ScriptException
|
||||
|
||||
abstract class AbstractWebDemoExamplesTest(relativePath: String) : BasicBoxTest(
|
||||
BasicBoxTest.TEST_DATA_DIR_PATH + "/$relativePath/",
|
||||
relativePath,
|
||||
generateNodeJsRunner = false
|
||||
) {
|
||||
override fun runGeneratedCode(
|
||||
jsFiles: List<String>,
|
||||
testModuleName: String?,
|
||||
testPackage: String?,
|
||||
testFunction: String,
|
||||
expectedResult: String,
|
||||
withModuleSystem: Boolean
|
||||
) {
|
||||
testChecker.checkStdout(jsFiles, expectedResult)
|
||||
}
|
||||
|
||||
@Throws(ScriptException::class)
|
||||
protected fun runMainAndCheckOutput(fileName: String, expectedResult: String, vararg args: String) {
|
||||
doTest(pathToTestDir + fileName, expectedResult, MainCallParameters.mainWithArguments(Lists.newArrayList(*args)))
|
||||
}
|
||||
|
||||
protected fun runMainAndCheckOutputWithExpectedFile(testName: String, testId: String, vararg args: String) {
|
||||
val expectedResult = StringUtil.convertLineSeparators(File(pathToTestDir + testName + testId + ".out").readText())
|
||||
doTest(pathToTestDir + testName + ".kt", expectedResult, MainCallParameters.mainWithArguments(Lists.newArrayList(*args)))
|
||||
}
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.js.test.semantics;
|
||||
|
||||
public final class WebDemoExamples1Test extends AbstractWebDemoExamplesTest {
|
||||
|
||||
public WebDemoExamples1Test() {
|
||||
super("webDemoExamples1/");
|
||||
}
|
||||
|
||||
public void testPrintArg() throws Exception {
|
||||
runMainAndCheckOutput("printArg.kt", "Hello, world!", "Hello, world!");
|
||||
}
|
||||
|
||||
|
||||
public void testWhileLoop() throws Exception {
|
||||
runMainAndCheckOutput("whileLoop.kt", "guest1\nguest2\nguest3\nguest4\n", "guest1", "guest2", "guest3", "guest4");
|
||||
}
|
||||
|
||||
|
||||
public void testIfAsExpression() throws Exception {
|
||||
runMainAndCheckOutput("ifAsExpression.kt", "20\n", "10", "20");
|
||||
}
|
||||
|
||||
|
||||
public void testObjectOrientedHello() throws Exception {
|
||||
runMainAndCheckOutput("objectOrientedHello.kt", "Hello, Pavel!\n", "Pavel");
|
||||
}
|
||||
|
||||
|
||||
public void testMultiLanguageHello() throws Exception {
|
||||
runMainAndCheckOutput("multiLanguageHello.kt", "Salut!\n", "FR");
|
||||
}
|
||||
|
||||
|
||||
public void testNullChecks() throws Exception {
|
||||
runMainAndCheckOutput("nullChecks.kt", "No number supplied");
|
||||
runMainAndCheckOutput("nullChecks.kt", "6", "2", "3");
|
||||
}
|
||||
|
||||
|
||||
public void testRanges() throws Exception {
|
||||
runMainAndCheckOutput("ranges.kt", "OK\n" +
|
||||
" 1 2 3 4 5\n" +
|
||||
"Out: array has only 3 elements. x = 4\n" +
|
||||
"Yes: array contains aaa\n" +
|
||||
"No: array doesn't contains ddd\n", "4");
|
||||
|
||||
runMainAndCheckOutput("ranges.kt", " 1 2 3 4 5\n" +
|
||||
"Out: array has only 3 elements. x = 10\n" +
|
||||
"Yes: array contains aaa\n" +
|
||||
"No: array doesn't contains ddd\n", "10");
|
||||
}
|
||||
|
||||
|
||||
public void testForLoop() throws Exception {
|
||||
runMainAndCheckOutput("forLoop.kt", "a\n" +
|
||||
"b\n" +
|
||||
"c\n" +
|
||||
"\n" +
|
||||
"a\n" +
|
||||
"b\n" +
|
||||
"c\n", "a", "b", "c");
|
||||
runMainAndCheckOutput("forLoop.kt", "123\n\n123\n", "123");
|
||||
}
|
||||
|
||||
|
||||
public void testIsCheck() throws Exception {
|
||||
runMainAndCheckOutput("isCheck.kt", "3\nnull\n");
|
||||
}
|
||||
|
||||
|
||||
public void testPatternMatching() throws Exception {
|
||||
runMainAndCheckOutput("patternMatching.kt", "Greeting\n" +
|
||||
"One\n" +
|
||||
"Not a string\n" +
|
||||
"Unknown\n");
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.js.test.semantics;
|
||||
|
||||
public final class WebDemoExamples2Test extends AbstractWebDemoExamplesTest {
|
||||
|
||||
public WebDemoExamples2Test() {
|
||||
super("webDemoExamples2/");
|
||||
}
|
||||
|
||||
public void testBottles() throws Exception {
|
||||
runMainAndCheckOutputWithExpectedFile("bottles", "2", "2");
|
||||
runMainAndCheckOutputWithExpectedFile("bottles", "");
|
||||
}
|
||||
|
||||
public void testLife() throws Exception {
|
||||
runMainAndCheckOutputWithExpectedFile("life", "", "2");
|
||||
}
|
||||
|
||||
public void testBuilder() throws Exception {
|
||||
runMainAndCheckOutputWithExpectedFile("builder", "");
|
||||
runMainAndCheckOutputWithExpectedFile("builder", "1", "over9000");
|
||||
}
|
||||
}
|
||||
@@ -136,3 +136,22 @@ open class AbstractMultiModuleOrderTest : AbstractJsTest(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open class AbstractWebDemoExamplesTest : AbstractJsTest(
|
||||
pathToTestDir = "${JsEnvironmentConfigurator.TEST_DATA_DIR_PATH}/webDemoExamples/",
|
||||
testGroupOutputDirPrefix = "webDemoExamples/"
|
||||
) {
|
||||
override fun configure(builder: TestConfigurationBuilder) {
|
||||
super.configure(builder)
|
||||
with(builder) {
|
||||
defaultDirectives {
|
||||
-JsEnvironmentConfigurationDirectives.GENERATE_NODE_JS_RUNNER
|
||||
JsEnvironmentConfigurationDirectives.DONT_RUN_GENERATED_CODE.with("JS")
|
||||
}
|
||||
|
||||
configureJsArtifactsHandlersStep {
|
||||
useHandlers(::MainCallWithArgumentsHandler)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-2
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.js.testNew.converters
|
||||
|
||||
import com.google.common.collect.Lists
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import org.jetbrains.kotlin.cli.common.output.writeAllTo
|
||||
@@ -82,8 +83,11 @@ class ClassicJsBackendFacade(
|
||||
|
||||
val units = unitsByPath.entries.sortedBy { it.key }.map { it.value }
|
||||
|
||||
val mainCallParameters = when (JsEnvironmentConfigurationDirectives.CALL_MAIN) {
|
||||
in module.directives -> MainCallParameters.mainWithArguments(listOf())
|
||||
val mainCallParameters = when {
|
||||
JsEnvironmentConfigurationDirectives.CALL_MAIN in module.directives -> MainCallParameters.mainWithArguments(listOf())
|
||||
JsEnvironmentConfigurationDirectives.MAIN_ARGS in module.directives -> {
|
||||
MainCallParameters.mainWithArguments(module.directives[JsEnvironmentConfigurationDirectives.MAIN_ARGS].first())
|
||||
}
|
||||
else -> MainCallParameters.noCall()
|
||||
}
|
||||
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* 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.testNew.handlers
|
||||
|
||||
import org.jetbrains.kotlin.js.testNew.utils.getOnlyJsFilesForRunner
|
||||
import org.jetbrains.kotlin.js.testNew.utils.getTestChecker
|
||||
import org.jetbrains.kotlin.test.services.TestServices
|
||||
import org.jetbrains.kotlin.test.services.moduleStructure
|
||||
|
||||
class MainCallWithArgumentsHandler(testServices: TestServices) : AbstractJsArtifactsCollector(testServices) {
|
||||
override fun processAfterAllModules(someAssertionWasFailed: Boolean) {
|
||||
if (someAssertionWasFailed) return
|
||||
|
||||
val testFile = testServices.moduleStructure.originalTestDataFiles.first()
|
||||
val expectedFile = testFile.parentFile.resolve(testFile.nameWithoutExtension + ".out")
|
||||
if (!expectedFile.exists()) {
|
||||
throw IllegalArgumentException("File ${expectedFile.absolutePath} with expected result doesn't exists")
|
||||
}
|
||||
val allJsFiles = getOnlyJsFilesForRunner(testServices, modulesToArtifact)
|
||||
|
||||
getTestChecker(testServices).checkStdout(allJsFiles, expectedFile.readText())
|
||||
}
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* 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.testNew;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
import org.jetbrains.kotlin.test.TargetBackend;
|
||||
import org.jetbrains.kotlin.test.TestMetadata;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** This class is generated by {@link GenerateNewCompilerTests.kt}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("js/js.translator/testData/webDemoExamples")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class WebDemoExamplesTestGenerated extends AbstractWebDemoExamplesTest {
|
||||
@Test
|
||||
public void testAllFilesPresentInWebDemoExamples() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/webDemoExamples"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("bottles.kt")
|
||||
public void testBottles() throws Exception {
|
||||
runTest("js/js.translator/testData/webDemoExamples/bottles.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("builder.kt")
|
||||
public void testBuilder() throws Exception {
|
||||
runTest("js/js.translator/testData/webDemoExamples/builder.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("forLoop1.kt")
|
||||
public void testForLoop1() throws Exception {
|
||||
runTest("js/js.translator/testData/webDemoExamples/forLoop1.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("forLoop2.kt")
|
||||
public void testForLoop2() throws Exception {
|
||||
runTest("js/js.translator/testData/webDemoExamples/forLoop2.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("ifAsExpression.kt")
|
||||
public void testIfAsExpression() throws Exception {
|
||||
runTest("js/js.translator/testData/webDemoExamples/ifAsExpression.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("isCheck.kt")
|
||||
public void testIsCheck() throws Exception {
|
||||
runTest("js/js.translator/testData/webDemoExamples/isCheck.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("life.kt")
|
||||
public void testLife() throws Exception {
|
||||
runTest("js/js.translator/testData/webDemoExamples/life.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("maze.kt")
|
||||
public void testMaze() throws Exception {
|
||||
runTest("js/js.translator/testData/webDemoExamples/maze.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("multiLanguageHello.kt")
|
||||
public void testMultiLanguageHello() throws Exception {
|
||||
runTest("js/js.translator/testData/webDemoExamples/multiLanguageHello.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullChecks1.kt")
|
||||
public void testNullChecks1() throws Exception {
|
||||
runTest("js/js.translator/testData/webDemoExamples/nullChecks1.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullChecks2.kt")
|
||||
public void testNullChecks2() throws Exception {
|
||||
runTest("js/js.translator/testData/webDemoExamples/nullChecks2.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("objectOrientedHello.kt")
|
||||
public void testObjectOrientedHello() throws Exception {
|
||||
runTest("js/js.translator/testData/webDemoExamples/objectOrientedHello.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("patternMatching.kt")
|
||||
public void testPatternMatching() throws Exception {
|
||||
runTest("js/js.translator/testData/webDemoExamples/patternMatching.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("printArg.kt")
|
||||
public void testPrintArg() throws Exception {
|
||||
runTest("js/js.translator/testData/webDemoExamples/printArg.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("ranges1.kt")
|
||||
public void testRanges1() throws Exception {
|
||||
runTest("js/js.translator/testData/webDemoExamples/ranges1.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("ranges2.kt")
|
||||
public void testRanges2() throws Exception {
|
||||
runTest("js/js.translator/testData/webDemoExamples/ranges2.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("whileLoop.kt")
|
||||
public void testWhileLoop() throws Exception {
|
||||
runTest("js/js.translator/testData/webDemoExamples/whileLoop.kt");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user