Merge pull request #1600 from ethereum/fix-tests-windows

Fix tests on windows
pull/1610/head
Jeffrey Wilcke 9 years ago
commit 698e98d981
  1. 2
      .gitattributes
  2. 9
      cmd/utils/customflags.go
  3. 5
      cmd/utils/customflags_test.go
  4. 2
      cmd/utils/flags.go
  5. 5
      common/compiler/solidity_test.go
  6. 1
      common/docserver/docserver.go
  7. 19
      common/docserver/docserver_test.go
  8. 11
      common/path.go
  9. 52
      common/path_test.go
  10. 2
      common/size_test.go
  11. 30
      jsre/jsre_test.go
  12. 4
      p2p/discover/table.go
  13. 8
      p2p/discover/table_test.go
  14. 5
      p2p/nat/natupnp_test.go

2
.gitattributes vendored

@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto

@ -21,7 +21,7 @@ import (
"fmt" "fmt"
"os" "os"
"os/user" "os/user"
"path/filepath" "path"
"strings" "strings"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
@ -138,11 +138,8 @@ func (self *DirectoryFlag) Set(value string) {
func expandPath(p string) string { func expandPath(p string) string {
if strings.HasPrefix(p, "~/") || strings.HasPrefix(p, "~\\") { if strings.HasPrefix(p, "~/") || strings.HasPrefix(p, "~\\") {
if user, err := user.Current(); err == nil { if user, err := user.Current(); err == nil {
if err == nil { p = user.HomeDir + p[1:]
p = strings.Replace(p, "~", user.HomeDir, 1)
}
} }
} }
return path.Clean(os.ExpandEnv(p))
return filepath.Clean(os.ExpandEnv(p))
} }

@ -23,18 +23,15 @@ import (
) )
func TestPathExpansion(t *testing.T) { func TestPathExpansion(t *testing.T) {
user, _ := user.Current() user, _ := user.Current()
tests := map[string]string{ tests := map[string]string{
"/home/someuser/tmp": "/home/someuser/tmp", "/home/someuser/tmp": "/home/someuser/tmp",
"~/tmp": user.HomeDir + "/tmp", "~/tmp": user.HomeDir + "/tmp",
"~thisOtherUser/b/": "~thisOtherUser/b",
"$DDDXXX/a/b": "/tmp/a/b", "$DDDXXX/a/b": "/tmp/a/b",
"/a/b/": "/a/b", "/a/b/": "/a/b",
} }
os.Setenv("DDDXXX", "/tmp") os.Setenv("DDDXXX", "/tmp")
for test, expected := range tests { for test, expected := range tests {
got := expandPath(test) got := expandPath(test)
if got != expected { if got != expected {

@ -478,7 +478,7 @@ func MakeAccountManager(ctx *cli.Context) *accounts.Manager {
} }
func IpcSocketPath(ctx *cli.Context) (ipcpath string) { func IpcSocketPath(ctx *cli.Context) (ipcpath string) {
if common.IsWindows() { if runtime.GOOS == "windows" {
ipcpath = common.DefaultIpcPath() ipcpath = common.DefaultIpcPath()
if ctx.GlobalIsSet(IPCPathFlag.Name) { if ctx.GlobalIsSet(IPCPathFlag.Name) {
ipcpath = ctx.GlobalString(IPCPathFlag.Name) ipcpath = ctx.GlobalString(IPCPathFlag.Name)

@ -20,6 +20,7 @@ import (
"encoding/json" "encoding/json"
"io/ioutil" "io/ioutil"
"os" "os"
"path"
"testing" "testing"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
@ -94,7 +95,7 @@ func TestSaveInfo(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("%v", err) t.Errorf("%v", err)
} }
filename := "/tmp/solctest.info.json" filename := path.Join(os.TempDir(), "solctest.info.json")
os.Remove(filename) os.Remove(filename)
cinfohash, err := SaveInfo(&cinfo, filename) cinfohash, err := SaveInfo(&cinfo, filename)
if err != nil { if err != nil {
@ -110,4 +111,4 @@ func TestSaveInfo(t *testing.T) {
if cinfohash != infohash { if cinfohash != infohash {
t.Errorf("content hash for info is incorrect. expected %v, got %v", infohash.Hex(), cinfohash.Hex()) t.Errorf("content hash for info is incorrect. expected %v, got %v", infohash.Hex(), cinfohash.Hex())
} }
} }

@ -38,7 +38,6 @@ func New(docRoot string) (self *DocServer) {
DocRoot: docRoot, DocRoot: docRoot,
schemes: []string{"file"}, schemes: []string{"file"},
} }
self.DocRoot = "/tmp/"
self.RegisterProtocol("file", http.NewFileTransport(http.Dir(self.DocRoot))) self.RegisterProtocol("file", http.NewFileTransport(http.Dir(self.DocRoot)))
return return
} }

@ -20,6 +20,7 @@ import (
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"os" "os"
"path"
"testing" "testing"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
@ -27,12 +28,18 @@ import (
) )
func TestGetAuthContent(t *testing.T) { func TestGetAuthContent(t *testing.T) {
text := "test" dir, err := ioutil.TempDir("", "docserver-test")
hash := common.Hash{} if err != nil {
copy(hash[:], crypto.Sha3([]byte(text))) t.Fatal("cannot create temporary directory:", err)
ioutil.WriteFile("/tmp/test.content", []byte(text), os.ModePerm) }
defer os.RemoveAll(dir)
ds := New(dir)
ds := New("/tmp/") text := "test"
hash := crypto.Sha3Hash([]byte(text))
if err := ioutil.WriteFile(path.Join(dir, "test.content"), []byte(text), os.ModePerm); err != nil {
t.Fatal("could not write test file", err)
}
content, err := ds.GetAuthContent("file:///test.content", hash) content, err := ds.GetAuthContent("file:///test.content", hash)
if err != nil { if err != nil {
t.Errorf("no error expected, got %v", err) t.Errorf("no error expected, got %v", err)
@ -67,4 +74,4 @@ func TestRegisterScheme(t *testing.T) {
if !ds.HasScheme("scheme") { if !ds.HasScheme("scheme") {
t.Errorf("expected scheme to be registered") t.Errorf("expected scheme to be registered")
} }
} }

@ -116,14 +116,3 @@ func DefaultIpcPath() string {
} }
return filepath.Join(DefaultDataDir(), "geth.ipc") return filepath.Join(DefaultDataDir(), "geth.ipc")
} }
func IsWindows() bool {
return runtime.GOOS == "windows"
}
func WindonizePath(path string) string {
if string(path[0]) == "/" && IsWindows() {
path = path[1:]
}
return path
}

@ -1,52 +0,0 @@
// Copyright 2014 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package common
import (
"os"
// "testing"
checker "gopkg.in/check.v1"
)
type CommonSuite struct{}
var _ = checker.Suite(&CommonSuite{})
func (s *CommonSuite) TestOS(c *checker.C) {
expwin := (os.PathSeparator == '\\' && os.PathListSeparator == ';')
res := IsWindows()
if !expwin {
c.Assert(res, checker.Equals, expwin, checker.Commentf("IsWindows is", res, "but path is", os.PathSeparator))
} else {
c.Assert(res, checker.Not(checker.Equals), expwin, checker.Commentf("IsWindows is", res, "but path is", os.PathSeparator))
}
}
func (s *CommonSuite) TestWindonziePath(c *checker.C) {
iswindowspath := os.PathSeparator == '\\'
path := "/opt/eth/test/file.ext"
res := WindonizePath(path)
ressep := string(res[0])
if !iswindowspath {
c.Assert(ressep, checker.Equals, "/")
} else {
c.Assert(ressep, checker.Not(checker.Equals), "/")
}
}

@ -40,7 +40,7 @@ func (s *SizeSuite) TestStorageSizeString(c *checker.C) {
c.Assert(StorageSize(data3).String(), checker.Equals, exp3) c.Assert(StorageSize(data3).String(), checker.Equals, exp3)
} }
func (s *CommonSuite) TestCommon(c *checker.C) { func (s *SizeSuite) TestCommon(c *checker.C) {
ether := CurrencyToString(BigPow(10, 19)) ether := CurrencyToString(BigPow(10, 19))
finney := CurrencyToString(BigPow(10, 16)) finney := CurrencyToString(BigPow(10, 16))
szabo := CurrencyToString(BigPow(10, 13)) szabo := CurrencyToString(BigPow(10, 13))

@ -19,6 +19,7 @@ package jsre
import ( import (
"io/ioutil" "io/ioutil"
"os" "os"
"path"
"testing" "testing"
"time" "time"
@ -40,10 +41,23 @@ func (no *testNativeObjectBinding) TestMethod(call otto.FunctionCall) otto.Value
return v return v
} }
func newWithTestJS(t *testing.T, testjs string) (*JSRE, string) {
dir, err := ioutil.TempDir("", "jsre-test")
if err != nil {
t.Fatal("cannot create temporary directory:", err)
}
if testjs != "" {
if err := ioutil.WriteFile(path.Join(dir, "test.js"), []byte(testjs), os.ModePerm); err != nil {
t.Fatal("cannot create test.js:", err)
}
}
return New(dir), dir
}
func TestExec(t *testing.T) { func TestExec(t *testing.T) {
jsre := New("/tmp") jsre, dir := newWithTestJS(t, `msg = "testMsg"`)
defer os.RemoveAll(dir)
ioutil.WriteFile("/tmp/test.js", []byte(`msg = "testMsg"`), os.ModePerm)
err := jsre.Exec("test.js") err := jsre.Exec("test.js")
if err != nil { if err != nil {
t.Errorf("expected no error, got %v", err) t.Errorf("expected no error, got %v", err)
@ -64,9 +78,9 @@ func TestExec(t *testing.T) {
} }
func TestNatto(t *testing.T) { func TestNatto(t *testing.T) {
jsre := New("/tmp") jsre, dir := newWithTestJS(t, `setTimeout(function(){msg = "testMsg"}, 1);`)
defer os.RemoveAll(dir)
ioutil.WriteFile("/tmp/test.js", []byte(`setTimeout(function(){msg = "testMsg"}, 1);`), os.ModePerm)
err := jsre.Exec("test.js") err := jsre.Exec("test.js")
if err != nil { if err != nil {
t.Errorf("expected no error, got %v", err) t.Errorf("expected no error, got %v", err)
@ -88,7 +102,7 @@ func TestNatto(t *testing.T) {
} }
func TestBind(t *testing.T) { func TestBind(t *testing.T) {
jsre := New("/tmp") jsre := New("")
jsre.Bind("no", &testNativeObjectBinding{}) jsre.Bind("no", &testNativeObjectBinding{})
@ -105,9 +119,9 @@ func TestBind(t *testing.T) {
} }
func TestLoadScript(t *testing.T) { func TestLoadScript(t *testing.T) {
jsre := New("/tmp") jsre, dir := newWithTestJS(t, `msg = "testMsg"`)
defer os.RemoveAll(dir)
ioutil.WriteFile("/tmp/test.js", []byte(`msg = "testMsg"`), os.ModePerm)
_, err := jsre.Run(`loadScript("test.js")`) _, err := jsre.Run(`loadScript("test.js")`)
if err != nil { if err != nil {
t.Errorf("expected no error, got %v", err) t.Errorf("expected no error, got %v", err)
@ -125,4 +139,4 @@ func TestLoadScript(t *testing.T) {
t.Errorf("expected '%v', got '%v'", exp, got) t.Errorf("expected '%v', got '%v'", exp, got)
} }
jsre.Stop(false) jsre.Stop(false)
} }

@ -164,7 +164,9 @@ func randUint(max uint32) uint32 {
// Close terminates the network listener and flushes the node database. // Close terminates the network listener and flushes the node database.
func (tab *Table) Close() { func (tab *Table) Close() {
tab.net.close() if tab.net != nil {
tab.net.close()
}
tab.db.close() tab.db.close()
} }

@ -35,6 +35,7 @@ func TestTable_pingReplace(t *testing.T) {
doit := func(newNodeIsResponding, lastInBucketIsResponding bool) { doit := func(newNodeIsResponding, lastInBucketIsResponding bool) {
transport := newPingRecorder() transport := newPingRecorder()
tab := newTable(transport, NodeID{}, &net.UDPAddr{}, "") tab := newTable(transport, NodeID{}, &net.UDPAddr{}, "")
defer tab.Close()
pingSender := newNode(MustHexID("a502af0f59b2aab7746995408c79e9ca312d2793cc997e44fc55eda62f0150bbb8c59a6f9269ba3a081518b62699ee807c7c19c20125ddfccca872608af9e370"), net.IP{}, 99, 99) pingSender := newNode(MustHexID("a502af0f59b2aab7746995408c79e9ca312d2793cc997e44fc55eda62f0150bbb8c59a6f9269ba3a081518b62699ee807c7c19c20125ddfccca872608af9e370"), net.IP{}, 99, 99)
// fill up the sender's bucket. // fill up the sender's bucket.
@ -158,9 +159,7 @@ func newPingRecorder() *pingRecorder {
func (t *pingRecorder) findnode(toid NodeID, toaddr *net.UDPAddr, target NodeID) ([]*Node, error) { func (t *pingRecorder) findnode(toid NodeID, toaddr *net.UDPAddr, target NodeID) ([]*Node, error) {
panic("findnode called on pingRecorder") panic("findnode called on pingRecorder")
} }
func (t *pingRecorder) close() { func (t *pingRecorder) close() {}
panic("close called on pingRecorder")
}
func (t *pingRecorder) waitping(from NodeID) error { func (t *pingRecorder) waitping(from NodeID) error {
return nil // remote always pings return nil // remote always pings
} }
@ -180,6 +179,7 @@ func TestTable_closest(t *testing.T) {
// for any node table, Target and N // for any node table, Target and N
tab := newTable(nil, test.Self, &net.UDPAddr{}, "") tab := newTable(nil, test.Self, &net.UDPAddr{}, "")
tab.add(test.All) tab.add(test.All)
defer tab.Close()
// check that doClosest(Target, N) returns nodes // check that doClosest(Target, N) returns nodes
result := tab.closest(test.Target, test.N).entries result := tab.closest(test.Target, test.N).entries
@ -237,6 +237,7 @@ func TestTable_ReadRandomNodesGetAll(t *testing.T) {
} }
test := func(buf []*Node) bool { test := func(buf []*Node) bool {
tab := newTable(nil, NodeID{}, &net.UDPAddr{}, "") tab := newTable(nil, NodeID{}, &net.UDPAddr{}, "")
defer tab.Close()
for i := 0; i < len(buf); i++ { for i := 0; i < len(buf); i++ {
ld := cfg.Rand.Intn(len(tab.buckets)) ld := cfg.Rand.Intn(len(tab.buckets))
tab.add([]*Node{nodeAtDistance(tab.self.sha, ld)}) tab.add([]*Node{nodeAtDistance(tab.self.sha, ld)})
@ -279,6 +280,7 @@ func (*closeTest) Generate(rand *rand.Rand, size int) reflect.Value {
func TestTable_Lookup(t *testing.T) { func TestTable_Lookup(t *testing.T) {
self := nodeAtDistance(common.Hash{}, 0) self := nodeAtDistance(common.Hash{}, 0)
tab := newTable(lookupTestnet, self.ID, &net.UDPAddr{}, "") tab := newTable(lookupTestnet, self.ID, &net.UDPAddr{}, "")
defer tab.Close()
// lookup on empty table returns no nodes // lookup on empty table returns no nodes
if results := tab.Lookup(lookupTestnet.target); len(results) > 0 { if results := tab.Lookup(lookupTestnet.target); len(results) > 0 {

@ -21,6 +21,7 @@ import (
"io" "io"
"net" "net"
"net/http" "net/http"
"runtime"
"strings" "strings"
"testing" "testing"
@ -28,6 +29,10 @@ import (
) )
func TestUPNP_DDWRT(t *testing.T) { func TestUPNP_DDWRT(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skipf("disabled to avoid firewall prompt")
}
dev := &fakeIGD{ dev := &fakeIGD{
t: t, t: t,
ssdpResp: "HTTP/1.1 200 OK\r\n" + ssdpResp: "HTTP/1.1 200 OK\r\n" +

Loading…
Cancel
Save