mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
Replace "ELVISH_TEST_TIME_SCALE" literals with a constant
This commit is contained in:
parent
947ac39876
commit
a4e539c823
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user