Replace "ELVISH_TEST_TIME_SCALE" literals with a constant

This commit is contained in:
Kurtis Rader 2020-08-14 22:14:51 -07:00 committed by Qi Xiao
parent 947ac39876
commit a4e539c823
3 changed files with 16 additions and 11 deletions

View File

@ -4,6 +4,8 @@ import (
"os"
"strconv"
"time"
"github.com/elves/elvish/pkg/util"
)
// ScaledMs returns ms milliseconds, scaled by the ELVISH_TEST_TIME_SCALE
@ -15,7 +17,7 @@ func ScaledMs(ms int) time.Duration {
}
func getTestTimeScale() float64 {
env := os.Getenv("ELVISH_TEST_TIME_SCALE")
env := os.Getenv(util.EnvELVISH_TEST_TIME_SCALE)
if env == "" {
return 1
}

View File

@ -4,6 +4,8 @@ import (
"os"
"testing"
"time"
"github.com/elves/elvish/pkg/util"
)
var scaledMsTests = []struct {
@ -25,12 +27,12 @@ var scaledMsTests = []struct {
}
func TestScaledMs(t *testing.T) {
envSave := os.Getenv("ELVISH_TEST_TIME_SCALE")
defer os.Setenv("ELVISH_TEST_TIME_SCALE", envSave)
envSave := os.Getenv(util.EnvELVISH_TEST_TIME_SCALE)
defer os.Setenv(util.EnvELVISH_TEST_TIME_SCALE, envSave)
for _, test := range scaledMsTests {
t.Run(test.name, func(t *testing.T) {
os.Setenv("ELVISH_TEST_TIME_SCALE", test.env)
os.Setenv(util.EnvELVISH_TEST_TIME_SCALE, test.env)
got := ScaledMs(test.ms)
if got != test.want {
t.Errorf("got %v, want %v", got, test.want)

View File

@ -6,11 +6,12 @@ package util
// Note that some of these env vars may be significant only in special
// circumstances; such as when running unit tests.
const (
EnvHOME = "HOME"
EnvPATH = "PATH"
EnvPATHEXT = "PATHEXT"
EnvPWD = "PWD"
EnvSHLVL = "SHLVL"
EnvLS_COLORS = "LS_COLORS"
EnvXDG_RUNTIME_DIR = "XDG_RUNTIME_DIR"
EnvHOME = "HOME"
EnvPATH = "PATH"
EnvPATHEXT = "PATHEXT"
EnvPWD = "PWD"
EnvSHLVL = "SHLVL"
EnvLS_COLORS = "LS_COLORS"
EnvXDG_RUNTIME_DIR = "XDG_RUNTIME_DIR"
EnvELVISH_TEST_TIME_SCALE = "ELVISH_TEST_TIME_SCALE"
)