Create KotlinCoreEnvironment a bit later in tests

Before this change, diagnostic tests with Java source files failed
because KotlinCoreEnvironment was being created in the test's setUp,
even before the test data file has been split into .java/.kt and the
resulting .java files have been copied to a temporary directory. In
KotlinCoreEnvironment's constructor, we now inspect all roots for
module-info files, which involves calling VirtualFile.getChildren on all
roots in the configuration. CoreLocalVirtualFile.getChildren is
cached on the first access, and so because the temporary directory with
.java files was empty at this point, the VirtualFile for that directory
returned empty array in getChildren later in the test, resulting in
unresolved reference errors.

This is fixed by creating the environment _after_ the .java files have
been copied to a temporary directory. Note that slow assertions for
flexible types are now enabled in KtUsefulTestCase instead of
KotlinTestWithEnvironmentManagement, because BaseDiagnosticsTest no
longer inherits from the latter
This commit is contained in:
Alexander Udalov
2017-06-22 16:22:34 +03:00
parent 03d83db660
commit 9274d963aa
9 changed files with 70 additions and 57 deletions
@@ -52,10 +52,11 @@ public abstract class AbstractCompilerLightClassTest extends KotlinMultiFileTest
@Override
protected void doMultiFileTest(File file, Map<String, ModuleAndDependencies> modules, List<Void> files) throws IOException {
KotlinCoreEnvironment environment = createEnvironment();
File expectedFile = KotlinTestUtils.replaceExtension(file, "java");
LightClassTestCommon.INSTANCE.testLightClass(expectedFile, file, s -> {
try {
return createFinder(getEnvironment()).findClass(s, GlobalSearchScope.allScope(getEnvironment().getProject()));
return createFinder(environment).findClass(s, GlobalSearchScope.allScope(environment.getProject()));
}
catch (IOException e) {
throw ExceptionUtilsKt.rethrow(e);