2022-01-26 06:54:36 -08:00
|
|
|
package segments
|
2020-10-16 08:43:02 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-01-05 12:57:38 -08:00
|
|
|
"github.com/jandedobbeleer/oh-my-posh/src/constants"
|
|
|
|
"github.com/jandedobbeleer/oh-my-posh/src/mock"
|
|
|
|
"github.com/jandedobbeleer/oh-my-posh/src/platform"
|
|
|
|
"github.com/jandedobbeleer/oh-my-posh/src/properties"
|
2022-12-28 08:30:48 -08:00
|
|
|
|
2020-10-16 08:43:02 -07:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2022-01-23 12:37:51 -08:00
|
|
|
func TestDotnetSegment(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
Case string
|
|
|
|
Expected string
|
|
|
|
ExitCode int
|
|
|
|
HasCommand bool
|
|
|
|
Version string
|
|
|
|
FetchVersion bool
|
|
|
|
}{
|
2022-01-26 06:54:36 -08:00
|
|
|
{Case: "Unsupported version", Expected: "\uf071", HasCommand: true, FetchVersion: true, ExitCode: constants.DotnetExitCode, Version: "3.1.402"},
|
2022-01-23 12:37:51 -08:00
|
|
|
{Case: "Regular version", Expected: "3.1.402", HasCommand: true, FetchVersion: true, Version: "3.1.402"},
|
|
|
|
{Case: "Regular version", Expected: "", HasCommand: true, FetchVersion: false, Version: "3.1.402"},
|
|
|
|
{Case: "Regular version", Expected: "", HasCommand: false, FetchVersion: false, Version: "3.1.402"},
|
2020-10-16 08:43:02 -07:00
|
|
|
}
|
|
|
|
|
2022-01-23 12:37:51 -08:00
|
|
|
for _, tc := range cases {
|
2022-01-26 01:23:18 -08:00
|
|
|
env := new(mock.MockedEnvironment)
|
2022-01-23 12:37:51 -08:00
|
|
|
env.On("HasCommand", "dotnet").Return(tc.HasCommand)
|
|
|
|
if tc.ExitCode != 0 {
|
2022-11-09 11:27:54 -08:00
|
|
|
err := &platform.CommandError{ExitCode: tc.ExitCode}
|
2022-01-23 12:37:51 -08:00
|
|
|
env.On("RunCommand", "dotnet", []string{"--version"}).Return("", err)
|
|
|
|
} else {
|
|
|
|
env.On("RunCommand", "dotnet", []string{"--version"}).Return(tc.Version, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
env.On("HasFiles", "*.cs").Return(true)
|
2022-02-19 10:04:06 -08:00
|
|
|
env.On("PathSeparator").Return("")
|
2022-01-23 12:37:51 -08:00
|
|
|
env.On("Pwd").Return("/usr/home/project")
|
|
|
|
env.On("Home").Return("/usr/home")
|
2022-11-09 11:27:54 -08:00
|
|
|
env.On("TemplateCache").Return(&platform.TemplateCache{
|
2022-01-23 12:37:51 -08:00
|
|
|
Env: make(map[string]string),
|
|
|
|
})
|
2022-01-26 04:53:35 -08:00
|
|
|
props := properties.Map{
|
|
|
|
properties.FetchVersion: tc.FetchVersion,
|
2022-01-23 12:37:51 -08:00
|
|
|
}
|
2022-01-26 05:10:18 -08:00
|
|
|
dotnet := &Dotnet{}
|
2022-01-26 05:26:56 -08:00
|
|
|
dotnet.Init(props, env)
|
|
|
|
assert.True(t, dotnet.Enabled())
|
|
|
|
assert.Equal(t, tc.Expected, renderTemplate(env, dotnet.Template(), dotnet), tc.Case)
|
2020-10-16 08:43:02 -07:00
|
|
|
}
|
|
|
|
}
|