[Test] Migrate SpecTestsConsistencyTest to JUnit5

This commit is contained in:
Dmitriy Novozhilov
2021-07-05 10:30:09 +03:00
parent c0c9e4a114
commit d473d22d8c
2 changed files with 14 additions and 21 deletions
+4 -4
View File
@@ -7,10 +7,8 @@ dependencies {
testCompile(projectTests(":compiler"))
testImplementation(projectTests(":compiler:test-infrastructure"))
testImplementation(projectTests(":compiler:tests-common-new"))
testRuntimeOnly(platform("org.junit:junit-bom:5.7.0"))
testRuntimeOnly("org.junit.jupiter:junit-jupiter")
testCompileOnly(intellijDep()) {
testCompile(intellijDep()) {
includeJars("groovy", "groovy-xml", rootProject = rootProject)
}
testCompile(intellijDep()) {
@@ -21,6 +19,8 @@ dependencies {
compile("org.jsoup:jsoup:1.10.3")
if (isIdeaActive) testRuntimeOnly(files("${rootProject.projectDir}/dist/kotlinc/lib/kotlin-reflect.jar"))
testRuntime(project(":kotlin-reflect"))
testApiJUnit5(vintageEngine = true)
}
sourceSets {
@@ -42,10 +42,10 @@ val printSpecTestsStatistic by generator("org.jetbrains.kotlin.spec.utils.tasks.
val specConsistencyTests by task<Test> {
workingDir = rootDir
filter {
includeTestsMatching("org.jetbrains.kotlin.spec.consistency.SpecTestsConsistencyTest")
}
useJUnitPlatform()
}
tasks.named<Test>("test") {
@@ -12,27 +12,19 @@ import org.jetbrains.kotlin.spec.utils.SpecTestLinkedType
import org.jetbrains.kotlin.spec.utils.TestArea
import org.jetbrains.kotlin.spec.utils.parsers.CommonParser.parseLinkedSpecTest
import org.jetbrains.kotlin.spec.utils.spec.SpecSentencesStorage
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource
import java.io.File
import java.util.stream.Stream
@TestDataPath("\$PROJECT_ROOT/compiler/tests-spec/testData/")
@RunWith(com.intellij.testFramework.Parameterized::class)
class SpecTestsConsistencyTest : TestCase() {
@org.junit.runners.Parameterized.Parameter
lateinit var testFilePath: String
companion object {
private val specSentencesStorage = SpecSentencesStorage()
@org.junit.runners.Parameterized.Parameters(name = "{0}")
@JvmStatic
fun getTestFiles() = emptyList<Array<Any>>()
@com.intellij.testFramework.Parameterized.Parameters(name = "{0}")
@JvmStatic
fun getTestFiles(@Suppress("UNUSED_PARAMETER") klass: Class<*>): List<Array<String>> {
val testFiles = mutableListOf<Array<String>>()
fun getTestFiles(): Stream<String> {
val testFiles = mutableListOf<String>()
TestArea.values().forEach { testArea ->
val testDataPath =
@@ -40,17 +32,18 @@ class SpecTestsConsistencyTest : TestCase() {
testFiles += File(testDataPath).let { testsDir ->
testsDir.walkTopDown().filter { it.extension == "kt" }.map {
arrayOf(it.relativeTo(File(GeneralConfiguration.SPEC_TESTDATA_PATH)).path.replace("/", "$"))
it.relativeTo(File(GeneralConfiguration.SPEC_TESTDATA_PATH)).path.replace("/", "$")
}.toList()
}
}
return testFiles
return testFiles.stream()
}
}
@Test
fun doTest() {
@ParameterizedTest
@MethodSource("getTestFiles")
fun doTest(testFilePath: String) {
val file = File("${GeneralConfiguration.SPEC_TESTDATA_PATH}/${testFilePath.replace("$", "/")}")
val specSentences = specSentencesStorage.getLatest() ?: return
val test = parseLinkedSpecTest(file.canonicalPath, mapOf("main" to file.readText()))