Get rid of code duplication in kt-against-kt tests
This commit is contained in:
+1
-33
@@ -16,18 +16,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.jvm.compiler
|
||||
|
||||
import org.jetbrains.kotlin.codegen.ClassFileFactory
|
||||
import org.jetbrains.kotlin.codegen.InlineTestUtil
|
||||
import org.jetbrains.kotlin.codegen.filterClassFiles
|
||||
import java.io.File
|
||||
import java.util.Collections
|
||||
|
||||
abstract class AbstractCompileKotlinAgainstInlineKotlinTest : AbstractCompileKotlinAgainstKotlinTest(), AbstractSMAPBaseTest {
|
||||
|
||||
fun doBoxTestWithInlineCheck(firstFileName: String) {
|
||||
val inputFiles = listOf(firstFileName, firstFileName.substringBeforeLast("1.kt") + "2.kt")
|
||||
|
||||
val (factory1, factory2) = doBoxTest(inputFiles)
|
||||
val (factory1, factory2) = doBoxTest(firstFileName)
|
||||
val allGeneratedFiles = factory1.asList() + factory2.asList()
|
||||
|
||||
try {
|
||||
@@ -40,30 +34,4 @@ abstract class AbstractCompileKotlinAgainstInlineKotlinTest : AbstractCompileKot
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
private fun doBoxTest(files: List<String>): Pair<ClassFileFactory, ClassFileFactory> {
|
||||
Collections.sort(files)
|
||||
|
||||
var factory1: ClassFileFactory? = null
|
||||
var factory2: ClassFileFactory? = null
|
||||
try {
|
||||
factory1 = compileA(File(files[1]))
|
||||
factory2 = compileB(File(files[0]))
|
||||
invokeBox(files[0])
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
var result = ""
|
||||
if (factory1 != null) {
|
||||
result += "FIRST: \n\n" + factory1.createText()
|
||||
}
|
||||
if (factory2 != null) {
|
||||
result += "\n\nSECOND: \n\n" + factory2.createText()
|
||||
}
|
||||
System.out.println(result)
|
||||
throw e
|
||||
}
|
||||
|
||||
return Pair(factory1!!, factory2!!)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+34
-3
@@ -20,6 +20,8 @@ import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import kotlin.Pair;
|
||||
import kotlin.text.StringsKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.cli.common.modules.ModuleBuilder;
|
||||
import org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsKt;
|
||||
@@ -36,12 +38,15 @@ import org.jetbrains.kotlin.test.ConfigurationKind;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.TestCaseWithTmpdir;
|
||||
import org.jetbrains.kotlin.test.TestJdkKind;
|
||||
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractCompileKotlinAgainstKotlinTest extends TestCaseWithTmpdir {
|
||||
private File aDir;
|
||||
@@ -69,7 +74,7 @@ public abstract class AbstractCompileKotlinAgainstKotlinTest extends TestCaseWit
|
||||
main.invoke(null, new Object[] {ArrayUtil.EMPTY_STRING_ARRAY});
|
||||
}
|
||||
|
||||
protected void invokeBox(@NotNull String fileName) throws Exception {
|
||||
private void invokeBox(@NotNull String fileName) throws Exception {
|
||||
Method box = generatedClass(fileName).getMethod("box");
|
||||
String result = (String) box.invoke(null);
|
||||
assertEquals("OK", result);
|
||||
@@ -85,13 +90,13 @@ public abstract class AbstractCompileKotlinAgainstKotlinTest extends TestCaseWit
|
||||
return classLoader.loadClass(PackagePartClassUtils.getFilePartShortName(fileLastName));
|
||||
}
|
||||
|
||||
protected ClassFileFactory compileA(@NotNull File ktAFile) throws IOException {
|
||||
private ClassFileFactory compileA(@NotNull File ktAFile) throws IOException {
|
||||
KotlinCoreEnvironment jetCoreEnvironment = KotlinTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations(getTestRootDisposable(),
|
||||
ConfigurationKind.ALL);
|
||||
return compileKotlin(ktAFile, aDir, jetCoreEnvironment, getTestRootDisposable());
|
||||
}
|
||||
|
||||
protected ClassFileFactory compileB(@NotNull File ktBFile) throws IOException {
|
||||
private ClassFileFactory compileB(@NotNull File ktBFile) throws IOException {
|
||||
CompilerConfiguration configurationWithADirInClasspath = KotlinTestUtils
|
||||
.compilerConfigurationForTests(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, KotlinTestUtils.getAnnotationsJar(), aDir);
|
||||
|
||||
@@ -119,4 +124,30 @@ public abstract class AbstractCompileKotlinAgainstKotlinTest extends TestCaseWit
|
||||
Disposer.dispose(disposable);
|
||||
return outputFiles;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected Pair<ClassFileFactory, ClassFileFactory> doBoxTest(@NotNull String firstFileName) {
|
||||
List<String> files = Arrays.asList(firstFileName, StringsKt.substringBeforeLast(firstFileName, "1.kt", "") + "2.kt");
|
||||
|
||||
ClassFileFactory factory1 = null;
|
||||
ClassFileFactory factory2 = null;
|
||||
try {
|
||||
factory1 = compileA(new File(files.get(1)));
|
||||
factory2 = compileB(new File(files.get(0)));
|
||||
invokeBox(files.get(0));
|
||||
}
|
||||
catch (Throwable e) {
|
||||
String result = "";
|
||||
if (factory1 != null) {
|
||||
result += "FIRST: \n\n" + factory1.createText();
|
||||
}
|
||||
if (factory2 != null) {
|
||||
result += "\n\nSECOND: \n\n" + factory2.createText();
|
||||
}
|
||||
System.out.println(result);
|
||||
throw ExceptionUtilsKt.rethrow(e);
|
||||
}
|
||||
|
||||
return new Pair<ClassFileFactory, ClassFileFactory>(factory1, factory2);
|
||||
}
|
||||
}
|
||||
|
||||
-57
@@ -1,57 +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.jvm.compiler
|
||||
|
||||
import org.jetbrains.kotlin.codegen.ClassFileFactory
|
||||
import org.jetbrains.kotlin.codegen.InlineTestUtil
|
||||
import org.jetbrains.kotlin.codegen.filterClassFiles
|
||||
import java.io.File
|
||||
import java.util.Collections
|
||||
|
||||
abstract class AbstractCompileKotlinAgainstMultifileKotlinTest : AbstractCompileKotlinAgainstKotlinTest(), AbstractSMAPBaseTest {
|
||||
|
||||
fun doBoxTest(firstFileName: String) {
|
||||
val inputFiles = listOf(firstFileName, firstFileName.substringBeforeLast("1.kt") + "2.kt")
|
||||
doBoxTest(inputFiles)
|
||||
}
|
||||
|
||||
private fun doBoxTest(files: List<String>): Pair<ClassFileFactory, ClassFileFactory> {
|
||||
Collections.sort(files)
|
||||
|
||||
var factory1: ClassFileFactory? = null
|
||||
var factory2: ClassFileFactory? = null
|
||||
try {
|
||||
factory1 = compileA(File(files[1]))
|
||||
factory2 = compileB(File(files[0]))
|
||||
invokeBox(files[0])
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
var result = ""
|
||||
if (factory1 != null) {
|
||||
result += "FIRST: \n\n" + factory1.createText()
|
||||
}
|
||||
if (factory2 != null) {
|
||||
result += "\n\nSECOND: \n\n" + factory2.createText()
|
||||
}
|
||||
System.out.println(result)
|
||||
throw e
|
||||
}
|
||||
|
||||
return Pair(factory1!!, factory2!!)
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -30,7 +30,7 @@ import java.util.regex.Pattern;
|
||||
@TestMetadata("compiler/testData/codegen/boxMultifileClasses")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class CompileKotlinAgainstMultifileKotlinTestGenerated extends AbstractCompileKotlinAgainstMultifileKotlinTest {
|
||||
public class CompileKotlinAgainstMultifileKotlinTestGenerated extends AbstractCompileKotlinAgainstKotlinTest {
|
||||
public void testAllFilesPresentInBoxMultifileClasses() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxMultifileClasses"), Pattern.compile("^(.+)\\.1.kt$"), true);
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ fun main(args: Array<String>) {
|
||||
model("codegen/boxInline", extension = "1.kt", testMethod = "doBoxTestWithInlineCheck")
|
||||
}
|
||||
|
||||
testClass(AbstractCompileKotlinAgainstMultifileKotlinTest::class.java, "CompileKotlinAgainstMultifileKotlinTestGenerated") {
|
||||
testClass(AbstractCompileKotlinAgainstKotlinTest::class.java, "CompileKotlinAgainstMultifileKotlinTestGenerated") {
|
||||
model("codegen/boxMultifileClasses", extension = "1.kt", testMethod = "doBoxTest")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user