common/compiler, common/docserver, jsre: fix tests on windows

pull/1600/head
Felix Lange 9 years ago
parent eae1191904
commit 3832019964
  1. 5
      common/compiler/solidity_test.go
  2. 1
      common/docserver/docserver.go
  3. 19
      common/docserver/docserver_test.go
  4. 30
      jsre/jsre_test.go

@ -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")
} }
} }

@ -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)
} }
Loading…
Cancel
Save