Skip to content

Commit 698e98d

Browse files
committed
Merge pull request bnb-chain#1600 from ethereum/fix-tests-windows
Fix tests on windows
2 parents a3b8169 + 803096c commit 698e98d

14 files changed

Lines changed: 59 additions & 96 deletions

File tree

‎.gitattributes‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

‎cmd/utils/customflags.go‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"fmt"
2222
"os"
2323
"os/user"
24-
"path/filepath"
24+
"path"
2525
"strings"
2626

2727
"github.com/codegangsta/cli"
@@ -138,11 +138,8 @@ func (self *DirectoryFlag) Set(value string) {
138138
func expandPath(p string) string {
139139
if strings.HasPrefix(p, "~/") || strings.HasPrefix(p, "~\\") {
140140
if user, err := user.Current(); err == nil {
141-
if err == nil {
142-
p = strings.Replace(p, "~", user.HomeDir, 1)
143-
}
141+
p = user.HomeDir + p[1:]
144142
}
145143
}
146-
147-
return filepath.Clean(os.ExpandEnv(p))
144+
return path.Clean(os.ExpandEnv(p))
148145
}

‎cmd/utils/customflags_test.go‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,15 @@ import (
2323
)
2424

2525
func TestPathExpansion(t *testing.T) {
26-
2726
user, _ := user.Current()
28-
2927
tests := map[string]string{
3028
"/home/someuser/tmp": "/home/someuser/tmp",
3129
"~/tmp": user.HomeDir + "/tmp",
30+
"~thisOtherUser/b/": "~thisOtherUser/b",
3231
"$DDDXXX/a/b": "/tmp/a/b",
3332
"/a/b/": "/a/b",
3433
}
35-
3634
os.Setenv("DDDXXX", "/tmp")
37-
3835
for test, expected := range tests {
3936
got := expandPath(test)
4037
if got != expected {

‎cmd/utils/flags.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ func MakeAccountManager(ctx *cli.Context) *accounts.Manager {
478478
}
479479

480480
func IpcSocketPath(ctx *cli.Context) (ipcpath string) {
481-
if common.IsWindows() {
481+
if runtime.GOOS == "windows" {
482482
ipcpath = common.DefaultIpcPath()
483483
if ctx.GlobalIsSet(IPCPathFlag.Name) {
484484
ipcpath = ctx.GlobalString(IPCPathFlag.Name)

‎common/compiler/solidity_test.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"encoding/json"
2121
"io/ioutil"
2222
"os"
23+
"path"
2324
"testing"
2425

2526
"github.com/ethereum/go-ethereum/common"
@@ -94,7 +95,7 @@ func TestSaveInfo(t *testing.T) {
9495
if err != nil {
9596
t.Errorf("%v", err)
9697
}
97-
filename := "/tmp/solctest.info.json"
98+
filename := path.Join(os.TempDir(), "solctest.info.json")
9899
os.Remove(filename)
99100
cinfohash, err := SaveInfo(&cinfo, filename)
100101
if err != nil {
@@ -110,4 +111,4 @@ func TestSaveInfo(t *testing.T) {
110111
if cinfohash != infohash {
111112
t.Errorf("content hash for info is incorrect. expected %v, got %v", infohash.Hex(), cinfohash.Hex())
112113
}
113-
}
114+
}

‎common/docserver/docserver.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ func New(docRoot string) (self *DocServer) {
3838
DocRoot: docRoot,
3939
schemes: []string{"file"},
4040
}
41-
self.DocRoot = "/tmp/"
4241
self.RegisterProtocol("file", http.NewFileTransport(http.Dir(self.DocRoot)))
4342
return
4443
}

‎common/docserver/docserver_test.go‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,26 @@ import (
2020
"io/ioutil"
2121
"net/http"
2222
"os"
23+
"path"
2324
"testing"
2425

2526
"github.com/ethereum/go-ethereum/common"
2627
"github.com/ethereum/go-ethereum/crypto"
2728
)
2829

2930
func TestGetAuthContent(t *testing.T) {
30-
text := "test"
31-
hash := common.Hash{}
32-
copy(hash[:], crypto.Sha3([]byte(text)))
33-
ioutil.WriteFile("/tmp/test.content", []byte(text), os.ModePerm)
31+
dir, err := ioutil.TempDir("", "docserver-test")
32+
if err != nil {
33+
t.Fatal("cannot create temporary directory:", err)
34+
}
35+
defer os.RemoveAll(dir)
36+
ds := New(dir)
3437

35-
ds := New("/tmp/")
38+
text := "test"
39+
hash := crypto.Sha3Hash([]byte(text))
40+
if err := ioutil.WriteFile(path.Join(dir, "test.content"), []byte(text), os.ModePerm); err != nil {
41+
t.Fatal("could not write test file", err)
42+
}
3643
content, err := ds.GetAuthContent("file:///test.content", hash)
3744
if err != nil {
3845
t.Errorf("no error expected, got %v", err)
@@ -67,4 +74,4 @@ func TestRegisterScheme(t *testing.T) {
6774
if !ds.HasScheme("scheme") {
6875
t.Errorf("expected scheme to be registered")
6976
}
70-
}
77+
}

‎common/path.go‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,3 @@ func DefaultIpcPath() string {
116116
}
117117
return filepath.Join(DefaultDataDir(), "geth.ipc")
118118
}
119-
120-
func IsWindows() bool {
121-
return runtime.GOOS == "windows"
122-
}
123-
124-
func WindonizePath(path string) string {
125-
if string(path[0]) == "/" && IsWindows() {
126-
path = path[1:]
127-
}
128-
return path
129-
}

‎common/path_test.go‎

Lines changed: 0 additions & 52 deletions
This file was deleted.

‎common/size_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (s *SizeSuite) TestStorageSizeString(c *checker.C) {
4040
c.Assert(StorageSize(data3).String(), checker.Equals, exp3)
4141
}
4242

43-
func (s *CommonSuite) TestCommon(c *checker.C) {
43+
func (s *SizeSuite) TestCommon(c *checker.C) {
4444
ether := CurrencyToString(BigPow(10, 19))
4545
finney := CurrencyToString(BigPow(10, 16))
4646
szabo := CurrencyToString(BigPow(10, 13))

0 commit comments

Comments
 (0)