3263463a7e
* ci: Test on Windows too Adds a Windows test run to CI. Go setup relies on GHA for this because Hermit doesn't yet support Windows. * fix(mapper_windows_test): assert.NotNil => assert.True assert.NotNil does not exist. * filecontent mapper: Handle error from directory If we couldn't read because the source is a directory, override the original error message. * fix(test): Handle platform-specific "file not found" messages
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
//go:build windows
|
|
// +build windows
|
|
|
|
package kong_test
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/alecthomas/assert/v2"
|
|
)
|
|
|
|
func TestWindowsPathMapper(t *testing.T) {
|
|
var cli struct {
|
|
Path string `short:"p" type:"path"`
|
|
Files []string `short:"f" type:"path"`
|
|
}
|
|
wd, err := os.Getwd()
|
|
assert.NoError(t, err, "Getwd failed")
|
|
p := mustNew(t, &cli)
|
|
|
|
_, err = p.Parse([]string{`-p`, `c:\an\absolute\path`, `-f`, `c:\second\absolute\path\`, `-f`, `relative\path\file`})
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, `c:\an\absolute\path`, cli.Path)
|
|
assert.Equal(t, []string{`c:\second\absolute\path\`, wd + `\relative\path\file`}, cli.Files)
|
|
}
|
|
|
|
func TestWindowsFileMapper(t *testing.T) {
|
|
type CLI struct {
|
|
File *os.File `arg:""`
|
|
}
|
|
var cli CLI
|
|
p := mustNew(t, &cli)
|
|
_, err := p.Parse([]string{"testdata\\file.txt"})
|
|
assert.NoError(t, err)
|
|
assert.True(t, cli.File != nil, "File should not be nil")
|
|
_ = cli.File.Close()
|
|
_, err = p.Parse([]string{"testdata\\missing.txt"})
|
|
assert.Error(t, err)
|
|
assert.Contains(t, err.Error(), "missing.txt:")
|
|
assert.IsError(t, err, os.ErrNotExist)
|
|
_, err = p.Parse([]string{"-"})
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, os.Stdin, cli.File)
|
|
}
|