[Spec tests] Make collectInfoFromTests for both spec and implementation tests
This commit is contained in:
@@ -33,6 +33,17 @@ enum class TestType(val type: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum class TestOrigin(private val testDataPath: String, private val testsPath: String? = null) {
|
||||||
|
IMPLEMENTATION(GeneralConfiguration.TESTDATA_PATH),
|
||||||
|
SPEC(GeneralConfiguration.SPEC_TESTDATA_PATH, TestsJsonMapGenerator.LINKED_TESTS_PATH);
|
||||||
|
|
||||||
|
fun getFilePath(testArea: TestArea) = buildString {
|
||||||
|
append("${testDataPath}/${testArea.testDataPath}")
|
||||||
|
if (testsPath != null)
|
||||||
|
append("/${testsPath}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
enum class TestArea(val testDataPath: String) {
|
enum class TestArea(val testDataPath: String) {
|
||||||
PSI("psi"),
|
PSI("psi"),
|
||||||
DIAGNOSTICS("diagnostics"),
|
DIAGNOSTICS("diagnostics"),
|
||||||
|
|||||||
+15
-42
@@ -16,7 +16,7 @@ import org.jetbrains.kotlin.spec.utils.parsers.LinkedSpecTestPatterns
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
object TestsJsonMapGenerator {
|
object TestsJsonMapGenerator {
|
||||||
private const val LINKED_TESTS_PATH = "linked"
|
const val LINKED_TESTS_PATH = "linked"
|
||||||
const val TESTS_MAP_FILENAME = "testsMap.json"
|
const val TESTS_MAP_FILENAME = "testsMap.json"
|
||||||
|
|
||||||
private inline fun <reified T : JsonElement> JsonObject.getOrCreate(key: String): T {
|
private inline fun <reified T : JsonElement> JsonObject.getOrCreate(key: String): T {
|
||||||
@@ -61,56 +61,29 @@ object TestsJsonMapGenerator {
|
|||||||
|
|
||||||
private fun collectInfoFromTests(
|
private fun collectInfoFromTests(
|
||||||
testsMap: JsonObject,
|
testsMap: JsonObject,
|
||||||
testDataPath: String,
|
testOrigin: TestOrigin,
|
||||||
linkedTestsPath: String = ""
|
|
||||||
) {
|
) {
|
||||||
|
val isImplementationTest = testOrigin == TestOrigin.IMPLEMENTATION
|
||||||
TestArea.values().forEach { testArea ->
|
TestArea.values().forEach { testArea ->
|
||||||
val filePath = buildString {
|
File(testOrigin.getFilePath(testArea)).walkTopDown()
|
||||||
append("${testDataPath}/${testArea.testDataPath}")
|
|
||||||
if (linkedTestsPath.isNotEmpty())
|
|
||||||
append("/${linkedTestsPath}")
|
|
||||||
}
|
|
||||||
File(filePath).walkTopDown()
|
|
||||||
.forEach testFiles@{ file ->
|
.forEach testFiles@{ file ->
|
||||||
if (!file.isFile || file.extension != "kt" || file.name.endsWith(".fir.kt")) return@testFiles
|
if (!file.isFile || file.extension != "kt" || file.name.endsWith(".fir.kt")) return@testFiles
|
||||||
val (specTest, _) = CommonParser.parseSpecTest(file.canonicalPath, mapOf("main.kt" to file.readText()))
|
if (isImplementationTest && !LinkedSpecTestPatterns.testInfoPattern.matcher(file.readText()).find())
|
||||||
if (specTest is LinkedSpecTest) {
|
|
||||||
collectInfoFromTests(testsMap = testsMap, specTest = specTest, file = file)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun collectInfoFromSpecTests(testsMap: JsonObject) {
|
|
||||||
TestArea.values().forEach { testArea ->
|
|
||||||
File("${GeneralConfiguration.SPEC_TESTDATA_PATH}/${testArea.testDataPath}/$LINKED_TESTS_PATH").walkTopDown()
|
|
||||||
.forEach testFiles@{ file ->
|
|
||||||
if (!file.isFile || file.extension != "kt" || file.name.endsWith(".fir.kt")) return@testFiles
|
|
||||||
val (specTest, _) = CommonParser.parseSpecTest(file.canonicalPath, mapOf("main.kt" to file.readText()))
|
|
||||||
if (specTest is LinkedSpecTest) {
|
|
||||||
collectInfoFromTests(testsMap = testsMap, specTest = specTest, file = file)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun collectInfoFromImplementationTests(testsMap: JsonObject) {
|
|
||||||
TestArea.values().forEach { testArea ->
|
|
||||||
File("${GeneralConfiguration.TESTDATA_PATH}/${testArea.testDataPath}").walkTopDown()
|
|
||||||
.forEach testFiles@{ file ->
|
|
||||||
if (!file.isFile || file.extension != "kt") return@testFiles
|
|
||||||
if (!LinkedSpecTestPatterns.testInfoPattern.matcher(file.readText()).find())
|
|
||||||
return@testFiles
|
return@testFiles
|
||||||
val (specTest, _) = CommonParser.parseSpecTest(file.canonicalPath, mapOf("main.kt" to file.readText()), true)
|
|
||||||
|
val (specTest, _) = CommonParser.parseSpecTest(
|
||||||
|
file.canonicalPath,
|
||||||
|
mapOf("main.kt" to file.readText()),
|
||||||
|
isImplementationTest
|
||||||
|
)
|
||||||
if (specTest is LinkedSpecTest) {
|
if (specTest is LinkedSpecTest) {
|
||||||
collectInfoFromTests(testsMap = testsMap, specTest = specTest, file = file)
|
collectInfoFromTest(testsMap, specTest, file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun collectInfoFromTest(
|
||||||
private fun collectInfoFromTests(
|
|
||||||
testsMap: JsonObject, specTest: LinkedSpecTest, file: File
|
testsMap: JsonObject, specTest: LinkedSpecTest, file: File
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@@ -128,8 +101,8 @@ object TestsJsonMapGenerator {
|
|||||||
|
|
||||||
fun buildTestsMapPerSection() {
|
fun buildTestsMapPerSection() {
|
||||||
val testsMap = JsonObject().apply {
|
val testsMap = JsonObject().apply {
|
||||||
collectInfoFromTests(this, GeneralConfiguration.SPEC_TESTDATA_PATH, LINKED_TESTS_PATH)
|
collectInfoFromTests(this, TestOrigin.SPEC)
|
||||||
collectInfoFromImplementationTests(this)
|
collectInfoFromTests(this, TestOrigin.IMPLEMENTATION)
|
||||||
}
|
}
|
||||||
|
|
||||||
val gson = GsonBuilder().setPrettyPrinting().create()
|
val gson = GsonBuilder().setPrettyPrinting().create()
|
||||||
|
|||||||
Reference in New Issue
Block a user