Replace "PATH" literals with a constant

This commit is contained in:
Kurtis Rader 2020-08-14 21:49:00 -07:00 committed by Qi Xiao
parent 19f315e28a
commit b2c7746bf6
4 changed files with 8 additions and 6 deletions

View File

@ -77,8 +77,8 @@ func TestMakeHasCommand(t *testing.T) {
// Set up environment.
testDir, cleanup := util.InTestDir()
defer cleanup()
oldPath := os.Getenv("PATH")
defer os.Setenv("PATH", oldPath)
oldPath := os.Getenv(util.EnvPATH)
defer os.Setenv(util.EnvPATH, oldPath)
if runtime.GOOS == "windows" {
oldPathExt := os.Getenv("PATHEXT")
defer os.Setenv("PATHEXT", oldPathExt)
@ -87,7 +87,7 @@ func TestMakeHasCommand(t *testing.T) {
}
// Set up a directory in PATH.
os.Setenv("PATH", filepath.Join(testDir, "bin"))
os.Setenv(util.EnvPATH, filepath.Join(testDir, "bin"))
mustMkdirAll("bin")
mustMkExecutable("bin/external")
mustMkExecutable("bin/@external")

View File

@ -5,10 +5,11 @@ import (
"testing"
"github.com/elves/elvish/pkg/eval/vals"
"github.com/elves/elvish/pkg/util"
)
func TestBuiltinFnEnv(t *testing.T) {
oldpath := os.Getenv("PATH")
oldpath := os.Getenv(util.EnvPATH)
listSep := string(os.PathListSeparator)
Test(t,
That(`get-env var`).ThrowsCause(errNonExistentEnvVar),
@ -29,5 +30,5 @@ func TestBuiltinFnEnv(t *testing.T) {
That(`paths = [/test-path2 $@paths]`),
That(`get-env PATH`).Puts("/test-path2"+listSep+"/test-path"),
)
os.Setenv("PATH", oldpath)
os.Setenv(util.EnvPATH, oldpath)
}

View File

@ -248,7 +248,7 @@ func (ev *Evaler) SetLibDir(libDir string) {
}
func searchPaths() []string {
return strings.Split(os.Getenv("PATH"), ":")
return strings.Split(os.Getenv(util.EnvPATH), ":")
}
// growPorts makes the size of ec.ports at least n, adding nil's if necessary.

View File

@ -4,6 +4,7 @@ package util
// Environment variables with special significance to Elvish.
const (
EnvHOME = "HOME"
EnvPATH = "PATH"
EnvPWD = "PWD"
EnvSHLVL = "SHLVL"
)