Added support for 'JVM.INHERIT_MULTIFILE_PARTS' flag in android tests

This commit is contained in:
Mikhael Bogdanov
2016-05-10 14:06:10 +03:00
parent ed60cf8c55
commit 1d2a83e182
@@ -125,27 +125,31 @@ public class CodegenTestsOnAndroidGenerator extends UsefulTestCase {
}
private void generateTestMethodsForDirectories(Printer p, File... dirs) throws IOException {
FilesWriter holderMock = new FilesWriter(false);
FilesWriter holderFull = new FilesWriter(true);
FilesWriter holderMock = new FilesWriter(false, false);
FilesWriter holderFull = new FilesWriter(true, false);
FilesWriter holderInheritMFP = new FilesWriter(true, true);
for (File dir : dirs) {
File[] files = dir.listFiles();
Assert.assertNotNull("Folder with testData is empty: " + dir.getAbsolutePath(), files);
processFiles(p, files, holderFull, holderMock);
processFiles(p, files, holderFull, holderMock, holderInheritMFP);
}
holderFull.writeFilesOnDisk();
holderMock.writeFilesOnDisk();
holderInheritMFP.writeFilesOnDisk();
}
class FilesWriter {
private final boolean isFullJdkAndRuntime;
private boolean inheritMultifileParts;
public List<KtFile> files = new ArrayList<KtFile>();
private KotlinCoreEnvironment environment;
private FilesWriter(boolean isFullJdkAndRuntime) {
private FilesWriter(boolean isFullJdkAndRuntime, boolean inheritMultifileParts) {
this.isFullJdkAndRuntime = isFullJdkAndRuntime;
this.inheritMultifileParts = inheritMultifileParts;
environment = createEnvironment(isFullJdkAndRuntime);
}
@@ -184,13 +188,18 @@ public class CodegenTestsOnAndroidGenerator extends UsefulTestCase {
private void writeFiles(List<KtFile> filesToCompile) {
if (filesToCompile.isEmpty()) return;
System.out.println("Generating " + filesToCompile.size() + " files" + (isFullJdkAndRuntime
? " (full jdk and runtime)" : "") + "...");
System.out.println("Generating " + filesToCompile.size() + " files" +
(inheritMultifileParts
? " (JVM.INHERIT_MULTIFILE_PARTS)"
: isFullJdkAndRuntime ? " (full jdk and runtime)" : "") + "...");
OutputFileCollection outputFiles;
try {
//hack to pass module name
CompilerConfiguration configuration = environment.getConfiguration().copy();
configuration.put(JVMConfigurationKeys.MODULE_NAME, "android-module-" + MODULE_INDEX++);
if (inheritMultifileParts) {
configuration.put(JVMConfigurationKeys.INHERIT_MULTIFILE_PARTS, true);
}
configuration.setReadOnly(true);
outputFiles = GenerationUtils.compileManyFilesGetGenerationStateForTest(
filesToCompile.iterator().next().getProject(),
@@ -217,11 +226,12 @@ public class CodegenTestsOnAndroidGenerator extends UsefulTestCase {
@NotNull Printer printer,
@NotNull File[] files,
@NotNull FilesWriter holderFull,
@NotNull FilesWriter holderMock)
throws IOException
{
@NotNull FilesWriter holderMock,
@NotNull FilesWriter holderInheritMFP
) throws IOException {
holderFull.writeFilesOnDiskIfNeeded();
holderMock.writeFilesOnDiskIfNeeded();
holderInheritMFP.writeFilesOnDiskIfNeeded();
for (File file : files) {
if (SpecialFiles.getExcludedFiles().contains(file.getName())) {
@@ -230,7 +240,7 @@ public class CodegenTestsOnAndroidGenerator extends UsefulTestCase {
if (file.isDirectory()) {
File[] listFiles = file.listFiles();
if (listFiles != null) {
processFiles(printer, listFiles, holderFull, holderMock);
processFiles(printer, listFiles, holderFull, holderMock, holderInheritMFP);
}
}
else if (!FileUtilRt.getExtension(file.getName()).equals(KotlinFileType.INSTANCE.getDefaultExtension())) {
@@ -245,6 +255,7 @@ public class CodegenTestsOnAndroidGenerator extends UsefulTestCase {
FilesWriter filesHolder = InTextDirectivesUtils.isDirectiveDefined(fullFileText, "FULL_JDK") ||
InTextDirectivesUtils.isDirectiveDefined(fullFileText, "WITH_RUNTIME") ||
InTextDirectivesUtils.isDirectiveDefined(fullFileText, "WITH_REFLECT") ? holderFull : holderMock;
filesHolder = fullFileText.contains("+JVM.INHERIT_MULTIFILE_PARTS") ? holderInheritMFP : filesHolder;
FqName classWithBoxMethod = AndroidTestGeneratorKt.genFiles(file, fullFileText, filesHolder);
if (classWithBoxMethod == null)