Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Borja Lorente committed Jan 25, 2024
1 parent 01a8224 commit 158cf4f
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com.intellij.openapi.util.WriteExternalException;
import javax.swing.JComponent;
import org.jdom.Element;
import org.jetbrains.annotations.VisibleForTesting;

import java.util.Map;

/** State for user-defined environment variables. */
Expand Down Expand Up @@ -70,6 +72,7 @@ public RunConfigurationStateEditor getEditor(Project project) {
return new Editor();
}

@VisibleForTesting
public void setEnvVars(Map<String, String> vars) {
data = data.with(vars);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public void testEditorApplyToAndResetFromMatches() throws ConfigurationException
state.getBlazeFlagsState().setRawFlags(ImmutableList.of("--flag1", "--flag2"));
state.getExeFlagsState().setRawFlags(ImmutableList.of("--exeFlag1"));
state.getBlazeBinaryState().setBlazeBinary("/usr/bin/blaze");
state.getUserEnvVarsState().setEnvVars(ImmutableMap.of("HELLO", "world"));

editor.resetFrom(configuration);
BlazeCommandRunConfiguration readConfiguration =
Expand Down
20 changes: 20 additions & 0 deletions examples/go/with_proto/go/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,23 @@ func TestFlagMacros(t *testing.T) {
}
}
}

func TestEnvVars(t *testing.T) {
testCases := []struct {
envVar string
validation func(string) bool
error string
}{
{
envVar: "ENV_VAR_IN_PLAIN_RUN_CONFIG",
validation: func(expanded string) bool { return expanded == "it works" },
error: "Expected value to be 'it works'",
},
}
for _, testCase := range testCases {
expanded := os.Getenv(testCase.envVar)
if !testCase.validation(expanded) {
t.Errorf("Failure validating expansion for env var %s: Got, %s, error is: %s", testCase.envVar, expanded, testCase.error)
}
}
}
18 changes: 18 additions & 0 deletions examples/go/with_proto/run_configurations/test_env_vars.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<configuration default="false" name="Test Environment Variables" type="BlazeCommandRunConfigurationType"
factoryName="Bazel Command">
<blaze-settings blaze-command="test" kind="go_test" handler-id="BlazeGoRunConfigurationHandlerProvider"
context-element="$PROJECT_DIR$/../go/main_test.go#TestEnvVars">
<blaze-target>//go:go_test</blaze-target>
<blaze-user-flag>--test_env=GO_TEST_WRAP_TESTV=1</blaze-user-flag>
<blaze-user-flag>--test_env=GO_TEST_WRAP_TESTV=1</blaze-user-flag>
<blaze-user-flag>--test_filter=^TestEnvVars$</blaze-user-flag>
<env_state>
<envs>
<env name="ENV_VAR_IN_PLAIN_RUN_CONFIG" value="it works"/>
</envs>
</env_state>
</blaze-settings>
<method v="2">
<option name="Blaze.BeforeRunTask" enabled="true"/>
</method>
</configuration>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<configuration name="Bazel test go:go_test" type="BlazeCommandRunConfigurationType"
<configuration name="Test Macro Expansion" type="BlazeCommandRunConfigurationType"
factoryName="Bazel Command" nameIsGenerated="true">
<blaze-settings handler-id="BlazeGoRunConfigurationHandlerProvider" blaze-command="test"
kind="go_test">
Expand Down
7 changes: 6 additions & 1 deletion examples/go/with_proto/with_proto.bazelproject
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@ gazelle_target: //:gazelle
import_run_configurations:
# Test that validates that macro expansion works, as per issue:
# https://github.com/bazelbuild/intellij/issues/4112#event-7958662669
# This configuration should only be executed on both 'run' (the green arrow) mode.
# This configuration should only be executed on 'run' (the green arrow) mode,
# as currently macros are not expanded in debug mode.
run_configurations/test_macro_expansion.xml

# Test that validates that environment variables are received correctly
# This configuration should be run on both 'run' and 'debug' modes.
run_configurations/test_env_vars.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import com.google.idea.blaze.base.run.confighandler.BlazeCommandGenericRunConfigurationRunner.BlazeCommandRunProfileState;
import com.google.idea.blaze.base.run.confighandler.BlazeCommandRunConfigurationRunner;
import com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState;
import com.google.idea.blaze.base.run.state.EnvironmentVariablesState;
import com.google.idea.blaze.base.settings.Blaze;
import com.google.idea.blaze.base.settings.BuildSystemName;
import com.google.idea.blaze.base.sync.aspects.BuildResult;
Expand Down

0 comments on commit 158cf4f

Please sign in to comment.