Reduce boilerplate in CompileKotlinAgainstCustomBinariesTest
Check against output.txt in compileKotlin; adapt test data of some tests
This commit is contained in:
+1
@@ -0,0 +1 @@
|
|||||||
|
OK
|
||||||
Vendored
+1
-1
@@ -3,7 +3,7 @@ package test
|
|||||||
public class A {
|
public class A {
|
||||||
|
|
||||||
inline public fun test(s: () -> Unit) {
|
inline public fun test(s: () -> Unit) {
|
||||||
|
s()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
public interface JavaInterface {
|
||||||
|
void foo(int javaName);
|
||||||
|
}
|
||||||
-3
@@ -1,3 +0,0 @@
|
|||||||
interface JavaInterface {
|
|
||||||
void foo(int javaName);
|
|
||||||
}
|
|
||||||
@@ -1,2 +1 @@
|
|||||||
OK
|
OK
|
||||||
OK
|
|
||||||
+30
-70
@@ -66,7 +66,7 @@ class CompileKotlinAgainstCustomBinariesTest : TestCaseWithTmpdir() {
|
|||||||
additionalOptions: List<String> = emptyList(),
|
additionalOptions: List<String> = emptyList(),
|
||||||
vararg extraClassPath: File
|
vararg extraClassPath: File
|
||||||
): File {
|
): File {
|
||||||
val output = compileKotlin(sourcePath, destination, extraClassPath.toList(), compiler, additionalOptions)
|
val output = compileKotlin(sourcePath, destination, extraClassPath.toList(), compiler, additionalOptions, expectedFileName = null)
|
||||||
assertEquals(normalizeOutput("" to ExitCode.OK), normalizeOutput(output))
|
assertEquals(normalizeOutput("" to ExitCode.OK), normalizeOutput(output))
|
||||||
return destination
|
return destination
|
||||||
}
|
}
|
||||||
@@ -116,7 +116,8 @@ class CompileKotlinAgainstCustomBinariesTest : TestCaseWithTmpdir() {
|
|||||||
output: File,
|
output: File,
|
||||||
classpath: List<File> = emptyList(),
|
classpath: List<File> = emptyList(),
|
||||||
compiler: CLICompiler<*> = K2JVMCompiler(),
|
compiler: CLICompiler<*> = K2JVMCompiler(),
|
||||||
additionalOptions: List<String> = emptyList()
|
additionalOptions: List<String> = emptyList(),
|
||||||
|
expectedFileName: String? = "output.txt"
|
||||||
): Pair<String, ExitCode> {
|
): Pair<String, ExitCode> {
|
||||||
val args = mutableListOf<String>()
|
val args = mutableListOf<String>()
|
||||||
val sourceFile = File(testDataDirectory, fileName)
|
val sourceFile = File(testDataDirectory, fileName)
|
||||||
@@ -146,23 +147,24 @@ class CompileKotlinAgainstCustomBinariesTest : TestCaseWithTmpdir() {
|
|||||||
|
|
||||||
args.addAll(additionalOptions)
|
args.addAll(additionalOptions)
|
||||||
|
|
||||||
return AbstractCliTest.executeCompilerGrabOutput(compiler, args)
|
val result = AbstractCliTest.executeCompilerGrabOutput(compiler, args)
|
||||||
|
if (expectedFileName != null) {
|
||||||
|
KotlinTestUtils.assertEqualsToFile(File(testDataDirectory, expectedFileName), normalizeOutput(result))
|
||||||
|
}
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun doTestBrokenJavaLibrary(libraryName: String, vararg pathsToDelete: String) {
|
private fun doTestBrokenJavaLibrary(libraryName: String, vararg pathsToDelete: String) {
|
||||||
// This function compiles a Java library, then deletes one class file and attempts to compile a Kotlin source against
|
// This function compiles a Java library, then deletes one class file and attempts to compile a Kotlin source against
|
||||||
// this broken library. The expected result is an error message from the compiler
|
// this broken library. The expected result is an error message from the compiler
|
||||||
val library = deletePaths(compileJava(libraryName), *pathsToDelete)
|
val library = deletePaths(compileJava(libraryName), *pathsToDelete)
|
||||||
|
compileKotlin("source.kt", tmpdir, listOf(library))
|
||||||
val output = compileKotlin("source.kt", tmpdir, listOf(library))
|
|
||||||
KotlinTestUtils.assertEqualsToFile(File(testDataDirectory, "output.txt"), normalizeOutput(output))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun doTestBrokenKotlinLibrary(libraryName: String, vararg pathsToDelete: String) {
|
private fun doTestBrokenKotlinLibrary(libraryName: String, vararg pathsToDelete: String) {
|
||||||
// Analogous to doTestBrokenJavaLibrary, but with a Kotlin library compiled to a JAR file
|
// Analogous to doTestBrokenJavaLibrary, but with a Kotlin library compiled to a JAR file
|
||||||
val library = copyJarFileWithoutEntry(compileLibrary(libraryName), *pathsToDelete)
|
val library = copyJarFileWithoutEntry(compileLibrary(libraryName), *pathsToDelete)
|
||||||
val output = compileKotlin("source.kt", tmpdir, listOf(library))
|
compileKotlin("source.kt", tmpdir, listOf(library))
|
||||||
KotlinTestUtils.assertEqualsToFile(File(testDataDirectory, "output.txt"), normalizeOutput(output))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun doTestKotlinLibraryWithWrongMetadataVersion(
|
private fun doTestKotlinLibraryWithWrongMetadataVersion(
|
||||||
@@ -180,8 +182,7 @@ class CompileKotlinAgainstCustomBinariesTest : TestCaseWithTmpdir() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
val output = compileKotlin("source.kt", tmpdir, listOf(library), K2JVMCompiler(), additionalOptions.toList())
|
compileKotlin("source.kt", tmpdir, listOf(library), K2JVMCompiler(), additionalOptions.toList())
|
||||||
KotlinTestUtils.assertEqualsToFile(File(testDataDirectory, "output.txt"), normalizeOutput(output))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun doTestKotlinLibraryWithWrongMetadataVersionJs(libraryName: String, vararg additionalOptions: String) {
|
private fun doTestKotlinLibraryWithWrongMetadataVersionJs(libraryName: String, vararg additionalOptions: String) {
|
||||||
@@ -193,8 +194,7 @@ class CompileKotlinAgainstCustomBinariesTest : TestCaseWithTmpdir() {
|
|||||||
"(" + JsMetadataVersion(42, 0, 0).toInteger() + ", "
|
"(" + JsMetadataVersion(42, 0, 0).toInteger() + ", "
|
||||||
), Charsets.UTF_8)
|
), Charsets.UTF_8)
|
||||||
|
|
||||||
val output = compileKotlin("source.kt", File(tmpdir, "usage.js"), listOf(library), K2JSCompiler(), additionalOptions.toList())
|
compileKotlin("source.kt", File(tmpdir, "usage.js"), listOf(library), K2JSCompiler(), additionalOptions.toList())
|
||||||
KotlinTestUtils.assertEqualsToFile(File(testDataDirectory, "output.txt"), normalizeOutput(output))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun doTestPreReleaseKotlinLibrary(
|
private fun doTestPreReleaseKotlinLibrary(
|
||||||
@@ -215,33 +215,21 @@ class CompileKotlinAgainstCustomBinariesTest : TestCaseWithTmpdir() {
|
|||||||
System.clearProperty(TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY)
|
System.clearProperty(TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY)
|
||||||
}
|
}
|
||||||
|
|
||||||
val output: Pair<String, ExitCode>
|
|
||||||
try {
|
try {
|
||||||
System.setProperty(TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY, "false")
|
System.setProperty(TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY, "false")
|
||||||
output = compileKotlin("source.kt", usageDestination, listOf(result), compiler, additionalOptions.toList())
|
compileKotlin("source.kt", usageDestination, listOf(result), compiler, additionalOptions.toList())
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
System.clearProperty(TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY)
|
System.clearProperty(TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY)
|
||||||
}
|
}
|
||||||
|
|
||||||
KotlinTestUtils.assertEqualsToFile(File(testDataDirectory, "output.txt"), normalizeOutput(output))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------
|
||||||
|
|
||||||
fun testRawTypes() {
|
fun testRawTypes() {
|
||||||
KotlinTestUtils.compileJavaFiles(
|
val libraryOutput = compileJava("library")
|
||||||
listOf(File(testDataDirectory.toString() + "/library/test/A.java")),
|
compileKotlin("library", libraryOutput, listOf(libraryOutput))
|
||||||
listOf("-d", tmpdir.path)
|
compileKotlin("main.kt", tmpdir, listOf(libraryOutput))
|
||||||
)
|
|
||||||
|
|
||||||
val outputLib = compileKotlin("library/test/lib.kt", tmpdir, listOf(tmpdir))
|
|
||||||
|
|
||||||
val outputMain = compileKotlin("main.kt", tmpdir, listOf(tmpdir))
|
|
||||||
|
|
||||||
KotlinTestUtils.assertEqualsToFile(
|
|
||||||
File(testDataDirectory, "output.txt"), normalizeOutput(outputLib) + "\n" + normalizeOutput(outputMain)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testDuplicateObjectInBinaryAndSources() {
|
fun testDuplicateObjectInBinaryAndSources() {
|
||||||
@@ -271,12 +259,8 @@ class CompileKotlinAgainstCustomBinariesTest : TestCaseWithTmpdir() {
|
|||||||
// This test checks that there are no PARAMETER_NAME_CHANGED_ON_OVERRIDE or DIFFERENT_NAMES_FOR_THE_SAME_PARAMETER_IN_SUPERTYPES
|
// This test checks that there are no PARAMETER_NAME_CHANGED_ON_OVERRIDE or DIFFERENT_NAMES_FOR_THE_SAME_PARAMETER_IN_SUPERTYPES
|
||||||
// warnings when subclassing in Kotlin from Java binaries (in case when no parameter names are available for Java classes)
|
// warnings when subclassing in Kotlin from Java binaries (in case when no parameter names are available for Java classes)
|
||||||
|
|
||||||
KotlinTestUtils.compileJavaFiles(
|
val libraryOutput = compileJava("library")
|
||||||
listOf(getTestDataFileWithExtension("java")),
|
val environment = createEnvironment(listOf(libraryOutput))
|
||||||
listOf("-d", tmpdir.path)
|
|
||||||
)
|
|
||||||
|
|
||||||
val environment = createEnvironment(listOf(tmpdir))
|
|
||||||
|
|
||||||
val ktFile = KotlinTestUtils.loadJetFile(environment.project, getTestDataFileWithExtension("kt"))
|
val ktFile = KotlinTestUtils.loadJetFile(environment.project, getTestDataFileWithExtension("kt"))
|
||||||
val result = JvmResolveUtil.analyze(ktFile, environment)
|
val result = JvmResolveUtil.analyze(ktFile, environment)
|
||||||
@@ -315,8 +299,7 @@ class CompileKotlinAgainstCustomBinariesTest : TestCaseWithTmpdir() {
|
|||||||
"a/A.class", "a/A\$Inner.class", "a/AA.class", "a/AA\$Inner.class")
|
"a/A.class", "a/A\$Inner.class", "a/AA.class", "a/AA\$Inner.class")
|
||||||
val library2 = copyJarFileWithoutEntry(compileLibrary("library2"),
|
val library2 = copyJarFileWithoutEntry(compileLibrary("library2"),
|
||||||
"a/A.class", "a/A\$Inner.class", "a/AA.class", "a/AA\$Inner.class")
|
"a/A.class", "a/A\$Inner.class", "a/AA.class", "a/AA\$Inner.class")
|
||||||
val output = compileKotlin("source.kt", tmpdir, listOf(library1, library2))
|
compileKotlin("source.kt", tmpdir, listOf(library1, library2))
|
||||||
KotlinTestUtils.assertEqualsToFile(File(testDataDirectory, "output.txt"), normalizeOutput(output))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testMissingDependencyJava() {
|
fun testMissingDependencyJava() {
|
||||||
@@ -326,8 +309,7 @@ class CompileKotlinAgainstCustomBinariesTest : TestCaseWithTmpdir() {
|
|||||||
fun testMissingDependencyJavaConflictingLibraries() {
|
fun testMissingDependencyJavaConflictingLibraries() {
|
||||||
val library1 = deletePaths(compileJava("library1"), "test/A.class", "test/A\$Inner.class")
|
val library1 = deletePaths(compileJava("library1"), "test/A.class", "test/A\$Inner.class")
|
||||||
val library2 = deletePaths(compileJava("library2"), "test/A.class", "test/A\$Inner.class")
|
val library2 = deletePaths(compileJava("library2"), "test/A.class", "test/A\$Inner.class")
|
||||||
val output = compileKotlin("source.kt", tmpdir, listOf(library1, library2))
|
compileKotlin("source.kt", tmpdir, listOf(library1, library2))
|
||||||
KotlinTestUtils.assertEqualsToFile(File(testDataDirectory, "output.txt"), normalizeOutput(output))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testMissingDependencyJavaNestedAnnotation() {
|
fun testMissingDependencyJavaNestedAnnotation() {
|
||||||
@@ -457,36 +439,20 @@ class CompileKotlinAgainstCustomBinariesTest : TestCaseWithTmpdir() {
|
|||||||
|
|
||||||
fun testProhibitNestedClassesByDollarName() {
|
fun testProhibitNestedClassesByDollarName() {
|
||||||
val library = compileLibrary("library")
|
val library = compileLibrary("library")
|
||||||
|
val javaLibraryOutput = compileJava("library")
|
||||||
KotlinTestUtils.compileJavaFiles(
|
compileKotlin("main.kt", tmpdir, listOf(javaLibraryOutput, library))
|
||||||
listOf(File(testDataDirectory.toString() + "/library/test/JavaOuter.java")),
|
|
||||||
listOf("-d", tmpdir.path)
|
|
||||||
)
|
|
||||||
|
|
||||||
val outputMain = compileKotlin("main.kt", tmpdir, listOf(tmpdir, library))
|
|
||||||
|
|
||||||
KotlinTestUtils.assertEqualsToFile(
|
|
||||||
File(testDataDirectory, "output.txt"), normalizeOutput(outputMain)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testTypeAliasesAreInvisibleInCompatibilityMode() {
|
fun testTypeAliasesAreInvisibleInCompatibilityMode() {
|
||||||
compileKotlin("typeAliases.kt", tmpdir)
|
val library = compileLibrary("typeAliases.kt")
|
||||||
|
compileKotlin("main.kt", tmpdir, listOf(library), K2JVMCompiler(), listOf("-language-version", "1.0"))
|
||||||
val outputMain = compileKotlin("main.kt", tmpdir, listOf(tmpdir), K2JVMCompiler(), listOf("-language-version", "1.0"))
|
|
||||||
|
|
||||||
KotlinTestUtils.assertEqualsToFile(
|
|
||||||
File(testDataDirectory, "output.txt"), normalizeOutput(outputMain)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testInnerClassPackageConflict() {
|
fun testInnerClassPackageConflict() {
|
||||||
compileJava("library")
|
val output = compileJava("library")
|
||||||
File(testDataDirectory, "library/test/Foo/x.txt").copyTo(File(tmpdir, "library/test/Foo/x.txt"))
|
File(testDataDirectory, "library/test/Foo/x.txt").copyTo(File(output, "test/Foo/x.txt"))
|
||||||
MockLibraryUtil.createJarFile(tmpdir, File(tmpdir, "library"), null, "library", false)
|
MockLibraryUtil.createJarFile(tmpdir, output, null, "library", false)
|
||||||
val jarPath = File(tmpdir, "library.jar")
|
compileKotlin("source.kt", tmpdir, listOf(File(tmpdir, "library.jar")))
|
||||||
val output = compileKotlin("source.kt", tmpdir, listOf(jarPath))
|
|
||||||
KotlinTestUtils.assertEqualsToFile(File(testDataDirectory, "output.txt"), normalizeOutput(output))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testInnerClassPackageConflict2() {
|
fun testInnerClassPackageConflict2() {
|
||||||
@@ -505,18 +471,12 @@ class CompileKotlinAgainstCustomBinariesTest : TestCaseWithTmpdir() {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
val output = compileKotlin("source.kt", tmpdir, listOf(library1))
|
compileKotlin("source.kt", tmpdir, listOf(library1))
|
||||||
KotlinTestUtils.assertEqualsToFile(File(testDataDirectory, "output.txt"), normalizeOutput(output))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testWrongInlineTarget() {
|
fun testWrongInlineTarget() {
|
||||||
val library = compileLibrary("library", additionalOptions = listOf("-jvm-target", "1.8"))
|
val library = compileLibrary("library", additionalOptions = listOf("-jvm-target", "1.8"))
|
||||||
|
compileKotlin("source.kt", tmpdir, listOf(library))
|
||||||
val outputMain = compileKotlin("source.kt", tmpdir, listOf(library))
|
|
||||||
|
|
||||||
KotlinTestUtils.assertEqualsToFile(
|
|
||||||
File(testDataDirectory, "output.txt"), normalizeOutput(outputMain)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
Reference in New Issue
Block a user