diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/TestExceptionsComparator.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/TestExceptionsComparator.kt index 7a0c3cf4471..8909fd784fa 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/TestExceptionsComparator.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/TestExceptionsComparator.kt @@ -8,47 +8,9 @@ package org.jetbrains.kotlin import org.jetbrains.kotlin.test.KotlinTestUtils import org.junit.Assert import java.io.File -import java.io.PrintStream -import java.io.PrintWriter import java.util.regex.Matcher import java.util.regex.Pattern -enum class TestsExceptionType(val postfix: String) { - COMPILER_ERROR("compiler"), - COMPILETIME_ERROR("compiletime"), - RUNTIME_ERROR("runtime"), - INFRASTRUCTURE_ERROR("infrastructure"); - - companion object { - private val map = values().associateBy(TestsExceptionType::postfix) - - fun fromValue(type: String) = map[type] - } -} - -sealed class TestsError(val original: Throwable, val type: TestsExceptionType) : Error() { - override fun toString(): String = original.toString() - override fun getStackTrace(): Array = original.stackTrace - override fun initCause(cause: Throwable?): Throwable = original.initCause(cause) - override val cause: Throwable? get() = original.cause - - // This function is called in the constructor of Throwable, where original is not yet initialized - override fun fillInStackTrace(): Throwable? = @Suppress("UNNECESSARY_SAFE_CALL") original?.fillInStackTrace() - - override fun setStackTrace(stackTrace: Array?) { - original.stackTrace = stackTrace - } - - override fun printStackTrace() = original.printStackTrace() - override fun printStackTrace(s: PrintStream?) = original.printStackTrace(s) - override fun printStackTrace(s: PrintWriter?) = original.printStackTrace(s) -} - -class TestsCompilerError(original: Throwable) : TestsError(original, TestsExceptionType.COMPILER_ERROR) -class TestsInfrastructureError(original: Throwable) : TestsError(original, TestsExceptionType.INFRASTRUCTURE_ERROR) -class TestsCompiletimeError(original: Throwable) : TestsError(original, TestsExceptionType.COMPILETIME_ERROR) -class TestsRuntimeError(original: Throwable) : TestsError(original, TestsExceptionType.RUNTIME_ERROR) - private enum class ExceptionType { ANALYZING_EXPRESSION, UNKNOWN diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/AbstractForeignAnnotationsNoAnnotationInClasspathTest.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/AbstractForeignAnnotationsNoAnnotationInClasspathTest.kt index a08c193f54e..8990007a67c 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/AbstractForeignAnnotationsNoAnnotationInClasspathTest.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/AbstractForeignAnnotationsNoAnnotationInClasspathTest.kt @@ -18,6 +18,7 @@ package org.jetbrains.kotlin.checkers import org.jetbrains.kotlin.codegen.CodegenTestUtil import org.jetbrains.kotlin.test.InTextDirectivesUtils +import org.jetbrains.kotlin.test.util.JUnit4Assertions import org.jetbrains.kotlin.test.util.KtTestUtil import java.io.File @@ -34,9 +35,10 @@ abstract class AbstractForeignAnnotationsNoAnnotationInClasspathTest : AbstractF val additionalClasspath = (foreignAnnotations + testAnnotations).map { it.path } CodegenTestUtil.compileJava( - CodegenTestUtil.findJavaSourcesInDirectory(javaFilesDir), - additionalClasspath, emptyList(), - compiledJavaPath + CodegenTestUtil.findJavaSourcesInDirectory(javaFilesDir), + additionalClasspath, emptyList(), + compiledJavaPath, + JUnit4Assertions ) return listOf(compiledJavaPath) + testAnnotations diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractBlackBoxAgainstJavaCodegenTest.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractBlackBoxAgainstJavaCodegenTest.kt index 4a3ad7319b7..28f63b170d2 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractBlackBoxAgainstJavaCodegenTest.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractBlackBoxAgainstJavaCodegenTest.kt @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.codegen import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoot import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.config.JvmTarget +import org.jetbrains.kotlin.test.util.JUnit4Assertions import java.io.File abstract class AbstractBlackBoxAgainstJavaCodegenTest : AbstractBlackBoxCodegenTest() { @@ -35,6 +36,7 @@ abstract class AbstractBlackBoxAgainstJavaCodegenTest : AbstractBlackBoxCodegenT jvmTargets.firstOrNull(), enablePreview, ), + JUnit4Assertions ) } diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/resolve/ExpectedResolveDataUtil.java b/compiler/tests-common/tests/org/jetbrains/kotlin/resolve/ExpectedResolveDataUtil.java index 257b5cebd96..c5507e91362 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/resolve/ExpectedResolveDataUtil.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/resolve/ExpectedResolveDataUtil.java @@ -33,8 +33,6 @@ import org.jetbrains.kotlin.psi.KtExpression; import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall; import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults; import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfoFactory; -import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory; -import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactoryImpl; import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt; import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil; import org.jetbrains.kotlin.resolve.scopes.ImportingScope; diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java index f4caa9bdf60..aa821066581 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java @@ -56,13 +56,10 @@ import org.jetbrains.kotlin.test.util.StringUtilsKt; import org.jetbrains.kotlin.utils.ExceptionUtilsKt; import org.junit.Assert; -import javax.tools.*; import java.io.File; import java.io.IOException; -import java.io.StringWriter; import java.lang.annotation.Annotation; import java.lang.reflect.Method; -import java.nio.charset.Charset; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/compiler/tests-compiler-utils/build.gradle.kts b/compiler/tests-compiler-utils/build.gradle.kts index f75f87e3487..ce290e101bf 100644 --- a/compiler/tests-compiler-utils/build.gradle.kts +++ b/compiler/tests-compiler-utils/build.gradle.kts @@ -22,6 +22,7 @@ dependencies { testCompile(project(":compiler:cli")) testCompile(project(":compiler:cli-js")) testCompile(project(":compiler:serialization")) + testCompile(project(":compiler:fir:entrypoint")) testCompile(projectTests(":compiler:test-infrastructure-utils")) testCompile(project(":kotlin-preloader")) testCompileOnly(intellijCoreDep()) { includeJars("intellij-core") } diff --git a/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/TestsError.kt b/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/TestsError.kt new file mode 100644 index 00000000000..aab3e369c4f --- /dev/null +++ b/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/TestsError.kt @@ -0,0 +1,45 @@ +/* + * 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 + +import java.io.PrintStream +import java.io.PrintWriter + +enum class TestsExceptionType(val postfix: String) { + COMPILER_ERROR("compiler"), + COMPILETIME_ERROR("compiletime"), + RUNTIME_ERROR("runtime"), + INFRASTRUCTURE_ERROR("infrastructure"); + + companion object { + private val map = values().associateBy(TestsExceptionType::postfix) + + fun fromValue(type: String) = map[type] + } +} + +sealed class TestsError(val original: Throwable, val type: TestsExceptionType) : Error() { + override fun toString(): String = original.toString() + override fun getStackTrace(): Array = original.stackTrace + override fun initCause(cause: Throwable?): Throwable = original.initCause(cause) + override val cause: Throwable? get() = original.cause + + // This function is called in the constructor of Throwable, where original is not yet initialized + override fun fillInStackTrace(): Throwable? = @Suppress("UNNECESSARY_SAFE_CALL") original?.fillInStackTrace() + + override fun setStackTrace(stackTrace: Array?) { + original.stackTrace = stackTrace + } + + override fun printStackTrace() = original.printStackTrace() + override fun printStackTrace(s: PrintStream?) = original.printStackTrace(s) + override fun printStackTrace(s: PrintWriter?) = original.printStackTrace(s) +} + +class TestsCompilerError(original: Throwable) : TestsError(original, TestsExceptionType.COMPILER_ERROR) +class TestsInfrastructureError(original: Throwable) : TestsError(original, TestsExceptionType.INFRASTRUCTURE_ERROR) +class TestsCompiletimeError(original: Throwable) : TestsError(original, TestsExceptionType.COMPILETIME_ERROR) +class TestsRuntimeError(original: Throwable) : TestsError(original, TestsExceptionType.RUNTIME_ERROR) diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/CodegenTestFiles.java b/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/codegen/CodegenTestFiles.java similarity index 100% rename from compiler/tests-common/tests/org/jetbrains/kotlin/codegen/CodegenTestFiles.java rename to compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/codegen/CodegenTestFiles.java diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/CodegenTestUtil.java b/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/codegen/CodegenTestUtil.java similarity index 84% rename from compiler/tests-common/tests/org/jetbrains/kotlin/codegen/CodegenTestUtil.java rename to compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/codegen/CodegenTestUtil.java index 6b563937420..ee8c65e5d22 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/CodegenTestUtil.java +++ b/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/codegen/CodegenTestUtil.java @@ -1,17 +1,6 @@ /* - * 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. + * 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.codegen; @@ -24,7 +13,9 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment; import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime; -import org.jetbrains.kotlin.test.KotlinTestUtils; +import org.jetbrains.kotlin.test.Assertions; +import org.jetbrains.kotlin.test.JvmCompilationUtils; +import org.jetbrains.kotlin.test.KtAssert; import org.jetbrains.kotlin.test.util.KtTestUtil; import org.jetbrains.kotlin.utils.ExceptionUtilsKt; import org.jetbrains.kotlin.utils.StringsKt; @@ -37,8 +28,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.junit.Assert.assertTrue; - public class CodegenTestUtil { private CodegenTestUtil() { } @@ -58,7 +47,7 @@ public class CodegenTestUtil { catch (InvocationTargetException ex) { caught = exceptionClass.isInstance(ex.getTargetException()); } - assertTrue(caught); + KtAssert.assertTrue(String.format("Exception of class %s must be thrown", exceptionClass.getName()), caught); } @NotNull @@ -83,11 +72,12 @@ public class CodegenTestUtil { public static File compileJava( @NotNull List fileNames, @NotNull List additionalClasspath, - @NotNull List additionalOptions + @NotNull List additionalOptions, + @NotNull Assertions assertions ) { try { File directory = KtTestUtil.tmpDir("java-classes"); - compileJava(fileNames, additionalClasspath, additionalOptions, directory); + compileJava(fileNames, additionalClasspath, additionalOptions, directory, assertions); return directory; } catch (IOException e) { @@ -99,11 +89,12 @@ public class CodegenTestUtil { @NotNull List fileNames, @NotNull List additionalClasspath, @NotNull List additionalOptions, - @NotNull File outDirectory + @NotNull File outDirectory, + @NotNull Assertions assertions ) { try { List options = prepareJavacOptions(additionalClasspath, additionalOptions, outDirectory); - KotlinTestUtils.compileJavaFiles(CollectionsKt.map(fileNames, File::new), options); + JvmCompilationUtils.compileJavaFiles(CollectionsKt.map(fileNames, File::new), options, assertions); } catch (IOException e) { throw ExceptionUtilsKt.rethrow(e); diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/GenerationUtils.kt b/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/codegen/GenerationUtils.kt similarity index 93% rename from compiler/tests-common/tests/org/jetbrains/kotlin/codegen/GenerationUtils.kt rename to compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/codegen/GenerationUtils.kt index 6ea194f2c05..23e10301bca 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/GenerationUtils.kt +++ b/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/codegen/GenerationUtils.kt @@ -1,17 +1,6 @@ /* - * 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. + * 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.codegen diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/fir/FirTestModuleInfo.kt b/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/fir/FirTestModuleInfo.kt similarity index 100% rename from compiler/tests-common/tests/org/jetbrains/kotlin/fir/FirTestModuleInfo.kt rename to compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/fir/FirTestModuleInfo.kt diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/fir/SessionTestUtils.kt b/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/fir/SessionTestUtils.kt similarity index 100% rename from compiler/tests-common/tests/org/jetbrains/kotlin/fir/SessionTestUtils.kt rename to compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/fir/SessionTestUtils.kt diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/resolve/lazy/JvmResolveUtil.kt b/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/resolve/lazy/JvmResolveUtil.kt similarity index 87% rename from compiler/tests-common/tests/org/jetbrains/kotlin/resolve/lazy/JvmResolveUtil.kt rename to compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/resolve/lazy/JvmResolveUtil.kt index 204c8451c9a..b49b6d945e9 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/resolve/lazy/JvmResolveUtil.kt +++ b/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/resolve/lazy/JvmResolveUtil.kt @@ -1,17 +1,6 @@ /* - * 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. + * 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.resolve.lazy diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/OuterClassGenTest.java b/compiler/tests/org/jetbrains/kotlin/codegen/OuterClassGenTest.java index bffde6c6c83..46263b1f886 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/OuterClassGenTest.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/OuterClassGenTest.java @@ -25,6 +25,7 @@ import org.jetbrains.kotlin.backend.common.output.OutputFile; import org.jetbrains.kotlin.backend.common.output.OutputFileCollection; import org.jetbrains.kotlin.name.SpecialNames; import org.jetbrains.kotlin.test.ConfigurationKind; +import org.jetbrains.kotlin.test.util.JUnit4Assertions; import org.jetbrains.kotlin.test.util.KtTestUtil; import org.jetbrains.kotlin.utils.StringsKt; import org.jetbrains.org.objectweb.asm.ClassReader; @@ -158,7 +159,8 @@ public class OuterClassGenTest extends CodegenTestCase { File javaOut = CodegenTestUtil.compileJava( Collections.singletonList(KtTestUtil.getTestDataPathBase() + "/codegen/" + getPrefix() + "/" + testDataFile + ".java"), Collections.emptyList(), - Collections.emptyList() + Collections.emptyList(), + JUnit4Assertions.INSTANCE ); String javaClassPath = javaClassName.replace('.', File.separatorChar) + ".class"; diff --git a/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/DebuggerTestCompilerFacility.kt b/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/DebuggerTestCompilerFacility.kt index 097601eee6b..d090288a18e 100644 --- a/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/DebuggerTestCompilerFacility.kt +++ b/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/DebuggerTestCompilerFacility.kt @@ -32,6 +32,7 @@ import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.test.KotlinBaseTest.TestFile import org.jetbrains.kotlin.test.MockLibraryUtil import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase +import org.jetbrains.kotlin.test.util.JUnit4Assertions import java.io.File class DebuggerTestCompilerFacility( @@ -109,7 +110,8 @@ class DebuggerTestCompilerFacility( java.map { File(srcDir, it.name).absolutePath }, mavenArtifacts + classesDir.absolutePath, listOf("-g"), - classesDir + classesDir, + JUnit4Assertions ) } } @@ -152,7 +154,8 @@ class DebuggerTestCompilerFacility( java.map { File(srcDir, it.name).absolutePath }, getClasspath(module) + listOf(classesDir.absolutePath), listOf("-g"), - classesDir + classesDir, + JUnit4Assertions ) } @@ -252,4 +255,4 @@ private fun splitByLanguage(files: List): TestFilesByLanguage { } return TestFilesByLanguage(kotlin = kotlin, java = java, resources = resources) -} \ No newline at end of file +}