Repository: JanDeDobbeleer/oh-my-posh
Pull request #1585 (2022-01-15 19:38:59)

os template
### Prerequisites

- [x] I have read and understood the `CONTRIBUTING` guide
- [x] The commit message follows the [conventional commits][cc] guidelines
- [x] Tests for the changes have been added (for bug fixes/features)
- [x] Docs have been added / updated (for bug fixes/features)

### Description

- refactor: remove the need for nil argument in mock
- feat: add OS to template functionality

<!---

Tips:

If you're not comfortable with working with Git, we're working a guide (https://ohmyposh.dev/docs/contributing_git) to help you out.
Oh My Posh advises GitKraken (https://www.gitkraken.com/invite/nQmDPR9D) as your preferred cross platform Git GUI power tool.

-->

[cc]: https://www.conventionalcommits.org/en/v1.0.0/#summary



Patch:
diff --git a/src/environment.go b/src/environment.go
index aaf5e941..ae5e26a7 100644
--- a/src/environment.go
+++ b/src/environment.go
@@ -90,6 +90,7 @@ type wifiInfo struct {
 
 type Environment interface {
 	getenv(key string) string
+	environ() map[string]string
 	getcwd() string
 	homeDir() string
 	hasFiles(pattern string) bool
@@ -154,12 +155,13 @@ const (
 )
 
 type environment struct {
-	args       *args
-	cwd        string
-	cmdCache   *commandCache
-	fileCache  *fileCache
-	logBuilder strings.Builder
-	debug      bool
+	args         *args
+	cwd          string
+	cmdCache     *commandCache
+	fileCache    *fileCache
+	environCache map[string]string
+	logBuilder   strings.Builder
+	debug        bool
 }
 
 func (env *environment) init(args *args) {
@@ -222,6 +224,25 @@ func (env *environment) getenv(key string) string {
 	return val
 }
 
+func (env *environment) environ() map[string]string {
+	defer env.trace(time.Now(), "environ")
+	if env.environCache != nil {
+		return env.environCache
+	}
+	const separator = "="
+	values := os.Environ()
+	for value := range values {
+		splitted := strings.Split(values[value], separator)
+		if len(splitted) != 2 {
+			continue
+		}
+		key := splitted[0]
+		val := splitted[1:]
+		env.environCache[key] = strings.Join(val, separator)
+	}
+	return env.environCache
+}
+
 func (env *environment) getcwd() string {
 	defer env.trace(time.Now(), "getcwd")
 	if env.cwd != "" {
diff --git a/src/segment_os.go b/src/segment_os.go
index 94aa3a0a..fcffea97 100644
--- a/src/segment_os.go
+++ b/src/segment_os.go
@@ -7,7 +7,8 @@ import (
 type osInfo struct {
 	props Properties
 	env   Environment
-	OS    string
+
+	os string
 }
 
 const (
@@ -71,25 +72,25 @@ func (n *osInfo) string() string {
 	goos := n.env.getRuntimeGOOS()
 	switch goos {
 	case windowsPlatform:
-		n.OS = windowsPlatform
+		n.os = windowsPlatform
 		return n.props.getString(Windows, "\uE62A")
 	case darwinPlatform:
-		n.OS = darwinPlatform
+		n.os = darwinPlatform
 		return n.props.getString(MacOS, "\uF179")
 	case linuxPlatform:
 		wsl := n.env.getenv("WSL_DISTRO_NAME")
 		p := n.env.getPlatform()
 		if len(wsl) == 0 {
-			n.OS = p
+			n.os = p
 			return n.getDistroName(p, "")
 		}
-		n.OS = wsl
+		n.os = wsl
 		return fmt.Sprintf("%s%s%s",
 			n.props.getString(WSL, "WSL"),
 			n.props.getString(WSLSeparator, " - "),
 			n.getDistroName(p, wsl))
 	default:
-		n.OS = goos
+		n.os = goos
 		return goos
 	}
 }
diff --git a/src/template.go b/src/template.go
index fba6a1c2..cc24e81a 100644
--- a/src/template.go
+++ b/src/template.go
@@ -34,6 +34,7 @@ type Context struct {
 	Host   string
 	Code   int
 	Env    map[string]string
+	OS     string
 
 	// Simple container to hold ANY object
 	Data
@@ -55,13 +56,16 @@ func (c *Context) init(t *textTemplate) {
 		c.Host = host
 	}
 	c.Code = t.Env.lastErrorCode()
-	if strings.Contains(t.Template, ".Env.") {
-		c.Env = map[string]string{}
-		matches := findAllNamedRegexMatch(templateEnvRegex, t.Template)
-		for _, match := range matches {
-			c.Env[match["ENV"]] = t.Env.getenv(match["ENV"])
+	c.Env = t.Env.environ()
+	goos := t.Env.getRuntimeGOOS()
+	if goos == linuxPlatform {
+		wsl := t.Env.getenv("WSL_DISTRO_NAME")
+		goos = t.Env.getPlatform()
+		if len(wsl) != 0 {
+			goos = wsl
 		}
 	}
+	c.OS = goos
 }
 
 func (t *textTemplate) render() (string, error) {
@@ -100,7 +104,7 @@ func (t *textTemplate) cleanTemplate() {
 		*knownVariables = append(*knownVariables, splitted[0])
 		return splitted[0], true
 	}
-	knownVariables := []string{"Root", "PWD", "Folder", "Shell", "User", "Host", "Env", "Data", "Code"}
+	knownVariables := []string{"Root", "PWD", "Folder", "Shell", "User", "Host", "Env", "Data", "Code", "OS"}
 	matches := findAllNamedRegexMatch(`(?: |{)(?P<var>(\.[a-zA-Z_][a-zA-Z0-9]*)+)`, t.Template)
 	for _, match := range matches {
 		if variable, OK := unknownVariable(match["var"], &knownVariables); OK {


Test patch:
diff --git a/src/console_title_test.go b/src/console_title_test.go
index 6be76b37..0d3b9624 100644
--- a/src/console_title_test.go
+++ b/src/console_title_test.go
@@ -54,14 +54,14 @@ func TestGetConsoleTitle(t *testing.T) {
 			ConsoleTitleTemplate: tc.Template,
 		}
 		env := new(MockedEnvironment)
-		env.On("getcwd", nil).Return(tc.Cwd)
-		env.On("homeDir", nil).Return("/usr/home")
-		env.On("getPathSeperator", nil).Return(tc.PathSeperator)
-		env.On("isRunningAsRoot", nil).Return(tc.Root)
-		env.On("getShellName", nil).Return(tc.ShellName)
+		env.On("getcwd").Return(tc.Cwd)
+		env.On("homeDir").Return("/usr/home")
+		env.On("getPathSeperator").Return(tc.PathSeperator)
+		env.On("isRunningAsRoot").Return(tc.Root)
+		env.On("getShellName").Return(tc.ShellName)
 		env.On("getenv", "USERDOMAIN").Return("MyCompany")
-		env.On("getCurrentUser", nil).Return("MyUser")
-		env.On("getHostName", nil).Return("MyHost", nil)
+		env.On("getCurrentUser").Return("MyUser")
+		env.On("getHostName").Return("MyHost", nil)
 		env.onTemplate()
 		ansi := &ansiUtils{}
 		ansi.init(tc.ShellName)
@@ -110,14 +110,14 @@ func TestGetConsoleTitleIfGethostnameReturnsError(t *testing.T) {
 			ConsoleTitleTemplate: tc.Template,
 		}
 		env := new(MockedEnvironment)
-		env.On("getcwd", nil).Return(tc.Cwd)
-		env.On("homeDir", nil).Return("/usr/home")
-		env.On("getPathSeperator", nil).Return(tc.PathSeperator)
-		env.On("isRunningAsRoot", nil).Return(tc.Root)
-		env.On("getShellName", nil).Return(tc.ShellName)
+		env.On("getcwd").Return(tc.Cwd)
+		env.On("homeDir").Return("/usr/home")
+		env.On("getPathSeperator").Return(tc.PathSeperator)
+		env.On("isRunningAsRoot").Return(tc.Root)
+		env.On("getShellName").Return(tc.ShellName)
 		env.On("getenv", "USERDOMAIN").Return("MyCompany")
-		env.On("getCurrentUser", nil).Return("MyUser")
-		env.On("getHostName", nil).Return("", fmt.Errorf("I have a bad feeling about this"))
+		env.On("getCurrentUser").Return("MyUser")
+		env.On("getHostName").Return("", fmt.Errorf("I have a bad feeling about this"))
 		env.onTemplate()
 		ansi := &ansiUtils{}
 		ansi.init(tc.ShellName)
diff --git a/src/engine_test.go b/src/engine_test.go
index 9bf919bb..dee1ff55 100644
--- a/src/engine_test.go
+++ b/src/engine_test.go
@@ -30,7 +30,7 @@ func TestCanWriteRPrompt(t *testing.T) {
 
 	for _, tc := range cases {
 		env := new(MockedEnvironment)
-		env.On("getTerminalWidth", nil).Return(tc.TerminalWidth, tc.TerminalWidthError)
+		env.On("getTerminalWidth").Return(tc.TerminalWidth, tc.TerminalWidthError)
 		ansi := &ansiUtils{}
 		ansi.init(plain)
 		engine := &engine{
diff --git a/src/regex_test.go b/src/regex_test.go
index 8d609414..68443b20 100644
--- a/src/regex_test.go
+++ b/src/regex_test.go
@@ -32,8 +32,8 @@ func TestDirMatchesOneOf(t *testing.T) {
 
 	for _, tc := range cases {
 		env := new(MockedEnvironment)
-		env.On("getRuntimeGOOS", nil).Return(tc.GOOS)
-		env.On("homeDir", nil).Return(tc.HomeDir)
+		env.On("getRuntimeGOOS").Return(tc.GOOS)
+		env.On("homeDir").Return(tc.HomeDir)
 		got := dirMatchesOneOf(env, tc.Dir, []string{tc.Pattern})
 		assert.Equal(t, tc.Expected, got)
 	}
diff --git a/src/scm_test.go b/src/scm_test.go
index cc58e0d0..edf718a2 100644
--- a/src/scm_test.go
+++ b/src/scm_test.go
@@ -174,8 +174,8 @@ func TestScmShouldIgnoreRootRepository(t *testing.T) {
 			},
 		}
 		env := new(MockedEnvironment)
-		env.On("homeDir", nil).Return("/home/bill")
-		env.On("getRuntimeGOOS", nil).Return(windowsPlatform)
+		env.On("homeDir").Return("/home/bill")
+		env.On("getRuntimeGOOS").Return(windowsPlatform)
 		s := &scm{
 			props: props,
 			env:   env,
diff --git a/src/segment_angular_test.go b/src/segment_angular_test.go
index 608a7297..087a32b7 100644
--- a/src/segment_angular_test.go
+++ b/src/segment_angular_test.go
@@ -24,8 +24,8 @@ func TestAngularCliVersionDisplayed(t *testing.T) {
 
 		var env = new(MockedEnvironment)
 		// mock  getVersion methods
-		env.On("getcwd", nil).Return("/usr/home/dev/my-app")
-		env.On("homeDir", nil).Return("/usr/home")
+		env.On("getcwd").Return("/usr/home/dev/my-app")
+		env.On("homeDir").Return("/usr/home")
 		env.On("hasFiles", params.extension).Return(true)
 		env.On("hasFilesInDir", "/usr/home/dev/my-app/node_modules/@angular/core", "package.json").Return(true)
 		env.On("getFileContent", "/usr/home/dev/my-app/node_modules/@angular/core/package.json").Return(ta.Version)
diff --git a/src/segment_aws_test.go b/src/segment_aws_test.go
index 0b0b3768..43bf74a1 100644
--- a/src/segment_aws_test.go
+++ b/src/segment_aws_test.go
@@ -53,7 +53,7 @@ func TestAWSSegment(t *testing.T) {
 		env.On("getenv", "AWS_DEFAULT_REGION").Return(tc.DefaultRegion)
 		env.On("getenv", "AWS_CONFIG_FILE").Return(tc.ConfigFile)
 		env.On("getFileContent", "/usr/home/.aws/config").Return("")
-		env.On("homeDir", nil).Return("/usr/home")
+		env.On("homeDir").Return("/usr/home")
 		env.onTemplate()
 		props := properties{
 			DisplayDefault: tc.DisplayDefault,
diff --git a/src/segment_az_test.go b/src/segment_az_test.go
index 09faf1b1..cb59c2bf 100644
--- a/src/segment_az_test.go
+++ b/src/segment_az_test.go
@@ -69,7 +69,7 @@ func TestAzSegment(t *testing.T) {
 	for _, tc := range cases {
 		env := new(MockedEnvironment)
 		home := "/Users/posh"
-		env.On("homeDir", nil).Return(home)
+		env.On("homeDir").Return(home)
 		var azureProfile, azureRmContext, azureRMContext string
 		if tc.HasCLI {
 			content, _ := ioutil.ReadFile("./test/azureProfile.json")
@@ -83,7 +83,7 @@ func TestAzSegment(t *testing.T) {
 			content, _ := ioutil.ReadFile("./test/AzureRmContext.json")
 			azureRMContext = string(content)
 		}
-		env.On("getRuntimeGOOS", nil).Return(linuxPlatform)
+		env.On("getRuntimeGOOS").Return(linuxPlatform)
 		env.On("getFileContent", filepath.Join(home, ".azure", "azureProfile.json")).Return(azureProfile)
 		env.On("getFileContent", filepath.Join(home, ".Azure", "AzureRmContext.json")).Return(azureRmContext)
 		env.On("getFileContent", filepath.Join(home, ".azure", "AzureRmContext.json")).Return(azureRMContext)
diff --git a/src/segment_brewfather_test.go b/src/segment_brewfather_test.go
index 979f35d3..a246daf6 100644
--- a/src/segment_brewfather_test.go
+++ b/src/segment_brewfather_test.go
@@ -150,7 +150,7 @@ func TestBrewfatherSegment(t *testing.T) {
 
 		env.On("HTTPRequest", BFBatchURL).Return([]byte(tc.BatchJSONResponse), tc.Error)
 		env.On("HTTPRequest", BFBatchReadingsURL).Return([]byte(tc.BatchReadingsJSONResponse), tc.Error)
-		env.On("cache", nil).Return(cache)
+		env.On("cache").Return(cache)
 		env.onTemplate()
 		if tc.Template != "" {
 			props[SegmentTemplate] = tc.Template
diff --git a/src/segment_deprecated_test.go b/src/segment_deprecated_test.go
index 498a6dbd..8c5e5a68 100644
--- a/src/segment_deprecated_test.go
+++ b/src/segment_deprecated_test.go
@@ -270,8 +270,8 @@ func TestStatusColorsWithoutDisplayStatus(t *testing.T) {
 	expected := changesColor
 	status := "## main...origin/main [ahead 33]\n M myfile"
 	env := new(MockedEnvironment)
-	env.On("isWsl", nil).Return(false)
-	env.On("getRuntimeGOOS", nil).Return("unix")
+	env.On("isWsl").Return(false)
+	env.On("getRuntimeGOOS").Return("unix")
 	env.On("hasFolder", "/rebase-merge").Return(false)
 	env.On("hasFolder", "/rebase-apply").Return(false)
 	env.On("hasFolder", "/sequencer").Return(false)
@@ -324,7 +324,7 @@ func TestExitWriterDeprecatedString(t *testing.T) {
 
 	for _, tc := range cases {
 		env := new(MockedEnvironment)
-		env.On("lastErrorCode", nil).Return(tc.ExitCode)
+		env.On("lastErrorCode").Return(tc.ExitCode)
 		props := properties{
 			SuccessIcon:     tc.SuccessIcon,
 			ErrorIcon:       tc.ErrorIcon,
@@ -446,7 +446,7 @@ func TestBatterySegmentSingle(t *testing.T) {
 		if tc.DisableCharged {
 			props[DisplayCharged] = false
 		}
-		env.On("getBatteryInfo", nil).Return(tc.Batteries, tc.Error)
+		env.On("getBatteryInfo").Return(tc.Batteries, tc.Error)
 		env.onTemplate()
 		b := &batt{
 			props: props,
@@ -623,12 +623,12 @@ func TestPropertySessionSegment(t *testing.T) {
 
 	for _, tc := range cases {
 		env := new(MockedEnvironment)
-		env.On("getCurrentUser", nil).Return(tc.UserName)
-		env.On("getRuntimeGOOS", nil).Return(tc.GOOS)
+		env.On("getCurrentUser").Return(tc.UserName)
+		env.On("getRuntimeGOOS").Return(tc.GOOS)
 		if tc.HostError {
-			env.On("getHostName", nil).Return(tc.Host, errors.New("oh snap"))
+			env.On("getHostName").Return(tc.Host, errors.New("oh snap"))
 		} else {
-			env.On("getHostName", nil).Return(tc.Host, nil)
+			env.On("getHostName").Return(tc.Host, nil)
 		}
 		var SSHSession string
 		if tc.SSHSession {
@@ -642,7 +642,7 @@ func TestPropertySessionSegment(t *testing.T) {
 		env.On("getenv", "SSH_CLIENT").Return(SSHClient)
 		env.On("getenv", "SSH_CLIENT").Return(SSHSession)
 		env.On("getenv", defaultUserEnvVar).Return(tc.DefaultUserNameEnv)
-		env.On("isRunningAsRoot", nil).Return(tc.Root)
+		env.On("isRunningAsRoot").Return(tc.Root)
 		props := properties{
 			UserInfoSeparator: " at ",
 			SSHIcon:           "ssh ",
@@ -754,9 +754,9 @@ func TestPythonVirtualEnv(t *testing.T) {
 		env.On("getenv", "CONDA_ENV_PATH").Return(tc.CondaEnvName)
 		env.On("getenv", "CONDA_DEFAULT_ENV").Return(tc.CondaDefaultEnvName)
 		env.On("getenv", "PYENV_VERSION").Return(tc.PyEnvName)
-		env.On("getPathSeperator", nil).Return("")
-		env.On("getcwd", nil).Return("/usr/home/project")
-		env.On("homeDir", nil).Return("/usr/home")
+		env.On("getPathSeperator").Return("")
+		env.On("getcwd").Return("/usr/home/project")
+		env.On("homeDir").Return("/usr/home")
 		env.onTemplate()
 		props := properties{
 			FetchVersion:      tc.FetchVersion,
diff --git a/src/segment_dotnet_test.go b/src/segment_dotnet_test.go
index efc4723a..003edf43 100644
--- a/src/segment_dotnet_test.go
+++ b/src/segment_dotnet_test.go
@@ -25,9 +25,9 @@ func bootStrapDotnetTest(args *dotnetArgs) *dotnet {
 	}
 
 	env.On("hasFiles", "*.cs").Return(true)
-	env.On("getPathSeperator", nil).Return("")
-	env.On("getcwd", nil).Return("/usr/home/project")
-	env.On("homeDir", nil).Return("/usr/home")
+	env.On("getPathSeperator").Return("")
+	env.On("getcwd").Return("/usr/home/project")
+	env.On("homeDir").Return("/usr/home")
 	env.onTemplate()
 	props := properties{
 		FetchVersion:                 args.displayVersion,
diff --git a/src/segment_executiontime_test.go b/src/segment_executiontime_test.go
index f4b6f787..5be55e0c 100644
--- a/src/segment_executiontime_test.go
+++ b/src/segment_executiontime_test.go
@@ -9,7 +9,7 @@ import (
 
 func TestExecutionTimeWriterDefaultThresholdEnabled(t *testing.T) {
 	env := new(MockedEnvironment)
-	env.On("executionTime", nil).Return(1337)
+	env.On("executionTime").Return(1337)
 	executionTime := &executiontime{
 		env:   env,
 		props: properties{},
@@ -19,7 +19,7 @@ func TestExecutionTimeWriterDefaultThresholdEnabled(t *testing.T) {
 
 func TestExecutionTimeWriterDefaultThresholdDisabled(t *testing.T) {
 	env := new(MockedEnvironment)
-	env.On("executionTime", nil).Return(1)
+	env.On("executionTime").Return(1)
 	executionTime := &executiontime{
 		env:   env,
 		props: properties{},
@@ -29,7 +29,7 @@ func TestExecutionTimeWriterDefaultThresholdDisabled(t *testing.T) {
 
 func TestExecutionTimeWriterCustomThresholdEnabled(t *testing.T) {
 	env := new(MockedEnvironment)
-	env.On("executionTime", nil).Return(99)
+	env.On("executionTime").Return(99)
 	props := properties{
 		ThresholdProperty: float64(10),
 	}
@@ -42,7 +42,7 @@ func TestExecutionTimeWriterCustomThresholdEnabled(t *testing.T) {
 
 func TestExecutionTimeWriterCustomThresholdDisabled(t *testing.T) {
 	env := new(MockedEnvironment)
-	env.On("executionTime", nil).Return(99)
+	env.On("executionTime").Return(99)
 	props := properties{
 		ThresholdProperty: float64(100),
 	}
@@ -57,7 +57,7 @@ func TestExecutionTimeWriterDuration(t *testing.T) {
 	input := 1337
 	expected := "1.337s"
 	env := new(MockedEnvironment)
-	env.On("executionTime", nil).Return(input)
+	env.On("executionTime").Return(input)
 	executionTime := &executiontime{
 		env:   env,
 		props: properties{},
@@ -70,7 +70,7 @@ func TestExecutionTimeWriterDuration2(t *testing.T) {
 	input := 13371337
 	expected := "3h 42m 51.337s"
 	env := new(MockedEnvironment)
-	env.On("executionTime", nil).Return(input)
+	env.On("executionTime").Return(input)
 	executionTime := &executiontime{
 		env:   env,
 		props: properties{},
diff --git a/src/segment_exit_test.go b/src/segment_exit_test.go
index ee8f8dab..b1b3aa56 100644
--- a/src/segment_exit_test.go
+++ b/src/segment_exit_test.go
@@ -18,7 +18,7 @@ func TestExitWriterEnabled(t *testing.T) {
 
 	for _, tc := range cases {
 		env := new(MockedEnvironment)
-		env.On("lastErrorCode", nil).Return(tc.ExitCode)
+		env.On("lastErrorCode").Return(tc.ExitCode)
 		e := &exit{
 			env:   env,
 			props: properties{},
@@ -76,7 +76,7 @@ func TestExitWriterTemplateString(t *testing.T) {
 
 	for _, tc := range cases {
 		env := new(MockedEnvironment)
-		env.On("lastErrorCode", nil).Return(tc.ExitCode)
+		env.On("lastErrorCode").Return(tc.ExitCode)
 		env.onTemplate()
 		props := properties{
 			SegmentTemplate: tc.Template,
diff --git a/src/segment_git_test.go b/src/segment_git_test.go
index 9fc3a0ef..d98a06cd 100644
--- a/src/segment_git_test.go
+++ b/src/segment_git_test.go
@@ -15,10 +15,10 @@ const (
 
 func TestEnabledGitNotFound(t *testing.T) {
 	env := new(MockedEnvironment)
-	env.On("inWSLSharedDrive", nil).Return(false)
+	env.On("inWSLSharedDrive").Return(false)
 	env.On("hasCommand", "git").Return(false)
-	env.On("getRuntimeGOOS", nil).Return("")
-	env.On("isWsl", nil).Return(false)
+	env.On("getRuntimeGOOS").Return("")
+	env.On("isWsl").Return(false)
 	g := &git{
 		scm: scm{
 			env:   env,
@@ -30,10 +30,10 @@ func TestEnabledGitNotFound(t *testing.T) {
 
 func TestEnabledInWorkingDirectory(t *testing.T) {
 	env := new(MockedEnvironment)
-	env.On("inWSLSharedDrive", nil).Return(false)
+	env.On("inWSLSharedDrive").Return(false)
 	env.On("hasCommand", "git").Return(true)
-	env.On("getRuntimeGOOS", nil).Return("")
-	env.On("isWsl", nil).Return(false)
+	env.On("getRuntimeGOOS").Return("")
+	env.On("isWsl").Return(false)
 	fileInfo := &fileInfo{
 		path:         "/dir/hello",
 		parentFolder: "/dir",
@@ -52,10 +52,10 @@ func TestEnabledInWorkingDirectory(t *testing.T) {
 
 func TestEnabledInWorkingTree(t *testing.T) {
 	env := new(MockedEnvironment)
-	env.On("inWSLSharedDrive", nil).Return(false)
+	env.On("inWSLSharedDrive").Return(false)
 	env.On("hasCommand", "git").Return(true)
-	env.On("getRuntimeGOOS", nil).Return("")
-	env.On("isWsl", nil).Return(false)
+	env.On("getRuntimeGOOS").Return("")
+	env.On("isWsl").Return(false)
 	fileInfo := &fileInfo{
 		path:         "/dev/folder_worktree/.git",
 		parentFolder: "/dev/folder_worktree",
@@ -77,10 +77,10 @@ func TestEnabledInWorkingTree(t *testing.T) {
 
 func TestEnabledInSubmodule(t *testing.T) {
 	env := new(MockedEnvironment)
-	env.On("inWSLSharedDrive", nil).Return(false)
+	env.On("inWSLSharedDrive").Return(false)
 	env.On("hasCommand", "git").Return(true)
-	env.On("getRuntimeGOOS", nil).Return("")
-	env.On("isWsl", nil).Return(false)
+	env.On("getRuntimeGOOS").Return("")
+	env.On("isWsl").Return(false)
 	fileInfo := &fileInfo{
 		path:         "/dev/parent/test-submodule/.git",
 		parentFolder: "/dev/parent/test-submodule",
@@ -106,9 +106,9 @@ func TestGetGitOutputForCommand(t *testing.T) {
 	commandArgs := []string{"symbolic-ref", "--short", "HEAD"}
 	want := "je suis le output"
 	env := new(MockedEnvironment)
-	env.On("isWsl", nil).Return(false)
+	env.On("isWsl").Return(false)
 	env.On("runCommand", "git", append(args, commandArgs...)).Return(want, nil)
-	env.On("getRuntimeGOOS", nil).Return("unix")
+	env.On("getRuntimeGOOS").Return("unix")
 	g := &git{
 		scm: scm{
 			env:   env,
@@ -228,9 +228,9 @@ func TestSetGitHEADContextClean(t *testing.T) {
 	}
 	for _, tc := range cases {
 		env := new(MockedEnvironment)
-		env.On("inWSLSharedDrive", nil).Return(false)
-		env.On("getRuntimeGOOS", nil).Return("unix")
-		env.On("isWsl", nil).Return(false)
+		env.On("inWSLSharedDrive").Return(false)
+		env.On("getRuntimeGOOS").Return("unix")
+		env.On("isWsl").Return(false)
 		env.mockGitCommand("", "describe", "--tags", "--exact-match")
 		env.mockGitCommand(tc.Theirs, "name-rev", "--name-only", "--exclude=tags/*", tc.Theirs)
 		env.mockGitCommand(tc.Ours, "name-rev", "--name-only", "--exclude=tags/*", tc.Ours)
@@ -297,8 +297,8 @@ func TestSetPrettyHEADName(t *testing.T) {
 	for _, tc := range cases {
 		env := new(MockedEnvironment)
 		env.On("getFileContent", "/HEAD").Return(tc.HEAD)
-		env.On("getRuntimeGOOS", nil).Return("unix")
-		env.On("isWsl", nil).Return(false)
+		env.On("getRuntimeGOOS").Return("unix")
+		env.On("isWsl").Return(false)
 		env.mockGitCommand(tc.Tag, "describe", "--tags", "--exact-match")
 		g := &git{
 			scm: scm{
@@ -414,8 +414,8 @@ func TestSetGitStatus(t *testing.T) {
 	}
 	for _, tc := range cases {
 		env := new(MockedEnvironment)
-		env.On("getRuntimeGOOS", nil).Return("unix")
-		env.On("isWsl", nil).Return(false)
+		env.On("getRuntimeGOOS").Return("unix")
+		env.On("isWsl").Return(false)
 		env.mockGitCommand(strings.ReplaceAll(tc.Output, "\t", ""), "status", "-unormal", "--branch", "--porcelain=2")
 		g := &git{
 			scm: scm{
@@ -477,10 +477,10 @@ func TestGitUpstream(t *testing.T) {
 	}
 	for _, tc := range cases {
 		env := &MockedEnvironment{}
-		env.On("isWsl", nil).Return(false)
+		env.On("isWsl").Return(false)
 		env.On("runCommand", "git", []string{"-C", "", "--no-optional-locks", "-c", "core.quotepath=false",
 			"-c", "color.status=false", "remote", "get-url", "origin"}).Return(tc.Upstream, nil)
-		env.On("getRuntimeGOOS", nil).Return("unix")
+		env.On("getRuntimeGOOS").Return("unix")
 		props := properties{
 			GithubIcon:      "GH",
 			GitlabIcon:      "GL",
@@ -556,8 +556,8 @@ func TestShouldIgnoreRootRepository(t *testing.T) {
 			},
 		}
 		env := new(MockedEnvironment)
-		env.On("homeDir", nil).Return("/home/bill")
-		env.On("getRuntimeGOOS", nil).Return(windowsPlatform)
+		env.On("homeDir").Return("/home/bill")
+		env.On("getRuntimeGOOS").Return(windowsPlatform)
 		git := &git{
 			scm: scm{
 				props: props,
@@ -588,9 +588,9 @@ func TestGetGitCommand(t *testing.T) {
 
 	for _, tc := range cases {
 		env := new(MockedEnvironment)
-		env.On("isWsl", nil).Return(tc.IsWSL)
-		env.On("getRuntimeGOOS", nil).Return(tc.GOOS)
-		env.On("getcwd", nil).Return(tc.CWD)
+		env.On("isWsl").Return(tc.IsWSL)
+		env.On("getRuntimeGOOS").Return(tc.GOOS)
+		env.On("getcwd").Return(tc.CWD)
 		wslUname := "5.10.60.1-microsoft-standard-WSL2"
 		if tc.IsWSL1 {
 			wslUname = "4.4.0-19041-Microsoft"
@@ -602,10 +602,10 @@ func TestGetGitCommand(t *testing.T) {
 			},
 		}
 		if tc.IsWslSharedPath {
-			env.On("inWSLSharedDrive", nil).Return(true)
+			env.On("inWSLSharedDrive").Return(true)
 			g.IsWslSharedPath = tc.IsWslSharedPath
 		} else {
-			env.On("inWSLSharedDrive", nil).Return(false)
+			env.On("inWSLSharedDrive").Return(false)
 		}
 		assert.Equal(t, tc.Expected, g.getGitCommand(), tc.Case)
 	}
diff --git a/src/segment_golang_test.go b/src/segment_golang_test.go
index 22c549c0..c87f6e6f 100644
--- a/src/segment_golang_test.go
+++ b/src/segment_golang_test.go
@@ -21,8 +21,8 @@ func getMockedLanguageEnv(params *mockedLanguageParams) (*MockedEnvironment, pro
 	env.On("hasCommand", params.cmd).Return(true)
 	env.On("runCommand", params.cmd, []string{params.versionParam}).Return(params.versionOutput, nil)
 	env.On("hasFiles", params.extension).Return(true)
-	env.On("getcwd", nil).Return("/usr/home/project")
-	env.On("homeDir", nil).Return("/usr/home")
+	env.On("getcwd").Return("/usr/home/project")
+	env.On("homeDir").Return("/usr/home")
 	env.onTemplate()
 	props := properties{
 		FetchVersion: true,
diff --git a/src/segment_java_test.go b/src/segment_java_test.go
index a5b8c9e5..645fea0e 100644
--- a/src/segment_java_test.go
+++ b/src/segment_java_test.go
@@ -57,8 +57,8 @@ func TestJava(t *testing.T) {
 		env.On("hasCommand", "java").Return(true)
 		env.On("runCommand", "java", []string{"-Xinternalversion"}).Return(tc.Version, nil)
 		env.On("hasFiles", "pom.xml").Return(true)
-		env.On("getcwd", nil).Return("/usr/home/project")
-		env.On("homeDir", nil).Return("/usr/home")
+		env.On("getcwd").Return("/usr/home/project")
+		env.On("homeDir").Return("/usr/home")
 		if tc.JavaHomeEnabled {
 			env.On("getenv", "JAVA_HOME").Return("/usr/java")
 			env.On("hasCommand", "/usr/java/bin/java").Return(true)
diff --git a/src/segment_kubectl_test.go b/src/segment_kubectl_test.go
index 6669aa02..f7c266db 100644
--- a/src/segment_kubectl_test.go
+++ b/src/segment_kubectl_test.go
@@ -124,7 +124,7 @@ func TestKubectlSegment(t *testing.T) {
 		for path, content := range tc.Files {
 			env.On("getFileContent", path).Return(content)
 		}
-		env.On("homeDir", nil).Return("testhome")
+		env.On("homeDir").Return("testhome")
 		env.onTemplate()
 
 		k := &kubectl{
diff --git a/src/segment_language_test.go b/src/segment_language_test.go
index dd17c620..e75e31b1 100644
--- a/src/segment_language_test.go
+++ b/src/segment_language_test.go
@@ -48,8 +48,8 @@ func bootStrapLanguageTest(args *languageArgs) *language {
 	if args.inHome {
 		cwd = home
 	}
-	env.On("getcwd", nil).Return(cwd)
-	env.On("homeDir", nil).Return(home)
+	env.On("getcwd").Return(cwd)
+	env.On("homeDir").Return(home)
 	env.onTemplate()
 	if args.properties == nil {
 		args.properties = properties{}
diff --git a/src/segment_nightscout_test.go b/src/segment_nightscout_test.go
index fc45e3f3..dffd21cb 100644
--- a/src/segment_nightscout_test.go
+++ b/src/segment_nightscout_test.go
@@ -140,7 +140,7 @@ func TestNSSegment(t *testing.T) {
 		cache.On("set", FAKEAPIURL, tc.JSONResponse, tc.CacheTimeout).Return()
 
 		env.On("HTTPRequest", FAKEAPIURL).Return([]byte(tc.JSONResponse), tc.Error)
-		env.On("cache", nil).Return(cache)
+		env.On("cache").Return(cache)
 		env.onTemplate()
 
 		if tc.Template != "" {
diff --git a/src/segment_os_test.go b/src/segment_os_test.go
index 3ba540a3..d074e946 100644
--- a/src/segment_os_test.go
+++ b/src/segment_os_test.go
@@ -61,9 +61,9 @@ func TestOSInfo(t *testing.T) {
 	}
 	for _, tc := range cases {
 		env := new(MockedEnvironment)
-		env.On("getRuntimeGOOS", nil).Return(tc.GOOS)
+		env.On("getRuntimeGOOS").Return(tc.GOOS)
 		env.On("getenv", "WSL_DISTRO_NAME").Return(tc.WSLDistro)
-		env.On("getPlatform", nil).Return(tc.Platform)
+		env.On("getPlatform").Return(tc.Platform)
 		osInfo := &osInfo{
 			env: env,
 			props: properties{
@@ -76,11 +76,11 @@ func TestOSInfo(t *testing.T) {
 		}
 		assert.Equal(t, tc.ExpectedString, osInfo.string(), tc.Case)
 		if tc.WSLDistro != "" {
-			assert.Equal(t, tc.WSLDistro, osInfo.OS, tc.Case)
+			assert.Equal(t, tc.WSLDistro, osInfo.os, tc.Case)
 		} else if tc.Platform != "" {
-			assert.Equal(t, tc.Platform, osInfo.OS, tc.Case)
+			assert.Equal(t, tc.Platform, osInfo.os, tc.Case)
 		} else {
-			assert.Equal(t, tc.GOOS, osInfo.OS, tc.Case)
+			assert.Equal(t, tc.GOOS, osInfo.os, tc.Case)
 		}
 	}
 }
diff --git a/src/segment_owm_test.go b/src/segment_owm_test.go
index 871a4069..709673dd 100644
--- a/src/segment_owm_test.go
+++ b/src/segment_owm_test.go
@@ -245,7 +245,7 @@ func TestOWMSegmentFromCache(t *testing.T) {
 	cache.On("get", "owm_response").Return(response, true)
 	cache.On("get", "owm_url").Return("http://api.openweathermap.org/data/2.5/weather?q=AMSTERDAM,NL&units=metric&appid=key", true)
 	cache.On("set").Return()
-	env.On("cache", nil).Return(cache)
+	env.On("cache").Return(cache)
 	env.onTemplate()
 
 	assert.Nil(t, o.setStatus())
@@ -272,7 +272,7 @@ func TestOWMSegmentFromCacheWithHyperlink(t *testing.T) {
 	cache.On("get", "owm_response").Return(response, true)
 	cache.On("get", "owm_url").Return("http://api.openweathermap.org/data/2.5/weather?q=AMSTERDAM,NL&units=metric&appid=key", true)
 	cache.On("set").Return()
-	env.On("cache", nil).Return(cache)
+	env.On("cache").Return(cache)
 	env.onTemplate()
 
 	assert.Nil(t, o.setStatus())
diff --git a/src/segment_path_test.go b/src/segment_path_test.go
index a29a21f0..0ede23d9 100644
--- a/src/segment_path_test.go
+++ b/src/segment_path_test.go
@@ -19,13 +19,18 @@ func (env *MockedEnvironment) getenv(key string) string {
 	return args.String(0)
 }
 
+func (env *MockedEnvironment) environ() map[string]string {
+	args := env.Called()
+	return args.Get(0).(map[string]string)
+}
+
 func (env *MockedEnvironment) getcwd() string {
-	args := env.Called(nil)
+	args := env.Called()
 	return args.String(0)
 }
 
 func (env *MockedEnvironment) homeDir() string {
-	args := env.Called(nil)
+	args := env.Called()
 	return args.String(0)
 }
 
@@ -55,27 +60,27 @@ func (env *MockedEnvironment) getFoldersList(path string) []string {
 }
 
 func (env *MockedEnvironment) getPathSeperator() string {
-	args := env.Called(nil)
+	args := env.Called()
 	return args.String(0)
 }
 
 func (env *MockedEnvironment) getCurrentUser() string {
-	args := env.Called(nil)
+	args := env.Called()
 	return args.String(0)
 }
 
 func (env *MockedEnvironment) getHostName() (string, error) {
-	args := env.Called(nil)
+	args := env.Called()
 	return args.String(0), args.Error(1)
 }
 
 func (env *MockedEnvironment) getRuntimeGOOS() string {
-	args := env.Called(nil)
+	args := env.Called()
 	return args.String(0)
 }
 
 func (env *MockedEnvironment) getPlatform() string {
-	args := env.Called(nil)
+	args := env.Called()
 	return args.String(0)
 }
 
@@ -95,32 +100,32 @@ func (env *MockedEnvironment) runShellCommand(shell, command string) string {
 }
 
 func (env *MockedEnvironment) lastErrorCode() int {
-	args := env.Called(nil)
+	args := env.Called()
 	return args.Int(0)
 }
 
 func (env *MockedEnvironment) executionTime() float64 {
-	args := env.Called(nil)
+	args := env.Called()
 	return float64(args.Int(0))
 }
 
 func (env *MockedEnvironment) isRunningAsRoot() bool {
-	args := env.Called(nil)
+	args := env.Called()
 	return args.Bool(0)
 }
 
 func (env *MockedEnvironment) getArgs() *args {
-	arguments := env.Called(nil)
+	arguments := env.Called()
 	return arguments.Get(0).(*args)
 }
 
 func (env *MockedEnvironment) getBatteryInfo() ([]*battery.Battery, error) {
-	args := env.Called(nil)
+	args := env.Called()
 	return args.Get(0).([]*battery.Battery), args.Error(1)
 }
 
 func (env *MockedEnvironment) getShellName() string {
-	args := env.Called(nil)
+	args := env.Called()
 	return args.String(0)
 }
 
@@ -145,61 +150,61 @@ func (env *MockedEnvironment) hasParentFilePath(path string) (*fileInfo, error)
 }
 
 func (env *MockedEnvironment) stackCount() int {
-	args := env.Called(nil)
+	args := env.Called()
 	return args.Int(0)
 }
 
 func (env *MockedEnvironment) isWsl() bool {
-	args := env.Called(nil)
+	args := env.Called()
 	return args.Bool(0)
 }
 
 func (env *MockedEnvironment) isWsl2() bool {
-	args := env.Called(nil)
+	args := env.Called()
 	return args.Bool(0)
 }
 
 func (env *MockedEnvironment) getTerminalWidth() (int, error) {
-	args := env.Called(nil)
+	args := env.Called()
 	return args.Int(0), args.Error(1)
 }
 
 func (env *MockedEnvironment) getCachePath() string {
-	args := env.Called(nil)
+	args := env.Called()
 	return args.String(0)
 }
 
 func (env *MockedEnvironment) cache() cache {
-	args := env.Called(nil)
+	args := env.Called()
 	return args.Get(0).(cache)
 }
 
 func (env *MockedEnvironment) close() {
-	_ = env.Called(nil)
+	_ = env.Called()
 }
 
 func (env *MockedEnvironment) logs() string {
-	args := env.Called(nil)
+	args := env.Called()
 	return args.String(0)
 }
 
 func (env *MockedEnvironment) inWSLSharedDrive() bool {
-	args := env.Called(nil)
+	args := env.Called()
 	return args.Bool(0)
 }
 
 func (env *MockedEnvironment) convertToWindowsPath(path string) string {
-	args := env.Called(nil)
+	args := env.Called()
 	return args.String(0)
 }
 
 func (env *MockedEnvironment) convertToLinuxPath(path string) string {
-	args := env.Called(nil)
+	args := env.Called()
 	return args.String(0)
 }
 
 func (env *MockedEnvironment) getWifiNetwork() (*wifiInfo, error) {
-	args := env.Called(nil)
+	args := env.Called()
 	return args.Get(0).(*wifiInfo), args.Error(1)
 }
 
@@ -210,7 +215,16 @@ func (env *MockedEnvironment) onTemplate() {
 				return
 			}
 		}
-		env.On(method, nil).Return(returnArguments...)
+		env.On(method).Return(returnArguments...)
+	}
+	patchEnvVars := func() map[string]string {
+		keyValueArray := make(map[string]string)
+		for _, call := range env.Mock.ExpectedCalls {
+			if call.Method == "getenv" {
+				keyValueArray[call.Arguments.String(0)] = call.ReturnArguments.String(0)
+			}
+		}
+		return keyValueArray
 	}
 	patchMethodIfNotSpecified("isRunningAsRoot", false)
 	patchMethodIfNotSpecified("getcwd", "/usr/home/dev/my-app")
@@ -220,6 +234,12 @@ func (env *MockedEnvironment) onTemplate() {
 	patchMethodIfNotSpecified("getCurrentUser", "dev")
 	patchMethodIfNotSpecified("getHostName", "laptop", nil)
 	patchMethodIfNotSpecified("lastErrorCode", 0)
+	patchMethodIfNotSpecified("getRuntimeGOOS", darwinPlatform)
+	if env.getRuntimeGOOS() == linuxPlatform {
+		env.On("getenv", "WSL_DISTRO_NAME").Return("ubuntu")
+		env.On("getPlatform").Return("ubuntu")
+	}
+	patchMethodIfNotSpecified("environ", patchEnvVars())
 }
 
 const (
@@ -232,7 +252,7 @@ const (
 func TestIsInHomeDirTrue(t *testing.T) {
 	home := homeBill
 	env := new(MockedEnvironment)
-	env.On("homeDir", nil).Return(home)
+	env.On("homeDir").Return(home)
 	path := &path{
 		env: env,
 	}
@@ -247,7 +267,7 @@ func TestIsInHomeDirLevelTrue(t *testing.T) {
 		pwd += levelDir
 	}
 	env := new(MockedEnvironment)
-	env.On("homeDir", nil).Return(home)
+	env.On("homeDir").Return(home)
 	path := &path{
 		env: env,
 	}
@@ -276,14 +296,14 @@ func TestRootLocationHome(t *testing.T) {
 	}
 	for _, tc := range cases {
 		env := new(MockedEnvironment)
-		env.On("homeDir", nil).Return(tc.HomePath)
-		env.On("getcwd", nil).Return(tc.Pwd)
+		env.On("homeDir").Return(tc.HomePath)
+		env.On("getcwd").Return(tc.Pwd)
 		args := &args{
 			PSWD: &tc.Pswd,
 		}
-		env.On("getArgs", nil).Return(args)
-		env.On("getPathSeperator", nil).Return(tc.PathSeperator)
-		env.On("getRuntimeGOOS", nil).Return("")
+		env.On("getArgs").Return(args)
+		env.On("getPathSeperator").Return(tc.PathSeperator)
+		env.On("getRuntimeGOOS").Return("")
 		path := &path{
 			env: env,
 			props: properties{
@@ -299,7 +319,7 @@ func TestRootLocationHome(t *testing.T) {
 func TestIsInHomeDirFalse(t *testing.T) {
 	home := homeBill
 	env := new(MockedEnvironment)
-	env.On("homeDir", nil).Return(home)
+	env.On("homeDir").Return(home)
 	path := &path{
 		env: env,
 	}
@@ -313,8 +333,8 @@ func TestPathDepthMultipleLevelsDeep(t *testing.T) {
 		pwd += levelDir
 	}
 	env := new(MockedEnvironment)
-	env.On("getPathSeperator", nil).Return("/")
-	env.On("getRunteGOOS", nil).Return("")
+	env.On("getPathSeperator").Return("/")
+	env.On("getRunteGOOS").Return("")
 	path := &path{
 		env: env,
 	}
@@ -325,7 +345,7 @@ func TestPathDepthMultipleLevelsDeep(t *testing.T) {
 func TestPathDepthZeroLevelsDeep(t *testing.T) {
 	pwd := "/usr/"
 	env := new(MockedEnvironment)
-	env.On("getPathSeperator", nil).Return("/")
+	env.On("getPathSeperator").Return("/")
 	path := &path{
 		env: env,
 	}
@@ -336,7 +356,7 @@ func TestPathDepthZeroLevelsDeep(t *testing.T) {
 func TestPathDepthOneLevelDeep(t *testing.T) {
 	pwd := "/usr/location"
 	env := new(MockedEnvironment)
-	env.On("getPathSeperator", nil).Return("/")
+	env.On("getPathSeperator").Return("/")
 	path := &path{
 		env: env,
 	}
@@ -427,15 +447,15 @@ func TestAgnosterPathStyles(t *testing.T) {
 	}
 	for _, tc := range cases {
 		env := new(MockedEnvironment)
-		env.On("getPathSeperator", nil).Return(tc.PathSeperator)
-		env.On("homeDir", nil).Return(tc.HomePath)
-		env.On("getcwd", nil).Return(tc.Pwd)
-		env.On("getRuntimeGOOS", nil).Return(tc.GOOS)
-		env.On("stackCount", nil).Return(0)
+		env.On("getPathSeperator").Return(tc.PathSeperator)
+		env.On("homeDir").Return(tc.HomePath)
+		env.On("getcwd").Return(tc.Pwd)
+		env.On("getRuntimeGOOS").Return(tc.GOOS)
+		env.On("stackCount").Return(0)
 		args := &args{
 			PSWD: &tc.Pswd,
 		}
-		env.On("getArgs", nil).Return(args)
+		env.On("getArgs").Return(args)
 		env.onTemplate()
 		path := &path{
 			env: env,
@@ -548,15 +568,15 @@ func TestGetFullPath(t *testing.T) {
 		if len(tc.PathSeparator) == 0 {
 			tc.PathSeparator = "/"
 		}
-		env.On("getPathSeperator", nil).Return(tc.PathSeparator)
-		env.On("homeDir", nil).Return("/usr/home")
-		env.On("getcwd", nil).Return(tc.Pwd)
-		env.On("getRuntimeGOOS", nil).Return(tc.GOOS)
-		env.On("stackCount", nil).Return(tc.StackCount)
+		env.On("getPathSeperator").Return(tc.PathSeparator)
+		env.On("homeDir").Return("/usr/home")
+		env.On("getcwd").Return(tc.Pwd)
+		env.On("getRuntimeGOOS").Return(tc.GOOS)
+		env.On("stackCount").Return(tc.StackCount)
 		args := &args{
 			PSWD: &tc.Pswd,
 		}
-		env.On("getArgs", nil).Return(args)
+		env.On("getArgs").Return(args)
 		env.onTemplate()
 		if len(tc.Template) == 0 {
 			tc.Template = "{{ if gt .StackCount 0 }}{{ .StackCount }} {{ end }}{{ .Path }}"
@@ -599,14 +619,14 @@ func TestGetFullPathCustomMappedLocations(t *testing.T) {
 
 	for _, tc := range cases {
 		env := new(MockedEnvironment)
-		env.On("getPathSeperator", nil).Return("/")
-		env.On("homeDir", nil).Return("/usr/home")
-		env.On("getcwd", nil).Return(tc.Pwd)
-		env.On("getRuntimeGOOS", nil).Return("")
+		env.On("getPathSeperator").Return("/")
+		env.On("homeDir").Return("/usr/home")
+		env.On("getcwd").Return(tc.Pwd)
+		env.On("getRuntimeGOOS").Return("")
 		args := &args{
 			PSWD: &tc.Pwd,
 		}
-		env.On("getArgs", nil).Return(args)
+		env.On("getArgs").Return(args)
 		path := &path{
 			env: env,
 			props: properties{
@@ -637,8 +657,8 @@ func TestNormalizePath(t *testing.T) {
 
 	for _, tc := range cases {
 		env := new(MockedEnvironment)
-		env.On("homeDir", nil).Return("/usr/home")
-		env.On("getRuntimeGOOS", nil).Return(tc.GOOS)
+		env.On("homeDir").Return("/usr/home")
+		env.On("getRuntimeGOOS").Return(tc.GOOS)
 		pt := &path{
 			env: env,
 		}
@@ -650,14 +670,14 @@ func TestNormalizePath(t *testing.T) {
 func TestGetFolderPathCustomMappedLocations(t *testing.T) {
 	pwd := "/a/b/c/d"
 	env := new(MockedEnvironment)
-	env.On("getPathSeperator", nil).Return("/")
-	env.On("homeDir", nil).Return("/usr/home")
-	env.On("getcwd", nil).Return(pwd)
-	env.On("getRuntimeGOOS", nil).Return("")
+	env.On("getPathSeperator").Return("/")
+	env.On("homeDir").Return("/usr/home")
+	env.On("getcwd").Return(pwd)
+	env.On("getRuntimeGOOS").Return("")
 	args := &args{
 		PSWD: &pwd,
 	}
-	env.On("getArgs", nil).Return(args)
+	env.On("getArgs").Return(args)
 	path := &path{
 		env: env,
 		props: properties{
@@ -697,14 +717,14 @@ func TestAgnosterPath(t *testing.T) { // nolint:dupl
 
 	for _, tc := range cases {
 		env := new(MockedEnvironment)
-		env.On("homeDir", nil).Return(tc.Home)
-		env.On("getPathSeperator", nil).Return(tc.PathSeparator)
-		env.On("getcwd", nil).Return(tc.PWD)
-		env.On("getRuntimeGOOS", nil).Return("")
+		env.On("homeDir").Return(tc.Home)
+		env.On("getPathSeperator").Return(tc.PathSeparator)
+		env.On("getcwd").Return(tc.PWD)
+		env.On("getRuntimeGOOS").Return("")
 		args := &args{
 			PSWD: &tc.PWD,
 		}
-		env.On("getArgs", nil).Return(args)
+		env.On("getArgs").Return(args)
 		path := &path{
 			env: env,
 			props: properties{
@@ -745,14 +765,14 @@ func TestAgnosterLeftPath(t *testing.T) { // nolint:dupl
 
 	for _, tc := range cases {
 		env := new(MockedEnvironment)
-		env.On("homeDir", nil).Return(tc.Home)
-		env.On("getPathSeperator", nil).Return(tc.PathSeparator)
-		env.On("getcwd", nil).Return(tc.PWD)
-		env.On("getRuntimeGOOS", nil).Return("")
+		env.On("homeDir").Return(tc.Home)
+		env.On("getPathSeperator").Return(tc.PathSeparator)
+		env.On("getcwd").Return(tc.PWD)
+		env.On("getRuntimeGOOS").Return("")
 		args := &args{
 			PSWD: &tc.PWD,
 		}
-		env.On("getArgs", nil).Return(args)
+		env.On("getArgs").Return(args)
 		path := &path{
 			env: env,
 			props: properties{
@@ -793,14 +813,14 @@ func TestGetPwd(t *testing.T) {
 
 	for _, tc := range cases {
 		env := new(MockedEnvironment)
-		env.On("getPathSeperator", nil).Return("/")
-		env.On("homeDir", nil).Return("/usr/home")
-		env.On("getcwd", nil).Return(tc.Pwd)
-		env.On("getRuntimeGOOS", nil).Return("")
+		env.On("getPathSeperator").Return("/")
+		env.On("homeDir").Return("/usr/home")
+		env.On("getcwd").Return(tc.Pwd)
+		env.On("getRuntimeGOOS").Return("")
 		args := &args{
 			PSWD: &tc.Pswd,
 		}
-		env.On("getArgs", nil).Return(args)
+		env.On("getArgs").Return(args)
 		path := &path{
 			env: env,
 			props: properties{
diff --git a/src/segment_plastic_test.go b/src/segment_plastic_test.go
index c34f877d..465bb0c3 100644
--- a/src/segment_plastic_test.go
+++ b/src/segment_plastic_test.go
@@ -9,8 +9,8 @@ import (
 func TestPlasticEnabledNotFound(t *testing.T) {
 	env := new(MockedEnvironment)
 	env.On("hasCommand", "cm").Return(false)
-	env.On("getRuntimeGOOS", nil).Return("")
-	env.On("isWsl", nil).Return(false)
+	env.On("getRuntimeGOOS").Return("")
+	env.On("isWsl").Return(false)
 	p := &plastic{
 		scm: scm{
 			env:   env,
@@ -23,8 +23,8 @@ func TestPlasticEnabledNotFound(t *testing.T) {
 func TestPlasticEnabledInWorkspaceDirectory(t *testing.T) {
 	env := new(MockedEnvironment)
 	env.On("hasCommand", "cm").Return(true)
-	env.On("getRuntimeGOOS", nil).Return("")
-	env.On("isWsl", nil).Return(false)
+	env.On("getRuntimeGOOS").Return("")
+	env.On("isWsl").Return(false)
 	fileInfo := &fileInfo{
 		path:         "/dir/hello",
 		parentFolder: "/dir",
diff --git a/src/segment_python_test.go b/src/segment_python_test.go
index e6c63c61..2f245efb 100644
--- a/src/segment_python_test.go
+++ b/src/segment_python_test.go
@@ -49,9 +49,9 @@ func TestPythonTemplate(t *testing.T) {
 		env.On("getenv", "CONDA_ENV_PATH").Return(tc.VirtualEnvName)
 		env.On("getenv", "CONDA_DEFAULT_ENV").Return(tc.VirtualEnvName)
 		env.On("getenv", "PYENV_VERSION").Return(tc.VirtualEnvName)
-		env.On("getPathSeperator", nil).Return("")
-		env.On("getcwd", nil).Return("/usr/home/project")
-		env.On("homeDir", nil).Return("/usr/home")
+		env.On("getPathSeperator").Return("")
+		env.On("getcwd").Return("/usr/home/project")
+		env.On("homeDir").Return("/usr/home")
 		env.onTemplate()
 		props := properties{
 			FetchVersion:    tc.FetchVersion,
@@ -76,7 +76,7 @@ func TestPythonPythonInContext(t *testing.T) {
 
 	for _, tc := range cases {
 		env := new(MockedEnvironment)
-		env.On("getPathSeperator", nil).Return("")
+		env.On("getPathSeperator").Return("")
 		env.On("getenv", "VIRTUAL_ENV").Return(tc.VirtualEnvName)
 		env.On("getenv", "CONDA_ENV_PATH").Return("")
 		env.On("getenv", "CONDA_DEFAULT_ENV").Return("")
diff --git a/src/segment_ruby_test.go b/src/segment_ruby_test.go
index bdb2d5fa..37cdd3d3 100644
--- a/src/segment_ruby_test.go
+++ b/src/segment_ruby_test.go
@@ -96,8 +96,8 @@ func TestRuby(t *testing.T) {
 		env.On("hasFiles", "*.rb").Return(tc.HasRubyFiles)
 		env.On("hasFiles", "Rakefile").Return(tc.HasRakeFile)
 		env.On("hasFiles", "Gemfile").Return(tc.HasGemFile)
-		env.On("getcwd", nil).Return("/usr/home/project")
-		env.On("homeDir", nil).Return("/usr/home")
+		env.On("getcwd").Return("/usr/home/project")
+		env.On("homeDir").Return("/usr/home")
 		env.onTemplate()
 		props := properties{
 			FetchVersion: tc.FetchVersion,
diff --git a/src/segment_session_test.go b/src/segment_session_test.go
index 2877064f..fa995319 100644
--- a/src/segment_session_test.go
+++ b/src/segment_session_test.go
@@ -96,16 +96,16 @@ func TestSessionSegmentTemplate(t *testing.T) {
 
 	for _, tc := range cases {
 		env := new(MockedEnvironment)
-		env.On("getCurrentUser", nil).Return(tc.UserName)
-		env.On("getRuntimeGOOS", nil).Return("burp")
-		env.On("getHostName", nil).Return(tc.ComputerName, nil)
+		env.On("getCurrentUser").Return(tc.UserName)
+		env.On("getRuntimeGOOS").Return("burp")
+		env.On("getHostName").Return(tc.ComputerName, nil)
 		var SSHSession string
 		if tc.SSHSession {
 			SSHSession = "zezzion"
 		}
 		env.On("getenv", "SSH_CONNECTION").Return(SSHSession)
 		env.On("getenv", "SSH_CLIENT").Return(SSHSession)
-		env.On("isRunningAsRoot", nil).Return(tc.Root)
+		env.On("isRunningAsRoot").Return(tc.Root)
 		env.On("getenv", defaultUserEnvVar).Return(tc.DefaultUserName)
 		env.onTemplate()
 		session := &session{
diff --git a/src/segment_shell_test.go b/src/segment_shell_test.go
index b48c8b2a..d8be4fb6 100644
--- a/src/segment_shell_test.go
+++ b/src/segment_shell_test.go
@@ -9,7 +9,7 @@ import (
 func TestWriteCurrentShell(t *testing.T) {
 	expected := "zsh"
 	env := new(MockedEnvironment)
-	env.On("getShellName", nil).Return(expected, nil)
+	env.On("getShellName").Return(expected, nil)
 	s := &shell{
 		env:   env,
 		props: properties{},
@@ -28,7 +28,7 @@ func TestUseMappedShellNames(t *testing.T) {
 	}
 	for _, tc := range cases {
 		env := new(MockedEnvironment)
-		env.On("getShellName", nil).Return(tc.Expected, nil)
+		env.On("getShellName").Return(tc.Expected, nil)
 		s := &shell{
 			env: env,
 			props: properties{
diff --git a/src/segment_spotify_wsl_test.go b/src/segment_spotify_wsl_test.go
index 70905388..2b9316bf 100644
--- a/src/segment_spotify_wsl_test.go
+++ b/src/segment_spotify_wsl_test.go
@@ -52,7 +52,7 @@ func TestSpotifyWsl(t *testing.T) {
 	}
 	for _, tc := range cases {
 		env := new(MockedEnvironment)
-		env.On("isWsl", nil).Return(true)
+		env.On("isWsl").Return(true)
 		env.On("runCommand", "tasklist.exe", []string{"/V", "/FI", "Imagename eq Spotify.exe", "/FO", "CSV", "/NH"}).Return(tc.ExecOutput, nil)
 		s := &spotify{
 			env:   env,
diff --git a/src/segment_strava_test.go b/src/segment_strava_test.go
index ed1faa54..b659e0bf 100644
--- a/src/segment_strava_test.go
+++ b/src/segment_strava_test.go
@@ -153,7 +153,7 @@ func TestStravaSegment(t *testing.T) {
 
 		env.On("HTTPRequest", url).Return([]byte(tc.JSONResponse), tc.Error)
 		env.On("HTTPRequest", tokenURL).Return([]byte(tc.TokenResponse), tc.Error)
-		env.On("cache", nil).Return(cache)
+		env.On("cache").Return(cache)
 		env.onTemplate()
 
 		if tc.Template != "" {
diff --git a/src/segment_terraform_test.go b/src/segment_terraform_test.go
index c8d40a28..23768174 100644
--- a/src/segment_terraform_test.go
+++ b/src/segment_terraform_test.go
@@ -16,7 +16,7 @@ func bootStrapTerraformTest(args *terraformArgs) *terraform {
 	env := new(MockedEnvironment)
 	env.On("hasCommand", "terraform").Return(args.hasTfCommand)
 	env.On("hasFolder", "/.terraform").Return(args.hasTfFolder)
-	env.On("getcwd", nil).Return("")
+	env.On("getcwd").Return("")
 	env.On("runCommand", "terraform", []string{"workspace", "show"}).Return(args.workspaceName, nil)
 	env.onTemplate()
 	k := &terraform{
diff --git a/src/segment_test.go b/src/segment_test.go
index 213ab4d5..69c7efb0 100644
--- a/src/segment_test.go
+++ b/src/segment_test.go
@@ -80,9 +80,9 @@ func TestShouldIncludeFolder(t *testing.T) {
 	}
 	for _, tc := range cases {
 		env := new(MockedEnvironment)
-		env.On("getRuntimeGOOS", nil).Return(linuxPlatform)
-		env.On("homeDir", nil).Return("")
-		env.On("getcwd", nil).Return(cwd)
+		env.On("getRuntimeGOOS").Return(linuxPlatform)
+		env.On("homeDir").Return("")
+		env.On("getcwd").Return(cwd)
 		segment := &Segment{
 			Properties: properties{
 				IncludeFolders: tc.IncludeFolders,
@@ -97,9 +97,9 @@ func TestShouldIncludeFolder(t *testing.T) {
 
 func TestShouldIncludeFolderRegexInverted(t *testing.T) {
 	env := new(MockedEnvironment)
-	env.On("getRuntimeGOOS", nil).Return(linuxPlatform)
-	env.On("homeDir", nil).Return("")
-	env.On("getcwd", nil).Return(cwd)
+	env.On("getRuntimeGOOS").Return(linuxPlatform)
+	env.On("homeDir").Return("")
+	env.On("getcwd").Return(cwd)
 	segment := &Segment{
 		Properties: properties{
 			ExcludeFolders: []string{"(?!Projects[\\/]).*"},
@@ -118,9 +118,9 @@ func TestShouldIncludeFolderRegexInverted(t *testing.T) {
 
 func TestShouldIncludeFolderRegexInvertedNonEscaped(t *testing.T) {
 	env := new(MockedEnvironment)
-	env.On("getRuntimeGOOS", nil).Return(linuxPlatform)
-	env.On("homeDir", nil).Return("")
-	env.On("getcwd", nil).Return(cwd)
+	env.On("getRuntimeGOOS").Return(linuxPlatform)
+	env.On("homeDir").Return("")
+	env.On("getcwd").Return(cwd)
 	segment := &Segment{
 		Properties: properties{
 			ExcludeFolders: []string{"(?!Projects/).*"},
diff --git a/src/segment_text_test.go b/src/segment_text_test.go
index 2859a643..d8608f8f 100644
--- a/src/segment_text_test.go
+++ b/src/segment_text_test.go
@@ -24,15 +24,15 @@ func TestTextSegment(t *testing.T) {
 
 	for _, tc := range cases {
 		env := new(MockedEnvironment)
-		env.On("getcwd", nil).Return("/usr/home/posh")
-		env.On("homeDir", nil).Return("/usr/home")
-		env.On("getPathSeperator", nil).Return("/")
-		env.On("isRunningAsRoot", nil).Return(true)
-		env.On("getShellName", nil).Return("terminal")
+		env.On("getcwd").Return("/usr/home/posh")
+		env.On("homeDir").Return("/usr/home")
+		env.On("getPathSeperator").Return("/")
+		env.On("isRunningAsRoot").Return(true)
+		env.On("getShellName").Return("terminal")
 		env.On("getenv", "HELLO").Return("hello")
 		env.On("getenv", "WORLD").Return("")
-		env.On("getCurrentUser", nil).Return("Posh")
-		env.On("getHostName", nil).Return("MyHost", nil)
+		env.On("getCurrentUser").Return("Posh")
+		env.On("getHostName").Return("MyHost", nil)
 		env.onTemplate()
 		txt := &text{
 			env: env,
diff --git a/src/segment_wakatime_test.go b/src/segment_wakatime_test.go
index cc93891f..7bffc452 100644
--- a/src/segment_wakatime_test.go
+++ b/src/segment_wakatime_test.go
@@ -76,7 +76,7 @@ func TestWTTrackedTime(t *testing.T) {
 		cache := &MockedCache{}
 		cache.On("get", FAKEAPIURL).Return(response, !tc.CacheFoundFail)
 		cache.On("set", FAKEAPIURL, response, tc.CacheTimeout).Return()
-		env.On("cache", nil).Return(cache)
+		env.On("cache").Return(cache)
 		env.onTemplate()
 
 		w := &wakatime{
diff --git a/src/segment_wifi_test.go b/src/segment_wifi_test.go
index dc4a155b..5ef8c4a0 100644
--- a/src/segment_wifi_test.go
+++ b/src/segment_wifi_test.go
@@ -42,9 +42,9 @@ func TestWiFiSegment(t *testing.T) {
 
 	for _, tc := range cases {
 		env := new(MockedEnvironment)
-		env.On("getPlatform", nil).Return(windowsPlatform)
-		env.On("isWsl", nil).Return(false)
-		env.On("getWifiNetwork", nil).Return(tc.Network, tc.WifiError)
+		env.On("getPlatform").Return(windowsPlatform)
+		env.On("isWsl").Return(false)
+		env.On("getWifiNetwork").Return(tc.Network, tc.WifiError)
 		env.onTemplate()
 
 		w := &wifi{
diff --git a/src/segment_winreg_test.go b/src/segment_winreg_test.go
index 5208704c..76f7290a 100644
--- a/src/segment_winreg_test.go
+++ b/src/segment_winreg_test.go
@@ -71,7 +71,7 @@ func TestWinReg(t *testing.T) {
 
 	for _, tc := range cases {
 		env := new(MockedEnvironment)
-		env.On("getRuntimeGOOS", nil).Return(windowsPlatform)
+		env.On("getRuntimeGOOS").Return(windowsPlatform)
 		env.On("getWindowsRegistryKeyValue", tc.Path).Return(tc.getWRKVOutput, tc.Err)
 		env.onTemplate()
 		r := &winreg{
diff --git a/src/template_test.go b/src/template_test.go
index 2e532257..c62fd465 100644
--- a/src/template_test.go
+++ b/src/template_test.go
@@ -121,10 +121,10 @@ func TestRenderTemplateEnvVar(t *testing.T) {
 	}
 	for _, tc := range cases {
 		env := &MockedEnvironment{}
-		env.onTemplate()
 		for name, value := range tc.Env {
 			env.On("getenv", name).Return(value)
 		}
+		env.onTemplate()
 		template := &textTemplate{
 			Template: tc.Template,
 			Context:  tc.Context,