[Tests] Introduce runTest with transformer to old testing framework
This commit is contained in:
@@ -48,6 +48,7 @@ import java.net.MalformedURLException;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.jetbrains.kotlin.cli.common.output.OutputUtilsKt.writeAllTo;
|
import static org.jetbrains.kotlin.cli.common.output.OutputUtilsKt.writeAllTo;
|
||||||
@@ -515,9 +516,13 @@ public abstract class CodegenTestCase extends KotlinBaseTest<KotlinBaseTest.Test
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doTest(@NotNull String filePath) throws Exception {
|
protected void doTest(@NotNull String filePath) throws Exception {
|
||||||
|
doTestWithTransformer(filePath, s -> s);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doTestWithTransformer(@NotNull String filePath, @NotNull Function<String, String> sourceTransformer) throws Exception {
|
||||||
File file = new File(filePath);
|
File file = new File(filePath);
|
||||||
|
|
||||||
String expectedText = KtTestUtil.doLoadFile(file);
|
String expectedText = sourceTransformer.apply(KtTestUtil.doLoadFile(file));
|
||||||
List<TestFile> testFiles = createTestFilesFromFile(file, expectedText);
|
List<TestFile> testFiles = createTestFilesFromFile(file, expectedText);
|
||||||
|
|
||||||
doMultiFileTest(file, testFiles);
|
doMultiFileTest(file, testFiles);
|
||||||
|
|||||||
+4
-3
@@ -18,15 +18,16 @@ object RunTestMethodGenerator : MethodGenerator<RunTestMethodModel>() {
|
|||||||
|
|
||||||
override fun generateBody(method: RunTestMethodModel, p: Printer) {
|
override fun generateBody(method: RunTestMethodModel, p: Printer) {
|
||||||
with(method) {
|
with(method) {
|
||||||
val transformerPostfix = if (method.withTransformer) ", transformer" else ""
|
val modifiedTestMethodName =
|
||||||
|
if (withTransformer) "path -> ${testMethodName}WithTransformer(path, transformer)" else "this::$testMethodName"
|
||||||
if (!isWithTargetBackend()) {
|
if (!isWithTargetBackend()) {
|
||||||
p.println("KotlinTestUtils.${method.testRunnerMethodName}(this::$testMethodName, this, testDataFilePath$transformerPostfix);")
|
p.println("KotlinTestUtils.$testRunnerMethodName($modifiedTestMethodName, this, testDataFilePath);")
|
||||||
} else {
|
} else {
|
||||||
val className = TargetBackend::class.java.simpleName
|
val className = TargetBackend::class.java.simpleName
|
||||||
val additionalArguments = if (additionalRunnerArguments.isNotEmpty())
|
val additionalArguments = if (additionalRunnerArguments.isNotEmpty())
|
||||||
additionalRunnerArguments.joinToString(separator = ", ", prefix = ", ")
|
additionalRunnerArguments.joinToString(separator = ", ", prefix = ", ")
|
||||||
else ""
|
else ""
|
||||||
p.println("KotlinTestUtils.$testRunnerMethodName(this::$testMethodName, $className.$targetBackend, testDataFilePath$additionalArguments$transformerPostfix);")
|
p.println("KotlinTestUtils.$testRunnerMethodName($modifiedTestMethodName, $className.$targetBackend, testDataFilePath$additionalArguments);")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -430,11 +430,7 @@ public class KotlinTestUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void runTest(@NotNull DoTest test, @NotNull TestCase testCase, @TestDataFile String testDataFile) throws Exception {
|
public static void runTest(@NotNull DoTest test, @NotNull TestCase testCase, @TestDataFile String testDataFile) throws Exception {
|
||||||
runTestImpl(testWithCustomIgnoreDirective(test, TargetBackend.ANY, IGNORE_BACKEND_DIRECTIVE_PREFIX), testCase, testDataFile, null);
|
runTestImpl(testWithCustomIgnoreDirective(test, TargetBackend.ANY, IGNORE_BACKEND_DIRECTIVE_PREFIX), testCase, testDataFile);
|
||||||
}
|
|
||||||
|
|
||||||
public static void runTest(@NotNull DoTest test, @NotNull TestCase testCase, @TestDataFile String testDataFile, @NotNull Function<String, String> contentTransformer) throws Exception {
|
|
||||||
runTestImpl(testWithCustomIgnoreDirective(test, TargetBackend.ANY, IGNORE_BACKEND_DIRECTIVE_PREFIX), testCase, testDataFile, contentTransformer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void runTest(@NotNull TestCase testCase, @NotNull Function0<Unit> test) {
|
public static void runTest(@NotNull TestCase testCase, @NotNull Function0<Unit> test) {
|
||||||
@@ -459,15 +455,8 @@ public class KotlinTestUtils {
|
|||||||
runTest0(test, targetBackend, testDataFile);
|
runTest0(test, targetBackend, testDataFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void runTest(
|
|
||||||
DoTest test, TargetBackend targetBackend, @TestDataFile String testDataFile,
|
|
||||||
@NotNull Function<String, String> contentTransformer
|
|
||||||
) throws Exception {
|
|
||||||
runTest0(test, targetBackend, testDataFile, contentTransformer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void runTestWithCustomIgnoreDirective(DoTest test, TargetBackend targetBackend, @TestDataFile String testDataFile, String ignoreDirective) throws Exception {
|
public static void runTestWithCustomIgnoreDirective(DoTest test, TargetBackend targetBackend, @TestDataFile String testDataFile, String ignoreDirective) throws Exception {
|
||||||
runTestImpl(testWithCustomIgnoreDirective(test, targetBackend, ignoreDirective), null, testDataFile, null);
|
runTestImpl(testWithCustomIgnoreDirective(test, targetBackend, ignoreDirective), null, testDataFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
// In this test runner version, NONE of the parameters are annotated by `TestDataFile`.
|
// In this test runner version, NONE of the parameters are annotated by `TestDataFile`.
|
||||||
@@ -479,16 +468,10 @@ public class KotlinTestUtils {
|
|||||||
// * sometimes, for too common/general names, it shows many variants to navigate
|
// * sometimes, for too common/general names, it shows many variants to navigate
|
||||||
// * it adds an additional step for navigation -- you must choose an exact file to navigate
|
// * it adds an additional step for navigation -- you must choose an exact file to navigate
|
||||||
public static void runTest0(DoTest test, TargetBackend targetBackend, String testDataFilePath) throws Exception {
|
public static void runTest0(DoTest test, TargetBackend targetBackend, String testDataFilePath) throws Exception {
|
||||||
runTestImpl(testWithCustomIgnoreDirective(test, targetBackend, IGNORE_BACKEND_DIRECTIVE_PREFIX), null, testDataFilePath, null);
|
runTestImpl(testWithCustomIgnoreDirective(test, targetBackend, IGNORE_BACKEND_DIRECTIVE_PREFIX), null, testDataFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void runTest0(
|
private static void runTestImpl(@NotNull DoTest test, @Nullable TestCase testCase, String testDataFilePath) throws Exception {
|
||||||
DoTest test, TargetBackend targetBackend, String testDataFilePath, @NotNull Function<String, String> contentTransformer
|
|
||||||
) throws Exception {
|
|
||||||
runTestImpl(testWithCustomIgnoreDirective(test, targetBackend, IGNORE_BACKEND_DIRECTIVE_PREFIX), null, testDataFilePath, contentTransformer);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void runTestImpl(@NotNull DoTest test, @Nullable TestCase testCase, String testDataFilePath, @SuppressWarnings("unused") @Nullable Function<String, String> contentTransformer) throws Exception {
|
|
||||||
if (testCase != null && !isRunTestOverridden(testCase)) {
|
if (testCase != null && !isRunTestOverridden(testCase)) {
|
||||||
Function0<Unit> wrapWithMuteInDatabase = MuteWithDatabaseKt.wrapWithMuteInDatabase(testCase, () -> {
|
Function0<Unit> wrapWithMuteInDatabase = MuteWithDatabaseKt.wrapWithMuteInDatabase(testCase, () -> {
|
||||||
try {
|
try {
|
||||||
|
|||||||
+1
-1
@@ -15741,7 +15741,7 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void runTest(String testDataFilePath, java.util.function.Function<String, String> transformer) throws Exception {
|
private void runTest(String testDataFilePath, java.util.function.Function<String, String> transformer) throws Exception {
|
||||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath, transformer);
|
KotlinTestUtils.runTest(path -> doTestWithTransformer(path, transformer), TargetBackend.JVM, testDataFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAllFilesPresentInInlineClasses() throws Exception {
|
public void testAllFilesPresentInInlineClasses() throws Exception {
|
||||||
|
|||||||
@@ -55,11 +55,12 @@ abstract class BasicWasmBoxTest(
|
|||||||
TODO("TestWithCoroutinesPackageReplacement are not supported")
|
TODO("TestWithCoroutinesPackageReplacement are not supported")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun doTest(filePath: String) {
|
fun doTest(filePath: String) = doTestWithTransformer(filePath) { it }
|
||||||
|
fun doTestWithTransformer(filePath: String, transformer: java.util.function.Function<String, String>) {
|
||||||
val file = File(filePath)
|
val file = File(filePath)
|
||||||
|
|
||||||
val outputDir = getOutputDir(file)
|
val outputDir = getOutputDir(file)
|
||||||
val fileContent = KtTestUtil.doLoadFile(file)
|
val fileContent = transformer.apply(KtTestUtil.doLoadFile(file))
|
||||||
|
|
||||||
TestFileFactoryImpl().use { testFactory ->
|
TestFileFactoryImpl().use { testFactory ->
|
||||||
val inputFiles: MutableList<TestFile> = TestFiles.createTestFiles(file.name, fileContent, testFactory, true)
|
val inputFiles: MutableList<TestFile> = TestFiles.createTestFiles(file.name, fileContent, testFactory, true)
|
||||||
|
|||||||
+1
-1
@@ -12423,7 +12423,7 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void runTest(String testDataFilePath, java.util.function.Function<String, String> transformer) throws Exception {
|
private void runTest(String testDataFilePath, java.util.function.Function<String, String> transformer) throws Exception {
|
||||||
KotlinTestUtils.runTest0(this::doTest, TargetBackend.WASM, testDataFilePath, transformer);
|
KotlinTestUtils.runTest0(path -> doTestWithTransformer(path, transformer), TargetBackend.WASM, testDataFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAllFilesPresentInInlineClasses() throws Exception {
|
public void testAllFilesPresentInInlineClasses() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user