[AA] Fix write access configuration in unit test application environments
- We cannot configure the application's write action accessibility on a per-test basis because (1) the application may be shared across concurrent tests and (2) the application is usually cached, so the configuration will be missed entirely. - There is actually a much easier solution to allow write access selectively: We can enable it in `runWriteAction` blocks, and keep it in a thread local to support concurrent test runs. As Analysis API tests never call `runWriteAction`, there will be no "analyze cannot be called from a write action" error, and if `analyze` is somehow called from a write action, it will now be caught. ^KT-63560 fixed
This commit is contained in:
committed by
Space Team
parent
3b7f43a9c2
commit
1870189e47
+1
-1
@@ -26,7 +26,7 @@ fun TestConfigurationBuilder.registerAnalysisApiBaseTestServices(
|
||||
) {
|
||||
useAdditionalService<TestDisposableProvider>(::TestDisposableProviderImpl)
|
||||
useAdditionalService<AnalysisApiKtModuleProvider>(::AnalysisApiKtModuleProviderImpl)
|
||||
useAdditionalService<AnalysisApiEnvironmentManager>(::AnalysisApiEnvironmentManagerImpl.bind(testDisposable, configurator))
|
||||
useAdditionalService<AnalysisApiEnvironmentManager>(::AnalysisApiEnvironmentManagerImpl.bind(testDisposable))
|
||||
useAdditionalService<ApplicationDisposableProvider> { ExecutionListenerBasedDisposableProvider() }
|
||||
useAdditionalService<KotlinStandardLibrariesPathProvider> { StandardLibrariesPathProviderForKotlinProject }
|
||||
|
||||
|
||||
+1
-2
@@ -40,13 +40,12 @@ abstract class AnalysisApiEnvironmentManager : TestService {
|
||||
class AnalysisApiEnvironmentManagerImpl(
|
||||
override val testServices: TestServices,
|
||||
override val testRootDisposable: Disposable,
|
||||
private val configurator: AnalysisApiTestConfigurator,
|
||||
) : AnalysisApiEnvironmentManager() {
|
||||
private val _projectEnvironment: KotlinCoreProjectEnvironment by lazy {
|
||||
StandaloneProjectFactory.createProjectEnvironment(
|
||||
testRootDisposable,
|
||||
testServices.applicationDisposableProvider.getApplicationRootDisposable(),
|
||||
KotlinCoreApplicationEnvironmentMode.UnitTest(configurator.isWriteAccessAllowed),
|
||||
KotlinCoreApplicationEnvironmentMode.UnitTest,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
-9
@@ -36,15 +36,6 @@ abstract class AnalysisApiTestConfigurator {
|
||||
|
||||
abstract val serviceRegistrars: List<AnalysisApiTestServiceRegistrar>
|
||||
|
||||
/**
|
||||
* Whether the associated [core application environment][org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreApplicationEnvironment] should
|
||||
* permit write access.
|
||||
*
|
||||
* Write access is disabled by default because the Analysis API should not be used during write actions. Nevertheless, some tests may
|
||||
* need write access, for example to modify PSI.
|
||||
*/
|
||||
open val isWriteAccessAllowed get() = false
|
||||
|
||||
open fun prepareFilesInModule(files: List<PsiFile>, module: TestModule, testServices: TestServices) {}
|
||||
|
||||
open fun doGlobalModuleStateModification(project: Project) {
|
||||
|
||||
Reference in New Issue
Block a user