-
-
Notifications
You must be signed in to change notification settings - Fork 140
/
mapper_windows_test.go
45 lines (39 loc) · 1.16 KB
/
mapper_windows_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//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.NotZero(t, cli.File, "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)
}