From 44058898ccb9660cd713cee033472eb2d8603580 Mon Sep 17 00:00:00 2001 From: inhere Date: Sat, 10 Apr 2021 11:57:37 +0800 Subject: [PATCH] update: add case for tests WSL env --- detect_env.go | 6 ++++-- utils_test.go | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/detect_env.go b/detect_env.go index f5dde8f..3b2300d 100644 --- a/detect_env.go +++ b/detect_env.go @@ -146,6 +146,8 @@ var wslContents string // https://github.com/Microsoft/WSL/issues/423#issuecomment-221627364 func detectWSL() bool { if !detectedWSL { + detectedWSL = true + b := make([]byte, 1024) // `cat /proc/version` // on mac: @@ -164,10 +166,10 @@ func detectWSL() bool { } wslContents = string(b) + return strings.Contains(wslContents, "Microsoft") } - detectedWSL = true } - return strings.Contains(wslContents, "Microsoft") + return false } // refer diff --git a/utils_test.go b/utils_test.go index 2a24839..b92eaa8 100644 --- a/utils_test.go +++ b/utils_test.go @@ -107,6 +107,13 @@ func TestIsDetectColorLevel_unix(t *testing.T) { is.True(IsSupportColor()) }) + mockOsEnvByText("WSL_DISTRO_NAME=Debian", func() { + is.Equal(LevelNo, DetectColorLevel()) + is.False(IsSupportTrueColor()) + is.False(IsSupport256Color()) + is.False(IsSupportColor()) + }) + // TERM_PROGRAM=Terminus mockOsEnvByText(` TERMINUS_PLUGINS=