diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-08-07 03:39:29 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-08-07 03:39:29 +0800 |
commit | 698e98d9814605bfea98ba3ad2fe7fda073cb2b1 (patch) | |
tree | 729aa720f3b18b9eb901111d1d58c355bc9b744c /jsre/jsre_test.go | |
parent | a3b8169938953a10ab57282853768c72bebaf0b4 (diff) | |
parent | 803096ca0f262be7d03081482777c3e293f5f7ac (diff) | |
download | dexon-698e98d9814605bfea98ba3ad2fe7fda073cb2b1.tar dexon-698e98d9814605bfea98ba3ad2fe7fda073cb2b1.tar.gz dexon-698e98d9814605bfea98ba3ad2fe7fda073cb2b1.tar.bz2 dexon-698e98d9814605bfea98ba3ad2fe7fda073cb2b1.tar.lz dexon-698e98d9814605bfea98ba3ad2fe7fda073cb2b1.tar.xz dexon-698e98d9814605bfea98ba3ad2fe7fda073cb2b1.tar.zst dexon-698e98d9814605bfea98ba3ad2fe7fda073cb2b1.zip |
Merge pull request #1600 from ethereum/fix-tests-windows
Fix tests on windows
Diffstat (limited to 'jsre/jsre_test.go')
-rw-r--r-- | jsre/jsre_test.go | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/jsre/jsre_test.go b/jsre/jsre_test.go index ad210932a..93dc7d1f9 100644 --- a/jsre/jsre_test.go +++ b/jsre/jsre_test.go @@ -19,6 +19,7 @@ package jsre import ( "io/ioutil" "os" + "path" "testing" "time" @@ -40,10 +41,23 @@ func (no *testNativeObjectBinding) TestMethod(call otto.FunctionCall) otto.Value 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) { - 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") if err != nil { t.Errorf("expected no error, got %v", err) @@ -64,9 +78,9 @@ func TestExec(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") if err != nil { t.Errorf("expected no error, got %v", err) @@ -88,7 +102,7 @@ func TestNatto(t *testing.T) { } func TestBind(t *testing.T) { - jsre := New("/tmp") + jsre := New("") jsre.Bind("no", &testNativeObjectBinding{}) @@ -105,9 +119,9 @@ func TestBind(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")`) if err != nil { 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) } jsre.Stop(false) -} +}
\ No newline at end of file |