government / lisp_test.go

@ f98307e213f9f3c11b00c8edc3c367c315b9819a | history


package government_test

import (
	"os"
	"path/filepath"
	"testing"

	"government/eval"
	"government/internal/lisptest"
)

// TestLispFiles runs every testdata/*.gov.lisp file straight from source text.
// Step 5.4 switches this to compiling each file to .gov and running the
// result.
func TestLispFiles(t *testing.T) {
	paths, err := filepath.Glob("testdata/*.gov.lisp")
	if err != nil {
		t.Fatal(err)
	}
	if len(paths) == 0 {
		t.Fatal("no testdata/*.gov.lisp files found")
	}
	for _, path := range paths {
		t.Run(filepath.Base(path), func(t *testing.T) {
			src, err := os.ReadFile(path)
			if err != nil {
				t.Fatal(err)
			}
			f, err := lisptest.Parse(path, string(src))
			if err != nil {
				t.Fatal(err)
			}
			lisptest.Run(t, f, eval.NewTopLevel())
		})
	}
}