From 98ac2af402758a7bfbbefd5056af776a02815b9d Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Fri, 18 Oct 2019 13:37:59 +0300 Subject: [PATCH] Use TargetBackend.ANY as default parameter and migrate to more generic runTest method --- .../kotlin/test/KotlinTestUtils.java | 30 +++++++++++++++++++ .../tests/generator/RunTestMethodModel.kt | 14 +++++---- .../tests/generator/SimpleTestClassModel.java | 22 ++++++++++---- .../tests/generator/SingleClassTestModel.java | 19 ++++++++---- 4 files changed, 70 insertions(+), 15 deletions(-) diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java index 96f5d2fbbfb..16897dc336b 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java @@ -707,6 +707,11 @@ public class KotlinTestUtils { void invoke(@NotNull String filePath) throws Exception; } + @SuppressWarnings("unused") + public static void runTest(@NotNull DoTest test, @NotNull TestCase testCase, @TestDataFile String testDataFile) throws Exception { + runTest(test, TargetBackend.ANY, testDataFile); + } + // In this test runner version the `testDataFile` parameter is annotated by `TestDataFile`. // So only file paths passed to this parameter will be used in navigation actions, like "Navigate to testdata" and "Related Symbol..." public static void runTest(DoTest test, TargetBackend targetBackend, @TestDataFile String testDataFile) throws Exception { @@ -828,6 +833,23 @@ public class KotlinTestUtils { } } + public static void assertAllTestsPresentByMetadata( + @NotNull Class testCaseClass, + @NotNull File testDataDir, + @NotNull Pattern filenamePattern, + boolean recursive, + @NotNull String... excludeDirs + ) { + assertAllTestsPresentByMetadata( + testCaseClass, + testDataDir, + filenamePattern, + TargetBackend.ANY, + recursive, + excludeDirs + ); + } + public static void assertAllTestsPresentByMetadata( @NotNull Class testCaseClass, @NotNull File testDataDir, @@ -856,6 +878,14 @@ public class KotlinTestUtils { } } + public static void assertAllTestsPresentInSingleGeneratedClass( + @NotNull Class testCaseClass, + @NotNull File testDataDir, + @NotNull Pattern filenamePattern + ) { + assertAllTestsPresentInSingleGeneratedClass(testCaseClass, testDataDir, filenamePattern, TargetBackend.ANY); + } + public static void assertAllTestsPresentInSingleGeneratedClass( @NotNull Class testCaseClass, @NotNull File testDataDir, diff --git a/generators/test-generator/tests/org/jetbrains/kotlin/generators/tests/generator/RunTestMethodModel.kt b/generators/test-generator/tests/org/jetbrains/kotlin/generators/tests/generator/RunTestMethodModel.kt index 6eb0ba18f28..ca40a6bf96e 100644 --- a/generators/test-generator/tests/org/jetbrains/kotlin/generators/tests/generator/RunTestMethodModel.kt +++ b/generators/test-generator/tests/org/jetbrains/kotlin/generators/tests/generator/RunTestMethodModel.kt @@ -22,11 +22,15 @@ class RunTestMethodModel( } override fun generateBody(p: Printer) { - val className = TargetBackend::class.java.simpleName - val additionalArguments = if (additionalRunnerArguments.isNotEmpty()) - additionalRunnerArguments.joinToString(separator = ", ", prefix = ", ") - else "" - p.println("KotlinTestUtils.$testRunnerMethodName(this::$testMethodName, $className.$targetBackend, testDataFilePath$additionalArguments);") + if (targetBackend == TargetBackend.ANY && additionalRunnerArguments.isEmpty() && testRunnerMethodName == METHOD_NAME) { + p.println("KotlinTestUtils.$testRunnerMethodName(this::$testMethodName, this, testDataFilePath);") + } else { + val className = TargetBackend::class.java.simpleName + val additionalArguments = if (additionalRunnerArguments.isNotEmpty()) + additionalRunnerArguments.joinToString(separator = ", ", prefix = ", ") + else "" + p.println("KotlinTestUtils.$testRunnerMethodName(this::$testMethodName, $className.$targetBackend, testDataFilePath$additionalArguments);") + } } companion object { diff --git a/generators/test-generator/tests/org/jetbrains/kotlin/generators/tests/generator/SimpleTestClassModel.java b/generators/test-generator/tests/org/jetbrains/kotlin/generators/tests/generator/SimpleTestClassModel.java index 83409ffb090..fcb537ed9c8 100644 --- a/generators/test-generator/tests/org/jetbrains/kotlin/generators/tests/generator/SimpleTestClassModel.java +++ b/generators/test-generator/tests/org/jetbrains/kotlin/generators/tests/generator/SimpleTestClassModel.java @@ -238,11 +238,23 @@ public class SimpleTestClassModel implements TestClassModel { exclude.append(StringUtil.escapeStringCharacters(dir)); exclude.append("\""); } - String assertTestsPresentStr = String.format( - "KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File(\"%s\"), Pattern.compile(\"%s\"), %s.%s, %s%s);", - KotlinTestUtils.getFilePath(rootFile), StringUtil.escapeStringCharacters(filenamePattern.pattern()), - TargetBackend.class.getSimpleName(), targetBackend.toString(), recursive, exclude - ); + + String assertTestsPresentStr; + + if (targetBackend == TargetBackend.ANY) { + assertTestsPresentStr = String.format( + "KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File(\"%s\"), Pattern.compile(\"%s\"), %s%s);", + KotlinTestUtils.getFilePath(rootFile), StringUtil.escapeStringCharacters(filenamePattern.pattern()), + recursive, exclude + ); + } else { + assertTestsPresentStr = String.format( + "KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File(\"%s\"), Pattern.compile(\"%s\"), %s.%s, %s%s);", + KotlinTestUtils.getFilePath(rootFile), StringUtil.escapeStringCharacters(filenamePattern.pattern()), + TargetBackend.class.getSimpleName(), targetBackend.toString(), recursive, exclude + ); + } + p.println(assertTestsPresentStr); } diff --git a/generators/test-generator/tests/org/jetbrains/kotlin/generators/tests/generator/SingleClassTestModel.java b/generators/test-generator/tests/org/jetbrains/kotlin/generators/tests/generator/SingleClassTestModel.java index ddc680159de..35b3d565042 100644 --- a/generators/test-generator/tests/org/jetbrains/kotlin/generators/tests/generator/SingleClassTestModel.java +++ b/generators/test-generator/tests/org/jetbrains/kotlin/generators/tests/generator/SingleClassTestModel.java @@ -143,11 +143,20 @@ public class SingleClassTestModel implements TestClassModel { @Override public void generateBody(@NotNull Printer p) { - String assertTestsPresentStr = String.format( - "KotlinTestUtils.assertAllTestsPresentInSingleGeneratedClass(this.getClass(), new File(\"%s\"), Pattern.compile(\"%s\"), %s.%s);", - KotlinTestUtils.getFilePath(rootFile), StringUtil.escapeStringCharacters(filenamePattern.pattern()), - TargetBackend.class.getSimpleName(), targetBackend.toString() - ); + String assertTestsPresentStr; + + if (targetBackend != TargetBackend.ANY) { + assertTestsPresentStr = String.format( + "KotlinTestUtils.assertAllTestsPresentInSingleGeneratedClass(this.getClass(), new File(\"%s\"), Pattern.compile(\"%s\"), %s.%s);", + KotlinTestUtils.getFilePath(rootFile), StringUtil.escapeStringCharacters(filenamePattern.pattern()), + TargetBackend.class.getSimpleName(), targetBackend.toString() + ); + } else { + assertTestsPresentStr = String.format( + "KotlinTestUtils.assertAllTestsPresentInSingleGeneratedClass(this.getClass(), new File(\"%s\"), Pattern.compile(\"%s\"));", + KotlinTestUtils.getFilePath(rootFile), StringUtil.escapeStringCharacters(filenamePattern.pattern()) + ); + } p.println(assertTestsPresentStr); }