[KAPT] Migrate tests in kapt3-base and kapt3-cli to JUnit 5
This commit is contained in:
committed by
teamcity
parent
b7cc781e97
commit
fdf1b8b1c0
@@ -9,19 +9,23 @@ dependencies {
|
||||
compileOnly(intellijCore())
|
||||
|
||||
testImplementation(intellijCore())
|
||||
testApi(projectTests(":compiler:tests-common"))
|
||||
testApi(projectTests(":compiler"))
|
||||
testApi(commonDependency("junit:junit"))
|
||||
testApi(projectTests(":compiler:test-infrastructure-utils"))
|
||||
testApi(projectTests(":compiler:tests-common-new"))
|
||||
testApiJUnit5()
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
"main" { projectDefault() }
|
||||
"test" { projectDefault() }
|
||||
"test" {
|
||||
projectDefault()
|
||||
generatedTestDir()
|
||||
}
|
||||
}
|
||||
|
||||
testsJar()
|
||||
|
||||
projectTest {
|
||||
useJUnitPlatform()
|
||||
workingDir = rootDir
|
||||
dependsOn(":dist")
|
||||
}
|
||||
|
||||
+4
-8
@@ -4,21 +4,17 @@
|
||||
*/
|
||||
package org.jetbrains.kotlin.kapt.cli.test
|
||||
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
import org.jetbrains.kotlin.kapt.cli.transformArgs
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.junit.runner.RunWith
|
||||
import org.jetbrains.kotlin.test.services.JUnit5Assertions
|
||||
import java.io.File
|
||||
|
||||
private val LINE_SEPARATOR: String = System.getProperty("line.separator")
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners::class)
|
||||
abstract class AbstractArgumentParsingTest : TestCase() {
|
||||
fun doTest(filePath: String) {
|
||||
abstract class AbstractArgumentParsingTest {
|
||||
fun runTest(filePath: String) {
|
||||
val testFile = File(filePath)
|
||||
|
||||
val sections = Section.parse(testFile)
|
||||
@@ -29,7 +25,7 @@ abstract class AbstractArgumentParsingTest : TestCase() {
|
||||
val actualAfter = if (messageCollector.hasErrors()) messageCollector.toString() else transformedArgs.joinToString(LINE_SEPARATOR)
|
||||
val actual = sections.replacingSection("after", actualAfter).render()
|
||||
|
||||
KotlinTestUtils.assertEqualsToFile(testFile, actual)
|
||||
JUnit5Assertions.assertEqualsToFile(testFile, actual)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+24
-11
@@ -7,21 +7,34 @@ package org.jetbrains.kotlin.kapt.cli.test
|
||||
|
||||
import com.intellij.openapi.util.SystemInfo
|
||||
import org.jetbrains.kotlin.cli.common.arguments.readArgumentsFromArgFile
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.TestCaseWithTmpdir
|
||||
import org.junit.runner.RunWith
|
||||
import org.jetbrains.kotlin.test.services.JUnit5Assertions
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.TestInfo
|
||||
import java.io.File
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.jvm.optionals.getOrNull
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners::class)
|
||||
abstract class AbstractKaptToolIntegrationTest : TestCaseWithTmpdir() {
|
||||
fun doTest(filePath: String) {
|
||||
abstract class AbstractKaptToolIntegrationTest {
|
||||
private lateinit var tmpdir: File
|
||||
private lateinit var testInfo: TestInfo
|
||||
|
||||
@BeforeEach
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
fun setUp(testInfo: TestInfo) {
|
||||
this.testInfo = testInfo
|
||||
tmpdir = KtTestUtil.tmpDirForTest(
|
||||
testInfo.testClass.getOrNull()?.simpleName ?: "TEST",
|
||||
testInfo.displayName
|
||||
)
|
||||
}
|
||||
|
||||
fun runTest(filePath: String) {
|
||||
val testDir = File(filePath)
|
||||
val testFile = File(testDir, "build.txt")
|
||||
assert(testFile.isFile) { "build.txt doesn't exist" }
|
||||
|
||||
testDir.listFiles().forEach { it.copyRecursively(File(tmpdir, it.name)) }
|
||||
testDir.listFiles()?.forEach { it.copyRecursively(File(tmpdir, it.name)) }
|
||||
doTestInTempDirectory(testFile, File(tmpdir, testFile.name))
|
||||
}
|
||||
|
||||
@@ -44,7 +57,7 @@ abstract class AbstractKaptToolIntegrationTest : TestCaseWithTmpdir() {
|
||||
}
|
||||
} catch (e: GotResult) {
|
||||
val actual = sections.replacingSection("after", e.actual).render()
|
||||
KotlinTestUtils.assertEqualsToFile(originalTestFile, actual)
|
||||
JUnit5Assertions.assertEqualsToFile(originalTestFile, actual)
|
||||
return
|
||||
} catch (e: Throwable) {
|
||||
throw RuntimeException("Section ${section.name} failed:\n${section.content}", e)
|
||||
@@ -82,7 +95,7 @@ abstract class AbstractKaptToolIntegrationTest : TestCaseWithTmpdir() {
|
||||
}
|
||||
|
||||
private fun runProcess(executablePath: String, args: List<String>, outputFile: File = File(tmpdir, "processOutput.txt")) {
|
||||
fun err(message: String): Nothing = error("$message: $name (${args.joinToString(" ")})")
|
||||
fun err(message: String): Nothing = error("$message: ${testInfo.displayName} (${args.joinToString(" ")})")
|
||||
|
||||
outputFile.delete()
|
||||
|
||||
@@ -126,4 +139,4 @@ private fun preprocessPathSeparators(text: String): String = buildString {
|
||||
val transformed = if (line.startsWith("-cp ")) line.replace(':', File.pathSeparatorChar) else line
|
||||
appendLine(transformed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+9
-9
@@ -6,49 +6,49 @@
|
||||
package org.jetbrains.kotlin.kapt.cli.test;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
import org.jetbrains.kotlin.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
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 org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
/** This class is generated by {@link GenerateNewCompilerTests.kt}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("plugins/kapt3/kapt3-cli/testData/argumentParsing")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class ArgumentParsingTestGenerated extends AbstractArgumentParsingTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllFilesPresentInArgumentParsing() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/kapt3/kapt3-cli/testData/argumentParsing"), Pattern.compile("^(.+)\\.txt$"), null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("errorFlag.txt")
|
||||
public void testErrorFlag() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/argumentParsing/errorFlag.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("errorKeyValue.txt")
|
||||
public void testErrorKeyValue() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/argumentParsing/errorKeyValue.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("errorValue.txt")
|
||||
public void testErrorValue() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/argumentParsing/errorValue.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kotlincHelp.txt")
|
||||
public void testKotlincHelp() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/argumentParsing/kotlincHelp.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("simple.txt")
|
||||
public void testSimple() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/argumentParsing/simple.txt");
|
||||
+15
-9
@@ -6,79 +6,85 @@
|
||||
package org.jetbrains.kotlin.kapt.cli.test;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
import org.jetbrains.kotlin.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
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 org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
/** This class is generated by {@link GenerateNewCompilerTests.kt}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("plugins/kapt3/kapt3-cli/testData/integration")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class KaptToolIntegrationTestGenerated extends AbstractKaptToolIntegrationTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllFilesPresentInIntegration() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/kapt3/kapt3-cli/testData/integration"), Pattern.compile("^([^\\.]+)$"), null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("argfile")
|
||||
public void testArgfile() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/integration/argfile/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("correctErrorTypesOff")
|
||||
public void testCorrectErrorTypesOff() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/integration/correctErrorTypesOff/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("correctErrorTypesOn")
|
||||
public void testCorrectErrorTypesOn() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/integration/correctErrorTypesOn/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("defaultPackage")
|
||||
public void testDefaultPackage() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/integration/defaultPackage/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kotlinFileGeneration")
|
||||
public void testKotlinFileGeneration() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/integration/kotlinFileGeneration/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kotlinFileGenerationCorrectErrorTypes")
|
||||
public void testKotlinFileGenerationCorrectErrorTypes() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/integration/kotlinFileGenerationCorrectErrorTypes/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kotlinFileGenerationDefaultOutput")
|
||||
public void testKotlinFileGenerationDefaultOutput() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/integration/kotlinFileGenerationDefaultOutput/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt33800")
|
||||
public void testKt33800() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/integration/kt33800/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("separateStubAptCompilation")
|
||||
public void testSeparateStubAptCompilation() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/integration/separateStubAptCompilation/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("simple")
|
||||
public void testSimple() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/integration/simple/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("withoutService")
|
||||
public void testWithoutService() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/integration/withoutService/");
|
||||
Reference in New Issue
Block a user