From b2697e184c96ea64c63db0192ad51f35a36ec6ee Mon Sep 17 00:00:00 2001 From: Brandon Dyck Date: Sat, 26 Nov 2022 16:30:16 -0700 Subject: [PATCH] Wrapped ph_vm_reset --- ph7.go | 5 +++++ ph7_test.go | 12 ++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/ph7.go b/ph7.go index efea127..2239e9d 100644 --- a/ph7.go +++ b/ph7.go @@ -160,9 +160,14 @@ func (vm *VM) ExtractOutput() (string, error) { } func (vm *VM) Exec() error { + // TODO return exit status return newError(C.ph7_vm_exec(vm.ptr, (*C.int)(nil))) } +func (vm *VM) Reset() error { + return newError(C.ph7_vm_reset(vm.ptr)) +} + func (vm *VM) Close() error { pointer.Unref(vm.pointerKey) return newError(C.ph7_vm_release(vm.ptr)) diff --git a/ph7_test.go b/ph7_test.go index a180d88..079ba8f 100644 --- a/ph7_test.go +++ b/ph7_test.go @@ -30,7 +30,7 @@ func mustSucceedF(t *testing.T, f func() error) { } } -func TestHelloWorld(t *testing.T) { +func TestCore(t *testing.T) { engine, err := ph7.NewEngine() mustSucceed(t, err) defer mustSucceedF(t, engine.Close) @@ -40,12 +40,20 @@ func TestHelloWorld(t *testing.T) { defer mustSucceedF(t, vm.Close) mustSucceed(t, vm.Exec()) - output, err := vm.ExtractOutput() mustSucceed(t, err) if output != "Hello world!" { t.Fatalf("unexpected output: %s", output) } + + mustSucceed(t, vm.Reset()) + + mustSucceed(t, vm.Exec()) + output, err = vm.ExtractOutput() + mustSucceed(t, err) + if output != "Hello world!" { + t.Fatalf("unexpected output: %s", output) + } } func TestCompileError(t *testing.T) {