mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-13 04:07:25 -08:00
feat(dotnet): correct exit code on Windows
dotnet on windows returns a 32-bit exit code. https://github.com/dotnet/runtime/blob/main/docs/design/features/host-error-codes.md
This commit is contained in:
parent
90b4996e55
commit
2ab35b0eec
|
@ -8,15 +8,19 @@ const (
|
|||
// UnsupportedDotnetVersionIcon is displayed when the dotnet version in
|
||||
// the current folder isn't supported by the installed dotnet SDK set.
|
||||
UnsupportedDotnetVersionIcon Property = "unsupported_version_icon"
|
||||
|
||||
dotnetExitCodeUnix = 145
|
||||
dotnetExitCodeWindows = -2147450735
|
||||
)
|
||||
|
||||
func (d *dotnet) string() string {
|
||||
version := d.language.string()
|
||||
|
||||
// Exit code 145 is a special indicator that dotnet
|
||||
// Exit codes 145 and 0x80008091 are special indicators that dotnet
|
||||
// ran, but the current project config settings specify
|
||||
// use of an SDK that isn't installed.
|
||||
if d.language.exitCode == 145 {
|
||||
exitCode := d.language.exitCode
|
||||
if exitCode == dotnetExitCodeWindows || exitCode == dotnetExitCodeUnix {
|
||||
return d.language.props.getString(UnsupportedDotnetVersionIcon, "\uf071 ")
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
type dotnetArgs struct {
|
||||
enabled bool
|
||||
version string
|
||||
unsupported bool
|
||||
exitCode int
|
||||
unsupportedIcon string
|
||||
displayVersion bool
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ type dotnetArgs struct {
|
|||
func bootStrapDotnetTest(args *dotnetArgs) *dotnet {
|
||||
env := new(MockedEnvironment)
|
||||
env.On("hasCommand", "dotnet").Return(args.enabled)
|
||||
if args.unsupported {
|
||||
err := &commandError{exitCode: 145}
|
||||
if args.exitCode != 0 {
|
||||
err := &commandError{exitCode: args.exitCode}
|
||||
env.On("runCommand", "dotnet", []string{"--version"}).Return("", err)
|
||||
} else {
|
||||
env.On("runCommand", "dotnet", []string{"--version"}).Return(args.version, nil)
|
||||
|
@ -75,7 +75,20 @@ func TestDotnetVersionUnsupported(t *testing.T) {
|
|||
args := &dotnetArgs{
|
||||
enabled: true,
|
||||
displayVersion: true,
|
||||
unsupported: true,
|
||||
exitCode: dotnetExitCodeUnix,
|
||||
unsupportedIcon: expected,
|
||||
}
|
||||
dotnet := bootStrapDotnetTest(args)
|
||||
assert.True(t, dotnet.enabled())
|
||||
assert.Equal(t, expected, dotnet.string())
|
||||
}
|
||||
|
||||
func TestDotnetVersionUnsupportedWindows(t *testing.T) {
|
||||
expected := "x"
|
||||
args := &dotnetArgs{
|
||||
enabled: true,
|
||||
displayVersion: true,
|
||||
exitCode: dotnetExitCodeWindows,
|
||||
unsupportedIcon: expected,
|
||||
}
|
||||
dotnet := bootStrapDotnetTest(args)
|
||||
|
|
Loading…
Reference in a new issue