diff --git a/pkg/runtime/internal/envdef/environment.go b/pkg/runtime/internal/envdef/environment.go index d5742ca2c0..1a1eb771bb 100644 --- a/pkg/runtime/internal/envdef/environment.go +++ b/pkg/runtime/internal/envdef/environment.go @@ -395,8 +395,10 @@ func (ed *EnvironmentDefinition) getEnvBasedOn(envLookup map[string]string) (map if len(ev.Values) > 0 { res[pev.Name] = pev.ValueString() if pev.Name != osName { - // On Windows, delete the case-insensitive version. Our case-sensitive version has already - // processed the value of the case-insensitive version. + // On Windows, delete the redundant (case-insensitive) version that our case-sensitive + // version could conflict with. (Our version has already processed the value of the + // redundant version.) + // For example, delete "Path" while preserving our "PATH". delete(res, osName) } } diff --git a/test/integration/exec_int_test.go b/test/integration/exec_int_test.go index bb4db87f50..e5edd8024c 100644 --- a/test/integration/exec_int_test.go +++ b/test/integration/exec_int_test.go @@ -178,6 +178,33 @@ func (suite *ExecIntegrationTestSuite) TestExeBatArguments() { cp.ExpectExitCode(0) } +func (suite *ExecIntegrationTestSuite) TestExec_PATH_and_Path_on_Windows() { + suite.OnlyRunForTags(tagsuite.Exec) + + if runtime.GOOS != "windows" { + suite.T().Skip("This test is only for windows") + } + + ts := e2e.New(suite.T(), false) + defer ts.Close() + + cp := ts.Spawn("checkout", "ActiveState-CLI/small-python", ".") + cp.Expect("Checked out") + cp.ExpectExitCode(0) + + cp = ts.Spawn("exec", "where", "python3") + cp.Expect(os.TempDir()) // from runtime's defined PATH + cp.ExpectExitCode(0) + + cp = ts.Spawn("exec", "where", "notepad") + cp.Expect("notepad.exe") // from OS-defined default Path + cp.ExpectExitCode(0) + + cp = ts.Spawn("exec", "where", "does-not-exist") + cp.Expect("not found") // neither on PATH or Path + cp.ExpectNotExitCode(0) +} + func TestExecIntegrationTestSuite(t *testing.T) { suite.Run(t, new(ExecIntegrationTestSuite)) }