Wrapped ph_vm_reset

This commit is contained in:
Brandon Dyck 2022-11-26 16:30:16 -07:00
parent 2a880cef4c
commit b2697e184c
2 changed files with 15 additions and 2 deletions

5
ph7.go
View File

@ -160,9 +160,14 @@ func (vm *VM) ExtractOutput() (string, error) {
} }
func (vm *VM) Exec() error { func (vm *VM) Exec() error {
// TODO return exit status
return newError(C.ph7_vm_exec(vm.ptr, (*C.int)(nil))) 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 { func (vm *VM) Close() error {
pointer.Unref(vm.pointerKey) pointer.Unref(vm.pointerKey)
return newError(C.ph7_vm_release(vm.ptr)) return newError(C.ph7_vm_release(vm.ptr))

View File

@ -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() engine, err := ph7.NewEngine()
mustSucceed(t, err) mustSucceed(t, err)
defer mustSucceedF(t, engine.Close) defer mustSucceedF(t, engine.Close)
@ -40,12 +40,20 @@ func TestHelloWorld(t *testing.T) {
defer mustSucceedF(t, vm.Close) defer mustSucceedF(t, vm.Close)
mustSucceed(t, vm.Exec()) mustSucceed(t, vm.Exec())
output, err := vm.ExtractOutput() output, err := vm.ExtractOutput()
mustSucceed(t, err) mustSucceed(t, err)
if output != "Hello world!" { if output != "Hello world!" {
t.Fatalf("unexpected output: %s", output) 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) { func TestCompileError(t *testing.T) {