github.com/ethereum/go-ethereum@v1.16.1/internal/flags/flags_test.go (about) 1 // Copyright 2015 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package flags 18 19 import ( 20 "os/user" 21 "runtime" 22 "testing" 23 ) 24 25 func TestPathExpansion(t *testing.T) { 26 user, _ := user.Current() 27 var tests map[string]string 28 29 if runtime.GOOS == "windows" { 30 tests = map[string]string{ 31 `/home/someuser/tmp`: `\home\someuser\tmp`, 32 `~/tmp`: user.HomeDir + `\tmp`, 33 `~thisOtherUser/b/`: `~thisOtherUser\b`, 34 `$DDDXXX/a/b`: `\tmp\a\b`, 35 `/a/b/`: `\a\b`, 36 `C:\Documents\Newsletters\`: `C:\Documents\Newsletters`, 37 `C:\`: `C:\`, 38 `\\.\pipe\\pipe\geth621383`: `\\.\pipe\\pipe\geth621383`, 39 } 40 } else { 41 tests = map[string]string{ 42 `/home/someuser/tmp`: `/home/someuser/tmp`, 43 `~/tmp`: user.HomeDir + `/tmp`, 44 `~thisOtherUser/b/`: `~thisOtherUser/b`, 45 `$DDDXXX/a/b`: `/tmp/a/b`, 46 `/a/b/`: `/a/b`, 47 `C:\Documents\Newsletters\`: `C:\Documents\Newsletters\`, 48 `C:\`: `C:\`, 49 `\\.\pipe\\pipe\geth621383`: `\\.\pipe\\pipe\geth621383`, 50 } 51 } 52 53 t.Setenv(`DDDXXX`, `/tmp`) 54 for test, expected := range tests { 55 t.Run(test, func(t *testing.T) { 56 t.Parallel() 57 58 got := expandPath(test) 59 if got != expected { 60 t.Errorf(`test %s, got %s, expected %s\n`, test, got, expected) 61 } 62 }) 63 } 64 }