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