Refactor debugger tests
1. Move tests to their own module 2. Avoid sharing the 'tinyApp' project between tests 3. Clean up option directive handling
This commit is contained in:
+1
-1
@@ -34,7 +34,7 @@ public abstract class AbstractBlackBoxCodegenTest extends CodegenTestCase {
|
||||
) throws Exception {
|
||||
boolean isIgnored = InTextDirectivesUtils.isIgnoredTarget(getBackend(), wholeFile);
|
||||
|
||||
compile(files, !isIgnored);
|
||||
compile(files, !isIgnored, false);
|
||||
|
||||
try {
|
||||
blackBox(!isIgnored, unexpectedBehaviour);
|
||||
|
||||
@@ -641,10 +641,10 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
|
||||
}
|
||||
|
||||
protected void compile(@NotNull List<TestFile> files) {
|
||||
compile(files, true);
|
||||
compile(files, true, false);
|
||||
}
|
||||
|
||||
protected void compile(@NotNull List<TestFile> files, boolean reportProblems) {
|
||||
protected void compile(@NotNull List<TestFile> files, boolean reportProblems, boolean dumpKotlinFiles) {
|
||||
File javaSourceDir = writeJavaFiles(files);
|
||||
|
||||
configurationKind = extractConfigurationKind(files);
|
||||
@@ -676,18 +676,16 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
|
||||
|
||||
generateClassesInFile(reportProblems);
|
||||
|
||||
if (javaSourceDir != null && javaClassesOutputDirectory == null) {
|
||||
// If there are Java files, they should be compiled against the class files produced by Kotlin, so we dump them to the disk
|
||||
File kotlinOut;
|
||||
try {
|
||||
kotlinOut = KotlinTestUtils.tmpDir(toString());
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw ExceptionUtilsKt.rethrow(e);
|
||||
}
|
||||
boolean compileJavaFiles = javaSourceDir != null && javaClassesOutputDirectory == null;
|
||||
File kotlinOut = null;
|
||||
|
||||
// If there are Java files, they should be compiled against the class files produced by Kotlin, so we dump them to the disk
|
||||
if (dumpKotlinFiles || compileJavaFiles) {
|
||||
kotlinOut = getKotlinClassesOutputDirectory();
|
||||
OutputUtilsKt.writeAllTo(classFileFactory, kotlinOut);
|
||||
}
|
||||
|
||||
if (compileJavaFiles) {
|
||||
List<String> javaClasspath = new ArrayList<>();
|
||||
javaClasspath.add(kotlinOut.getPath());
|
||||
|
||||
@@ -695,9 +693,8 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
|
||||
javaClasspath.add(ForTestCompileRuntime.androidAnnotationsForTests().getPath());
|
||||
}
|
||||
|
||||
javaClassesOutputDirectory = CodegenTestUtil.compileJava(
|
||||
findJavaSourcesInDirectory(javaSourceDir), javaClasspath, javacOptions
|
||||
);
|
||||
javaClassesOutputDirectory = getJavaClassesOutputDirectory();
|
||||
compileJava(findJavaSourcesInDirectory(javaSourceDir), javaClasspath, javacOptions, javaClassesOutputDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -801,18 +798,35 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
|
||||
}, coroutinesPackage);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected File getJavaSourcesOutputDirectory() {
|
||||
return createTempDirectory("java-files");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected File getJavaClassesOutputDirectory() {
|
||||
return createTempDirectory("java-classes");
|
||||
}
|
||||
|
||||
protected File getKotlinClassesOutputDirectory() {
|
||||
return createTempDirectory(toString());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static File createTempDirectory(String prefix) {
|
||||
try {
|
||||
return KotlinTestUtils.tmpDir(prefix);
|
||||
} catch (IOException e) {
|
||||
throw ExceptionUtilsKt.rethrow(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected static File writeJavaFiles(@NotNull List<TestFile> files) {
|
||||
protected File writeJavaFiles(@NotNull List<TestFile> files) {
|
||||
List<TestFile> javaFiles = CollectionsKt.filter(files, file -> file.name.endsWith(".java"));
|
||||
if (javaFiles.isEmpty()) return null;
|
||||
|
||||
File dir;
|
||||
try {
|
||||
dir = KotlinTestUtils.tmpDir("java-files");
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw ExceptionUtilsKt.rethrow(e);
|
||||
}
|
||||
File dir = getJavaSourcesOutputDirectory();
|
||||
|
||||
for (TestFile testFile : javaFiles) {
|
||||
File file = new File(dir, testFile.name);
|
||||
|
||||
@@ -100,11 +100,11 @@ public final class InTextDirectivesUtils {
|
||||
|
||||
@NotNull
|
||||
public static List<String> findLinesWithPrefixesRemoved(String fileText, String... prefixes) {
|
||||
return findLinesWithPrefixesRemoved(fileText, true, prefixes);
|
||||
return findLinesWithPrefixesRemoved(fileText, true, true, prefixes);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<String> findLinesWithPrefixesRemoved(String fileText, boolean trim, String... prefixes) {
|
||||
public static List<String> findLinesWithPrefixesRemoved(String fileText, boolean trim, boolean strict, String... prefixes) {
|
||||
if (prefixes.length == 0) {
|
||||
throw new IllegalArgumentException("Please specify the prefixes to check");
|
||||
}
|
||||
@@ -121,7 +121,7 @@ public final class InTextDirectivesUtils {
|
||||
Character.isWhitespace(prefix.charAt(prefix.length() - 1))) {
|
||||
result.add(trim ? noPrefixLine.trim() : StringUtil.trimTrailing(StringsKt.drop(noPrefixLine, 1)));
|
||||
break;
|
||||
} else {
|
||||
} else if (strict) {
|
||||
throw new AssertionError(
|
||||
"Line starts with prefix \"" + prefix + "\", but doesn't have space symbol after it: " + line);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user