Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename failIf test helper to fatalIf since it uses t.Fatal #189

Merged
merged 1 commit into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ func TestRegistryFromJSON(t *testing.T) {
global := v8.NewObjectTemplate(iso)
err := global.Set("location", v8.NewFunctionTemplate(iso, func(info *v8.FunctionCallbackInfo) *v8.Value {
v, err := v8.NewValue(iso, "world")
failIf(t, err)
fatalIf(t, err)
return v
}))
failIf(t, err)
fatalIf(t, err)

ctx := v8.NewContext(iso, global)
defer ctx.Close()
Expand All @@ -140,10 +140,10 @@ func TestRegistryFromJSON(t *testing.T) {
},
})
`, "main.js")
failIf(t, err)
fatalIf(t, err)

s, err := v8.JSONStringify(ctx, v)
failIf(t, err)
fatalIf(t, err)

expected := `{"hello":"world"}`
if s != expected {
Expand Down
52 changes: 26 additions & 26 deletions function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ func TestFunctionCall(t *testing.T) {
defer ctx.Close()

_, err := ctx.RunScript("function add(a, b) { return a + b; }", "")
failIf(t, err)
fatalIf(t, err)
addValue, err := ctx.Global().Get("add")
failIf(t, err)
fatalIf(t, err)
iso := ctx.Isolate()

arg1, err := v8.NewValue(iso, int32(1))
failIf(t, err)
fatalIf(t, err)

fn, _ := addValue.AsFunction()
resultValue, err := fn.Call(v8.Undefined(iso), arg1, arg1)
failIf(t, err)
fatalIf(t, err)

if resultValue.Int32() != 2 {
t.Errorf("expected 1 + 1 = 2, got: %v", resultValue.DetailString())
Expand All @@ -49,17 +49,17 @@ func TestFunctionCallToGoFunc(t *testing.T) {
})

err := global.Set("print", printfn, v8.ReadOnly)
failIf(t, err)
fatalIf(t, err)

ctx := v8.NewContext(iso, global)
defer ctx.Close()

val, err := ctx.RunScript(`(a, b) => { print("foo"); }`, "")
failIf(t, err)
fatalIf(t, err)
fn, err := val.AsFunction()
failIf(t, err)
fatalIf(t, err)
resultValue, err := fn.Call(v8.Undefined(iso))
failIf(t, err)
fatalIf(t, err)

if !called {
t.Errorf("expected my function to be called, wasn't")
Expand All @@ -77,15 +77,15 @@ func TestFunctionCallWithObjectReceiver(t *testing.T) {

ctx := v8.NewContext(iso, global)
val, err := ctx.RunScript(`class Obj { constructor(input) { this.input = input } print() { return this.input.toString() } }; new Obj("some val")`, "")
failIf(t, err)
fatalIf(t, err)
obj, err := val.AsObject()
failIf(t, err)
fatalIf(t, err)
fnVal, err := obj.Get("print")
failIf(t, err)
fatalIf(t, err)
fn, err := fnVal.AsFunction()
failIf(t, err)
fatalIf(t, err)
resultValue, err := fn.Call(obj)
failIf(t, err)
fatalIf(t, err)

if !resultValue.IsString() || resultValue.String() != "some val" {
t.Errorf("expected 'some val', got: %v", resultValue.DetailString())
Expand All @@ -101,9 +101,9 @@ func TestFunctionCallError(t *testing.T) {
defer ctx.Close()

_, err := ctx.RunScript("function throws() { throw 'error'; }", "script.js")
failIf(t, err)
fatalIf(t, err)
addValue, err := ctx.Global().Get("throws")
failIf(t, err)
fatalIf(t, err)

fn, _ := addValue.AsFunction()
_, err = fn.Call(v8.Undefined(iso))
Expand All @@ -124,9 +124,9 @@ func TestFunctionSourceMapUrl(t *testing.T) {
defer ctx.Isolate().Dispose()
defer ctx.Close()
_, err := ctx.RunScript("function add(a, b) { return a + b; }; //# sourceMappingURL=main.js.map", "main.js")
failIf(t, err)
fatalIf(t, err)
addValue, err := ctx.Global().Get("add")
failIf(t, err)
fatalIf(t, err)

fn, _ := addValue.AsFunction()

Expand All @@ -136,9 +136,9 @@ func TestFunctionSourceMapUrl(t *testing.T) {
}

_, err = ctx.RunScript("function sub(a, b) { return a - b; };", "")
failIf(t, err)
fatalIf(t, err)
subValue, err := ctx.Global().Get("sub")
failIf(t, err)
fatalIf(t, err)

subFn, _ := subValue.AsFunction()
resultVal = subFn.SourceMapUrl()
Expand All @@ -157,16 +157,16 @@ func TestFunctionNewInstance(t *testing.T) {
iso := ctx.Isolate()

value, err := ctx.Global().Get("Error")
failIf(t, err)
fatalIf(t, err)
fn, err := value.AsFunction()
failIf(t, err)
fatalIf(t, err)
messageObj, err := v8.NewValue(iso, "test message")
failIf(t, err)
fatalIf(t, err)
errObj, err := fn.NewInstance(messageObj)
failIf(t, err)
fatalIf(t, err)

message, err := errObj.Get("message")
failIf(t, err)
fatalIf(t, err)
if !message.IsString() {
t.Error("missing error message")
}
Expand All @@ -185,9 +185,9 @@ func TestFunctionNewInstanceError(t *testing.T) {
defer ctx.Close()

_, err := ctx.RunScript("function throws() { throw 'error'; }", "script.js")
failIf(t, err)
fatalIf(t, err)
throwsValue, err := ctx.Global().Get("throws")
failIf(t, err)
fatalIf(t, err)
fn, _ := throwsValue.AsFunction()

_, err = fn.NewInstance()
Expand Down
2 changes: 1 addition & 1 deletion helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package v8go_test

import "testing"

func failIf(t *testing.T, err error) {
func fatalIf(t *testing.T, err error) {
t.Helper()
if err != nil {
t.Fatal(err)
Expand Down
6 changes: 3 additions & 3 deletions object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestObjectMethodCall(t *testing.T) {
val, _ := ctx.RunScript(`class Obj { constructor(input) { this.input = input, this.prop = "" } print() { return this.input.toString() } }; new Obj("some val")`, "")
obj, _ := val.AsObject()
val, err := obj.MethodCall("print")
failIf(t, err)
fatalIf(t, err)
if val.String() != "some val" {
t.Errorf("unexpected value: %q", val)
}
Expand All @@ -29,11 +29,11 @@ func TestObjectMethodCall(t *testing.T) {
}

val, err = ctx.RunScript(`class Obj2 { print(str) { return str.toString() }; get fails() { throw "error" } }; new Obj2()`, "")
failIf(t, err)
fatalIf(t, err)
obj, _ = val.AsObject()
arg, _ := v8.NewValue(iso, "arg")
val, err = obj.MethodCall("print", arg)
failIf(t, err)
fatalIf(t, err)
if val.String() != "arg" {
t.Errorf("unexpected value: %q", val)
}
Expand Down
6 changes: 3 additions & 3 deletions value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func TestValueConstants(t *testing.T) {
tt := tt

val, err := ctx.RunScript(tt.source, "test.js")
failIf(t, err)
fatalIf(t, err)

if tt.value.SameValue(val) != tt.same {
t.Errorf("SameValue on JS `%s` and V8 value %+v didn't return %v",
Expand Down Expand Up @@ -482,9 +482,9 @@ func TestValueSameValue(t *testing.T) {

objTempl := v8.NewObjectTemplate(iso)
obj1, err := objTempl.NewInstance(ctx)
failIf(t, err)
fatalIf(t, err)
obj2, err := objTempl.NewInstance(ctx)
failIf(t, err)
fatalIf(t, err)

if obj1.Value.SameValue(obj2.Value) != false {
t.Errorf("SameValue on two different values didn't return false")
Expand Down