From 3616adbe1b558f3649e4525e03101852ed7f26d5 Mon Sep 17 00:00:00 2001 From: Bogdan Mukvich Date: Tue, 12 Dec 2023 13:46:58 +0100 Subject: [PATCH] Replace single artifacts-test with test factory * Add the ability to fix all tests locally in one run ^KTI-1515 --- .../jetbrains/kotlin/code/ArtifactsTest.kt | 72 +++++++++++-------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/repo/artifacts-tests/src/test/kotlin/org/jetbrains/kotlin/code/ArtifactsTest.kt b/repo/artifacts-tests/src/test/kotlin/org/jetbrains/kotlin/code/ArtifactsTest.kt index 03d5745102b..bc289a8549c 100644 --- a/repo/artifacts-tests/src/test/kotlin/org/jetbrains/kotlin/code/ArtifactsTest.kt +++ b/repo/artifacts-tests/src/test/kotlin/org/jetbrains/kotlin/code/ArtifactsTest.kt @@ -7,11 +7,16 @@ package org.jetbrains.kotlin.code import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertEqualsToFile import org.jetbrains.kotlin.test.services.JUnit5Assertions.isTeamCityBuild +import org.junit.jupiter.api.DynamicTest +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.TestFactory import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths import java.nio.file.attribute.BasicFileAttributes -import kotlin.test.Test +import java.util.stream.Stream +import kotlin.streams.asSequence +import kotlin.streams.asStream import kotlin.test.assertTrue import kotlin.test.fail @@ -39,40 +44,49 @@ class ArtifactsTest { "org.jetbrains.kotlin.fus-statistics-gradle-plugin.gradle.plugin", ) - @Test - fun verifyArtifactFiles() { - val visitedPoms = mutableSetOf() - val actualPoms = Files.find( - localRepoPath, - Integer.MAX_VALUE, - { path: Path, fileAttributes: BasicFileAttributes -> - fileAttributes.isRegularFile - && "${path.fileName}".endsWith(".pom", ignoreCase = true) - && path.contains(Paths.get(kotlinVersion)) - }) - actualPoms.forEach { actual -> + @TestFactory + fun generateArtifactTests(): Stream { + return findActualPoms().map { actual -> val expectedPomPath = actual.toExpectedPath() - if ("${expectedPomPath.parent.fileName}" !in excludedProjects) { - val actualString = actual.toFile().readText().replace(kotlinVersion, "ArtifactsTest.version") - assertEqualsToFile(expectedPomPath, actualString) - visitedPoms.add(expectedPomPath) - } else { - if (isTeamCityBuild) fail("Excluded project in actual artifacts: $actual") + DynamicTest.dynamicTest(expectedPomPath.fileName.toString()) { + if ("${expectedPomPath.parent.fileName}" !in excludedProjects) { + val actualString = actual.toFile().readText().replace(kotlinVersion, "ArtifactsTest.version") + assertEqualsToFile(expectedPomPath, actualString) + } else { + if (isTeamCityBuild) fail("Excluded project in actual artifacts: $actual") + } } - } + }.asStream() + } - val expectedPoms = Files.find( - expectedRepoPath, - Integer.MAX_VALUE, - { path: Path, fileAttributes: BasicFileAttributes -> - fileAttributes.isRegularFile - && "${path.fileName}".endsWith(".pom", ignoreCase = true) - }) - expectedPoms.forEach { - assertTrue(it in visitedPoms, "Missing actual pom for expected pom: $it") + @Test + fun allExpectedPomsPresentInActual() { + val publishedPoms = findActualPoms() + .map { it.toExpectedPath() } + .filter { "${it.parent.fileName}" !in excludedProjects }.toSet() + + findExpectedPoms().forEach { expected -> + assertTrue(expected in publishedPoms, "Missing actual pom for expected pom: $expected") } } + private fun findActualPoms() = Files.find( + localRepoPath, + Integer.MAX_VALUE, + { path: Path, fileAttributes: BasicFileAttributes -> + fileAttributes.isRegularFile + && "${path.fileName}".endsWith(".pom", ignoreCase = true) + && path.contains(Paths.get(kotlinVersion)) + }).asSequence() + + private fun findExpectedPoms() = Files.find( + expectedRepoPath, + Integer.MAX_VALUE, + { path: Path, fileAttributes: BasicFileAttributes -> + fileAttributes.isRegularFile + && "${path.fileName}".endsWith(".pom", ignoreCase = true) + }).asSequence() + /** * convert: * ${mavenLocal}/org/jetbrains/kotlin/artifact/version/artifact-version.pom