go-ph7/ph7_test.go

39 lines
701 B
Go

package ph7_test
import (
"testing"
ph7 "git.codemonkeysoftware.net/b/go-ph7"
)
func mustSucceed(t *testing.T, err error) {
if err != nil {
t.Fatal(err.Error())
}
}
func mustSucceedF(t *testing.T, f func() error) {
err := f()
if err != nil {
t.Fatal(err.Error())
}
}
func TestDoStuff(t *testing.T) {
engine, err := ph7.NewEngine()
mustSucceed(t, err)
defer mustSucceedF(t, engine.Close)
vm, err := engine.Compile([]byte("<?php echo 'Hello world!'; ?>"), false)
mustSucceed(t, err)
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)
}
}