forked from cerc-io/plugeth
Use filepath.clean instead of path.clean (#26404)
* internal/flags: use filepath.Clean instead of path.Clean * internal/flags: fix windows pipe issue * internal/flags: modify test for windows * internal/flags: use backticks, fix test
This commit is contained in:
@@ -19,23 +19,43 @@ package flags
|
||||
import (
|
||||
"os"
|
||||
"os/user"
|
||||
"runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPathExpansion(t *testing.T) {
|
||||
user, _ := user.Current()
|
||||
tests := map[string]string{
|
||||
"/home/someuser/tmp": "/home/someuser/tmp",
|
||||
"~/tmp": user.HomeDir + "/tmp",
|
||||
"~thisOtherUser/b/": "~thisOtherUser/b",
|
||||
"$DDDXXX/a/b": "/tmp/a/b",
|
||||
"/a/b/": "/a/b",
|
||||
var tests map[string]string
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
tests = map[string]string{
|
||||
`/home/someuser/tmp`: `\home\someuser\tmp`,
|
||||
`~/tmp`: user.HomeDir + `\tmp`,
|
||||
`~thisOtherUser/b/`: `~thisOtherUser\b`,
|
||||
`$DDDXXX/a/b`: `\tmp\a\b`,
|
||||
`/a/b/`: `\a\b`,
|
||||
`C:\Documents\Newsletters\`: `C:\Documents\Newsletters`,
|
||||
`C:\`: `C:\`,
|
||||
`\\.\pipe\\pipe\geth621383`: `\\.\pipe\\pipe\geth621383`,
|
||||
}
|
||||
} else {
|
||||
tests = map[string]string{
|
||||
`/home/someuser/tmp`: `/home/someuser/tmp`,
|
||||
`~/tmp`: user.HomeDir + `/tmp`,
|
||||
`~thisOtherUser/b/`: `~thisOtherUser/b`,
|
||||
`$DDDXXX/a/b`: `/tmp/a/b`,
|
||||
`/a/b/`: `/a/b`,
|
||||
`C:\Documents\Newsletters\`: `C:\Documents\Newsletters\`,
|
||||
`C:\`: `C:\`,
|
||||
`\\.\pipe\\pipe\geth621383`: `\\.\pipe\\pipe\geth621383`,
|
||||
}
|
||||
}
|
||||
os.Setenv("DDDXXX", "/tmp")
|
||||
|
||||
os.Setenv(`DDDXXX`, `/tmp`)
|
||||
for test, expected := range tests {
|
||||
got := expandPath(test)
|
||||
if got != expected {
|
||||
t.Errorf("test %s, got %s, expected %s\n", test, got, expected)
|
||||
t.Errorf(`test %s, got %s, expected %s\n`, test, got, expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user