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:
Chris Donnelly 2021-06-16 11:52:42 -05:00 committed by Jan De Dobbeleer
parent 90b4996e55
commit 2ab35b0eec
2 changed files with 23 additions and 6 deletions

View file

@ -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 ")
}

View file

@ -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)