government

commit 69e3ad85cc0f4df2aca759df28acafb505578821

tree

parent:
2dbe47969d09d4856796bbf662b4e11c74a7f4fe

nmyk <nick@nmyk.io>

2026-11-14T22:53:58-05:00

make lisptest data internal

diff --git a/DESIGN.md b/DESIGN.md
index 35d36c60e6a7eed317ae709558a9bdc3f62fe1d2..55c812aa686443a94be0f19a58d54a90af149e50 100644
--- a/DESIGN.md
+++ b/DESIGN.md
@@ -378,7 +378,7 @@
 After a top-level form, `;=> value` asserts its printed value, and `;=! text` asserts an error whose message contains `text`. In test mode, an error ends only that form, so one file can hold many error cases.
 
 ```lisp
-; testdata/scoping.gov.lisp  (lexical, not dynamic)
+; internal/lisptest/testdata/scoping.gov.lisp  (lexical, not dynamic)
 (define x 1)
 (define f (lambda () x))
 (define g (lambda (x) (f)))
@@ -387,14 +387,14 @@ (define x 2)          ;=! immutable
 ((lambda (x) (define y (+ x 1)) (define z (+ y 1)) z) 1)   ;=> 3
 ((lambda () (define a (lambda () (b))) (define b (lambda () 1)) (a)))   ;=! unbound
 
-; testdata/truthiness.gov.lisp
+; internal/lisptest/testdata/truthiness.gov.lisp
 (and F (car '()))     ;=> F
 (or F 7)              ;=> 7
 (if 0 'true 'false)   ;=> true
 (if F 1)              ;=> ()
 (not 0)               ;=> F
 
-; testdata/strings.gov.lisp
+; internal/lisptest/testdata/strings.gov.lisp
 (strlen "héllo")        ;=> 5
 (strcat "gov" "ern" "ment")   ;=> "government"
 (str? "")             ;=> T
@@ -405,9 +405,9 @@ ### Test categories
 
 | Category | Form | Checks |
 | --- | --- | --- |
-| Language | `testdata/*.gov.lisp` | All semantics: arithmetic, comparisons, truthiness, `if`, `quote`, lists, `define`, closures, scoping, recursion, higher-order functions, strings and Unicode |
+| Language | `internal/lisptest/testdata/*.gov.lisp`, listed by `lisptest.Files` | All semantics: arithmetic, comparisons, truthiness, `if`, `quote`, lists, `define`, closures, scoping, recursion, higher-order functions, strings and Unicode |
 | Shape stress | `stress_test.go`, generated | 200-deep nesting (201 certs), 1,000-argument calls, 1,000-element `quote`d lists, 1,000 top-level forms, all through the whole pipeline; `--max-nodes` exactly at and one below a program's graph size; a small file asking for a million-node graph, refused quickly. Shared subexpressions are in `lisp2gov/share_test.go` |
-| Round trip | Go test over every `testdata` file | `gov2lisp(lisp2gov(src))` equals the normalized source, comments included |
+| Round trip | Go test over every language test program | `gov2lisp(lisp2gov(src))` equals the normalized source, comments included |
 | Ratification | Go table test that mutates a valid chain | Flipped signature byte, reordered certs, dropped mapping, orphaned policy, mapping in cert n, `anyPolicy` missing from a cert 2..n or asserted in cert 1, a list node with no elements, unknown critical extension; each expects a specific error |
 | Civic | Go table test | Runs before, inside and after a `--not-before`/`--not-after` window; repeal of each depth; scheduled repeal; stale CRL; CRL signed by the wrong key; `--anchor` pin across a re-ratified version; notes over 200 characters; default-key warning |
 | Golden | `lisp2gov/testdata/golden.gov` and `golden.crl`, from `golden.gov.lisp` | Byte equality with every option fixed (seed, author, dates), so any change to the encoding fails, reported as the block and DER byte where it starts; the program uses every literal kind, a split note, a dotted pair and a shared node, and must also run. `go test ./lisp2gov -update` accepts a deliberate change |
diff --git a/README.md b/README.md
index 90a565792ff8d52c9f0d1f745608bff875f25acf..a128894b2cb67ecde470ff4a97add04905537695 100644
--- a/README.md
+++ b/README.md
@@ -329,9 +329,9 @@ | `go test -short ./...`       | Runs every test except the largest shared-subexpression one.                       |
 | `go test ./lisp2gov -update` | Rewrites the golden files. Use it only for a deliberate change to the file format. |
 | `make oracle`                | Builds an OpenSSL without its policy tree limit, and checks GOVERNMENT against it. |
 
-Each program in `testdata/` is a GovLisp file: a `;=>` comment gives a form's
-expected value, and `;=!` its expected error. The tests compile each file and
-run it through the whole interpreter.
+Each program in `internal/lisptest/testdata/` is a GovLisp file: a `;=>` comment
+gives a form's expected value, and `;=!` its expected error. The tests compile
+each file and run it through the whole interpreter.
 
 The OpenSSL tests use the `openssl` command. On macOS that is often LibreSSL,
 and the tests skip. Set `GOVERNMENT_OPENSSL` to the path of an OpenSSL binary to
diff --git a/ast/share_test.go b/ast/share_test.go
index d133026c71cada2813fd1dc6d3cb07a4ff7dd897..b17133594889e528a325ff1d4efeea4d04bdce64 100644
--- a/ast/share_test.go
+++ b/ast/share_test.go
@@ -7,6 +7,7 @@ 	"reflect"
 	"strings"
 	"testing"
 
+	"government/internal/lisptest"
 	"government/sexpr"
 )
 
@@ -168,7 +169,7 @@
 // TestShareTestdata runs Share over every test program, which between them
 // repeat plenty of subexpressions.
 func TestShareTestdata(t *testing.T) {
-	paths, _ := filepath.Glob("../testdata/*.gov.lisp")
+	paths, _ := lisptest.Files()
 	examples, _ := filepath.Glob("../examples/*.gov.lisp")
 	for _, path := range append(paths, examples...) {
 		src, err := os.ReadFile(path)
diff --git a/ast/tree_test.go b/ast/tree_test.go
index 23205569790d6bf80ffe1aa314121d9b4cd91a0f..35764e9e35e7caa64e72f05ce5f5bd7c0d015c91 100644
--- a/ast/tree_test.go
+++ b/ast/tree_test.go
@@ -8,6 +8,7 @@ 	"strconv"
 	"strings"
 	"testing"
 
+	"government/internal/lisptest"
 	"government/sexpr"
 )
 
@@ -103,7 +104,7 @@ 	}
 }
 
 func TestRoundTripTestdata(t *testing.T) {
-	files, err := filepath.Glob("../testdata/*.gov.lisp")
+	files, err := lisptest.Files()
 	if err != nil || len(files) == 0 {
 		t.Fatalf("no testdata: %v", err)
 	}
@@ -264,7 +265,7 @@ // values it reads as give the same tree, notes aside. A difference would
 // mean the reader splits some list differently from DatumOf.
 func TestBuildMatchesToTree(t *testing.T) {
 	sources := []string{`'(1 . (2 . (3 . ())))`, `'(a . 'b)`, `'(a b . c)`, `(f () T F "s" 1.5 -2)`, `'''x`}
-	files, _ := filepath.Glob("../testdata/*.gov.lisp")
+	files, _ := lisptest.Files()
 	examples, _ := filepath.Glob("../examples/*.gov.lisp")
 	for _, f := range append(files, examples...) {
 		src, err := os.ReadFile(f)
diff --git a/ast/unlayer_test.go b/ast/unlayer_test.go
index 099e9045bb5754bb04421330691f0c6fe8b410df..2bca28414fc281abfe903fe80d046d87111bbaeb 100644
--- a/ast/unlayer_test.go
+++ b/ast/unlayer_test.go
@@ -2,10 +2,11 @@ package ast
 
 import (
 	"os"
-	"path/filepath"
 	"reflect"
 	"strings"
 	"testing"
+
+	"government/internal/lisptest"
 )
 
 // withCopies adds what policy processing adds on top of Layer's output: a
@@ -67,7 +68,7 @@ 	}
 }
 
 func TestUnlayerRoundTripTestdata(t *testing.T) {
-	files, err := filepath.Glob("../testdata/*.gov.lisp")
+	files, err := lisptest.Files()
 	if err != nil || len(files) == 0 {
 		t.Fatalf("no testdata: %v", err)
 	}
diff --git a/gov2lisp/gov2lisp_test.go b/gov2lisp/gov2lisp_test.go
index cc93670eb57f2b03461b2658d8aae078eb7bd824..a738cc3d7afddc588cb3a1be481d6bf5e71b9a23 100644
--- a/gov2lisp/gov2lisp_test.go
+++ b/gov2lisp/gov2lisp_test.go
@@ -9,6 +9,7 @@ 	"testing"
 	"time"
 
 	"government/ast"
+	"government/internal/lisptest"
 	"government/lisp2gov"
 	"government/program"
 	"government/sexpr"
@@ -33,7 +34,7 @@ // and compiling it again must give the same text: a bug anywhere between
 // reading the source and printing the decoded program shows up here, in
 // either direction.
 func TestRoundTrip(t *testing.T) {
-	files, _ := filepath.Glob("../testdata/*.gov.lisp")
+	files, _ := lisptest.Files()
 	examples, _ := filepath.Glob("../examples/*.gov.lisp")
 	files = append(files, examples...)
 	if len(files) == 0 {
diff --git a/internal/lisptest/lisptest.go b/internal/lisptest/lisptest.go
index dfdc12cb554daaabc92eb8f2a1ef54c62bd589a9..377c6b8ff81fb920782685624c4845722b5bc257 100644
--- a/internal/lisptest/lisptest.go
+++ b/internal/lisptest/lisptest.go
@@ -15,6 +15,8 @@ package lisptest
 
 import (
 	"fmt"
+	"path/filepath"
+	"runtime"
 	"strings"
 
 	"government/eval"
@@ -166,3 +168,20 @@ 		g.Cases[i] = c
 	}
 	return &g, nil
 }
+
+// Files returns the paths of the language test programs, the
+// testdata/*.gov.lisp files beside this package, so every package's tests
+// can run them without knowing where they live. It finds them through
+// this source file's path, which is only right when tests run from
+// source, as go test does.
+func Files() ([]string, error) {
+	_, self, _, ok := runtime.Caller(0)
+	if !ok {
+		return nil, fmt.Errorf("lisptest: cannot find its own source")
+	}
+	paths, err := filepath.Glob(filepath.Join(filepath.Dir(self), "testdata", "*.gov.lisp"))
+	if err == nil && len(paths) == 0 {
+		err = fmt.Errorf("lisptest: no test programs in %s", filepath.Join(filepath.Dir(self), "testdata"))
+	}
+	return paths, err
+}
diff --git a/lisp2gov/compile_test.go b/lisp2gov/compile_test.go
index 878eb7fd8233c4b9cd54800bfb61c7ce707e7b84..4d6c97bbee0493e1aef0794d46388e5007349567 100644
--- a/lisp2gov/compile_test.go
+++ b/lisp2gov/compile_test.go
@@ -8,11 +8,12 @@ 	"os"
 	"path/filepath"
 	"testing"
 
+	"government/internal/lisptest"
 	"government/sexpr"
 )
 
 func TestCompileTestdata(t *testing.T) {
-	files, err := filepath.Glob("../testdata/*.gov.lisp")
+	files, err := lisptest.Files()
 	if err != nil || len(files) == 0 {
 		t.Fatalf("no testdata: %v", err)
 	}
diff --git a/lisp2gov/openssl_test.go b/lisp2gov/openssl_test.go
index 03e8c2022c503d6491714f9b882871d9c2d063f9..0fec4e8bc99653635a00fd02eaf8a46ba06e2de9 100644
--- a/lisp2gov/openssl_test.go
+++ b/lisp2gov/openssl_test.go
@@ -16,6 +16,7 @@ 	"strings"
 	"testing"
 	"time"
 
+	"government/internal/lisptest"
 	"government/program"
 )
 
@@ -130,7 +131,7 @@ // and not, passes OpenSSL's path validation, and OpenSSL finds the same
 // top-level policies the first cert lists.
 func TestOpenSSLAcceptsEveryProgram(t *testing.T) {
 	needOpenSSL(t)
-	paths, _ := filepath.Glob("../testdata/*.gov.lisp")
+	paths, _ := lisptest.Files()
 	examples, _ := filepath.Glob("../examples/*.gov.lisp")
 	paths = append(append(paths, examples...), "testdata/golden.gov.lisp")
 	at := time.Date(2028, 1, 1, 0, 0, 0, 0, time.UTC)
diff --git a/lisp_test.go b/lisp_test.go
index 8eabeb63911896af7795827c13516be6731b7d30..75aea6d3967b03ea835cb3787075e8c76667b740 100644
--- a/lisp_test.go
+++ b/lisp_test.go
@@ -13,17 +13,14 @@ 	"government/lisp2gov"
 	"government/program"
 )
 
-// TestLispFiles compiles every testdata/*.gov.lisp file to a .gov program,
+// TestLispFiles compiles every language test program (lisptest.Files) to a .gov program,
 // with and without shared subexpressions, runs that program through the
 // whole pipeline (ratify, policy graph, decode, evaluate), and checks each
 // form against the expectation written in the source.
 func TestLispFiles(t *testing.T) {
-	paths, err := filepath.Glob("testdata/*.gov.lisp")
+	paths, err := lisptest.Files()
 	if err != nil {
 		t.Fatal(err)
-	}
-	if len(paths) == 0 {
-		t.Fatal("no testdata/*.gov.lisp files found")
 	}
 	for _, path := range paths {
 		for _, noShare := range []bool{false, true} {
diff --git a/policy/strict_test.go b/policy/strict_test.go
index a760c97de1ad02d1f4bd065d8bf3d9c268582921..4f02bf12feaae901c40e154b516a75bbc6be8dd4 100644
--- a/policy/strict_test.go
+++ b/policy/strict_test.go
@@ -10,6 +10,7 @@ 	"strings"
 	"testing"
 
 	"government/ast"
+	"government/internal/lisptest"
 	"government/lisp2gov"
 	"government/ratify"
 	"government/sexpr"
@@ -61,7 +62,7 @@ 	return forms, err
 }
 
 func TestTestdataDecodesToItsSource(t *testing.T) {
-	files, _ := filepath.Glob("../testdata/*.gov.lisp")
+	files, _ := lisptest.Files()
 	examples, _ := filepath.Glob("../examples/*.gov.lisp")
 	files = append(files, examples...)
 	for _, file := range files {
diff --git a/ratify/load_test.go b/ratify/load_test.go
index cf17380b31eb11f41394ad34cb88541243d9efcb..765350b1e0be0d4a7cd8beba34b92d9a1e6110a9 100644
--- a/ratify/load_test.go
+++ b/ratify/load_test.go
@@ -12,6 +12,7 @@ 	"path/filepath"
 	"strings"
 	"testing"
 
+	"government/internal/lisptest"
 	"government/lisp2gov"
 )
 
@@ -34,7 +35,7 @@ 	}
 }
 
 func TestLoadCompiledPrograms(t *testing.T) {
-	files, _ := filepath.Glob("../testdata/*.gov.lisp")
+	files, _ := lisptest.Files()
 	examples, _ := filepath.Glob("../examples/*.gov.lisp")
 	files = append(files, examples...)
 	for _, file := range files {
diff --git a/testdata/arithmetic.gov.lisp b/internal/lisptest/testdata/arithmetic.gov.lisp
rename from testdata/arithmetic.gov.lisp
rename to internal/lisptest/testdata/arithmetic.gov.lisp
diff --git a/testdata/comparison.gov.lisp b/internal/lisptest/testdata/comparison.gov.lisp
rename from testdata/comparison.gov.lisp
rename to internal/lisptest/testdata/comparison.gov.lisp
diff --git a/testdata/functions.gov.lisp b/internal/lisptest/testdata/functions.gov.lisp
rename from testdata/functions.gov.lisp
rename to internal/lisptest/testdata/functions.gov.lisp
diff --git a/testdata/lists.gov.lisp b/internal/lisptest/testdata/lists.gov.lisp
rename from testdata/lists.gov.lisp
rename to internal/lisptest/testdata/lists.gov.lisp
diff --git a/testdata/quote.gov.lisp b/internal/lisptest/testdata/quote.gov.lisp
rename from testdata/quote.gov.lisp
rename to internal/lisptest/testdata/quote.gov.lisp
diff --git a/testdata/recursion.gov.lisp b/internal/lisptest/testdata/recursion.gov.lisp
rename from testdata/recursion.gov.lisp
rename to internal/lisptest/testdata/recursion.gov.lisp
diff --git a/testdata/scoping.gov.lisp b/internal/lisptest/testdata/scoping.gov.lisp
rename from testdata/scoping.gov.lisp
rename to internal/lisptest/testdata/scoping.gov.lisp
diff --git a/testdata/strings.gov.lisp b/internal/lisptest/testdata/strings.gov.lisp
rename from testdata/strings.gov.lisp
rename to internal/lisptest/testdata/strings.gov.lisp
diff --git a/testdata/truthiness.gov.lisp b/internal/lisptest/testdata/truthiness.gov.lisp
rename from testdata/truthiness.gov.lisp
rename to internal/lisptest/testdata/truthiness.gov.lisp