More tests
Some checks failed
Build / build (push) Failing after 1m26s
Test / build (push) Failing after 11m43s

This commit is contained in:
Chuck Smith
2024-03-18 19:46:54 -04:00
parent c59ce311b0
commit ca4eed10b8
16 changed files with 124 additions and 24 deletions

View File

@@ -316,6 +316,13 @@ func (vm *VM) Run() error {
}
}
if vm.Debug {
log.Printf(
"%-25s [ip=%02d fp=%02d, sp=%02d]",
"", ip, vm.framesIndex-1, vm.sp,
)
}
}
return nil

View File

@@ -8,7 +8,9 @@ import (
"monkey/object"
"monkey/parser"
"os"
"path"
"path/filepath"
"strings"
"testing"
)
@@ -831,6 +833,47 @@ func TestAssignmentStatements(t *testing.T) {
runVmTests(t, tests)
}
func TestIntegration(t *testing.T) {
matches, err := filepath.Glob("../testdata/*.monkey")
if err != nil {
t.Error(err)
}
for _, match := range matches {
basename := path.Base(match)
name := strings.TrimSuffix(basename, filepath.Ext(basename))
t.Run(name, func(t *testing.T) {
b, err := os.ReadFile(match)
if err != nil {
t.Error(err)
}
input := string(b)
program := parse(input)
c := compiler.New()
err = c.Compile(program)
if err != nil {
t.Log(input)
t.Fatalf("compiler error: %s", err)
}
vm := New(c.Bytecode())
err = vm.Run()
if err != nil {
t.Log(input)
t.Fatalf("vm error: %s", err)
}
if vm.sp != 0 {
t.Log(input)
t.Fatal("vm stack pointer non-zero")
}
})
}
}
func TestExamples(t *testing.T) {
matches, err := filepath.Glob("../examples/*.monkey")
if err != nil {
@@ -838,32 +881,36 @@ func TestExamples(t *testing.T) {
}
for _, match := range matches {
b, err := os.ReadFile(match)
if err != nil {
t.Error(err)
}
basename := path.Base(match)
name := strings.TrimSuffix(basename, filepath.Ext(basename))
input := string(b)
program := parse(input)
t.Run(name, func(t *testing.T) {
b, err := os.ReadFile(match)
if err != nil {
t.Error(err)
}
c := compiler.New()
err = c.Compile(program)
if err != nil {
t.Log(input)
t.Fatalf("compiler error: %s", err)
}
input := string(b)
program := parse(input)
vm := New(c.Bytecode())
c := compiler.New()
err = c.Compile(program)
if err != nil {
t.Log(input)
t.Fatalf("compiler error: %s", err)
}
err = vm.Run()
if err != nil {
t.Log(input)
t.Fatalf("vm error: %s", err)
}
vm := New(c.Bytecode())
if vm.sp != 0 {
t.Log(input)
t.Fatal("vm stack pointer non-zero")
}
err = vm.Run()
if err != nil {
t.Log(input)
t.Fatalf("vm error: %s", err)
}
if vm.sp != 0 {
t.Log(input)
t.Fatal("vm stack pointer non-zero")
}
})
}
}