From 4f6c1a02b0805ca3c88058b4f3b21152ac1837b0 Mon Sep 17 00:00:00 2001 From: Tomasz Pasternak Date: Tue, 26 Sep 2023 13:26:42 +0200 Subject: [PATCH] Prepare for 2023.3: Do not depend on MacroManager.getInstance() Probably caused by this change https://github.com/JetBrains/intellij-community/commit/b3ed61706fbed5e04c88d1ab3f69160246fd87e8#diff-737d7a5e2b283fc8b2a9c7f301e689e29a83629c1a3533053b813570da2e59f4R21 Before that, MacroManager was instantiated only if it was present in LangExtensions.xml (not a thing in Bazel Plugin tests). Now, it is instantiated always, which results in a crash in expandMacros call in tests. Hence, we need a new way to disable macro expansion in tests. --- .../com/google/idea/blaze/base/command/BlazeFlags.java | 10 +--------- .../unit/com/google/idea/blaze/base/BlazeTestCase.java | 2 ++ 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/base/src/com/google/idea/blaze/base/command/BlazeFlags.java b/base/src/com/google/idea/blaze/base/command/BlazeFlags.java index 6aa5c5f6cb3..8925b3485e1 100644 --- a/base/src/com/google/idea/blaze/base/command/BlazeFlags.java +++ b/base/src/com/google/idea/blaze/base/command/BlazeFlags.java @@ -23,11 +23,10 @@ import com.google.idea.blaze.base.projectview.section.sections.SyncFlagsSection; import com.google.idea.blaze.base.projectview.section.sections.TestFlagsSection; import com.google.idea.blaze.base.scope.BlazeContext; -import com.intellij.execution.configurations.ParametersList; import com.intellij.execution.util.ProgramParametersConfigurator; -import com.intellij.ide.macro.MacroManager; import com.intellij.openapi.project.Project; import com.intellij.util.PlatformUtils; + import java.util.ArrayList; import java.util.List; @@ -124,13 +123,6 @@ public static String getToolTagFlag() { /** Expands any macros in the passed build flags. */ public static List expandBuildFlags(List flags) { - // The code below depends on there being a globally registered `MacroManager`. - // `MacroManager` is a final class with a private constructor, and therefore it can't be mocked. - // We have tests that manipulate flags, but are not interested in exercising this code. - // Therefore, we return early in those cases. - if (MacroManager.getInstance() == null) { - return flags; - } // This built-in IntelliJ class will do macro expansion using // both your environment and your Settings > Behavior > Path Variables List expandedFlags = new ArrayList<>(); diff --git a/base/tests/utils/unit/com/google/idea/blaze/base/BlazeTestCase.java b/base/tests/utils/unit/com/google/idea/blaze/base/BlazeTestCase.java index 95565e79968..f44b3618ed1 100644 --- a/base/tests/utils/unit/com/google/idea/blaze/base/BlazeTestCase.java +++ b/base/tests/utils/unit/com/google/idea/blaze/base/BlazeTestCase.java @@ -33,6 +33,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.SystemInfo; +import com.intellij.openapi.util.registry.Registry; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -94,6 +95,7 @@ public void register(Class klass, T instance) { @Before public final void setup() { + Registry.get("allow.macros.for.run.configurations").setValue(false); testDisposable = new RootDisposable(); MockApplication application = TestUtils.createMockApplication(testDisposable); MockProject mockProject = TestUtils.mockProject(application.getPicoContainer(), testDisposable);