Use TargetBackend.ANY as default parameter and migrate to more generic runTest method
This commit is contained in:
@@ -707,6 +707,11 @@ public class KotlinTestUtils {
|
|||||||
void invoke(@NotNull String filePath) throws Exception;
|
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`.
|
// 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..."
|
// 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 {
|
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(
|
public static void assertAllTestsPresentByMetadata(
|
||||||
@NotNull Class<?> testCaseClass,
|
@NotNull Class<?> testCaseClass,
|
||||||
@NotNull File testDataDir,
|
@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(
|
public static void assertAllTestsPresentInSingleGeneratedClass(
|
||||||
@NotNull Class<?> testCaseClass,
|
@NotNull Class<?> testCaseClass,
|
||||||
@NotNull File testDataDir,
|
@NotNull File testDataDir,
|
||||||
|
|||||||
+9
-5
@@ -22,11 +22,15 @@ class RunTestMethodModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun generateBody(p: Printer) {
|
override fun generateBody(p: Printer) {
|
||||||
val className = TargetBackend::class.java.simpleName
|
if (targetBackend == TargetBackend.ANY && additionalRunnerArguments.isEmpty() && testRunnerMethodName == METHOD_NAME) {
|
||||||
val additionalArguments = if (additionalRunnerArguments.isNotEmpty())
|
p.println("KotlinTestUtils.$testRunnerMethodName(this::$testMethodName, this, testDataFilePath);")
|
||||||
additionalRunnerArguments.joinToString(separator = ", ", prefix = ", ")
|
} else {
|
||||||
else ""
|
val className = TargetBackend::class.java.simpleName
|
||||||
p.println("KotlinTestUtils.$testRunnerMethodName(this::$testMethodName, $className.$targetBackend, testDataFilePath$additionalArguments);")
|
val additionalArguments = if (additionalRunnerArguments.isNotEmpty())
|
||||||
|
additionalRunnerArguments.joinToString(separator = ", ", prefix = ", ")
|
||||||
|
else ""
|
||||||
|
p.println("KotlinTestUtils.$testRunnerMethodName(this::$testMethodName, $className.$targetBackend, testDataFilePath$additionalArguments);")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
+17
-5
@@ -238,11 +238,23 @@ public class SimpleTestClassModel implements TestClassModel {
|
|||||||
exclude.append(StringUtil.escapeStringCharacters(dir));
|
exclude.append(StringUtil.escapeStringCharacters(dir));
|
||||||
exclude.append("\"");
|
exclude.append("\"");
|
||||||
}
|
}
|
||||||
String assertTestsPresentStr = String.format(
|
|
||||||
"KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File(\"%s\"), Pattern.compile(\"%s\"), %s.%s, %s%s);",
|
String assertTestsPresentStr;
|
||||||
KotlinTestUtils.getFilePath(rootFile), StringUtil.escapeStringCharacters(filenamePattern.pattern()),
|
|
||||||
TargetBackend.class.getSimpleName(), targetBackend.toString(), recursive, exclude
|
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);
|
p.println(assertTestsPresentStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+14
-5
@@ -143,11 +143,20 @@ public class SingleClassTestModel implements TestClassModel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateBody(@NotNull Printer p) {
|
public void generateBody(@NotNull Printer p) {
|
||||||
String assertTestsPresentStr = String.format(
|
String assertTestsPresentStr;
|
||||||
"KotlinTestUtils.assertAllTestsPresentInSingleGeneratedClass(this.getClass(), new File(\"%s\"), Pattern.compile(\"%s\"), %s.%s);",
|
|
||||||
KotlinTestUtils.getFilePath(rootFile), StringUtil.escapeStringCharacters(filenamePattern.pattern()),
|
if (targetBackend != TargetBackend.ANY) {
|
||||||
TargetBackend.class.getSimpleName(), targetBackend.toString()
|
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);
|
p.println(assertTestsPresentStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user