Commit 28cdff42
28cdff429cc0Merged
Sam Ruby <[email protected]> · 5 months ago · 28 files · +27 added · ~1 modified
Description
Add golden tests for the RBS extractor
PR #1262 noted there were no tests for RBS support. spinel_rbs_extract is a pure, deterministic text transform (.rbs in -> seed lines on stdout) and a compiled C binary, so it golden-tests cleanly with no Ruby at test time. It is also the layer where RBS regressions are actually visible: seeds are advisory, so most extractor bugs produce identical program output and slip past the compile-and-run test/.rb suite (this branch's union->poly fix being a case in point).
test/rbs/.rbs + .seed.expected pairs cover the documented subset: scalar vocabulary, nominal types, Array[T]/Hash[K,V] tag selection, nullable, heterogeneous-union -> poly, member kinds (meth/cmeth/self?./attr_*/@ivar), unqualified parent-scope resolution, first-overload-wins, and the signature/type shapes that drop a method.
make rbs-test diffs live output against the goldens and is a
prerequisite of make test; it skips gracefully when vendor/rbs has
not been fetched. make regen-rbs-expected regenerates the goldens.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 28cdff429cc0
- Parent
- 9dd34a49fe0a
MakefilemodifiedView file
COMPILER_HELPERS_STAMP := build/stamps/compiler_helpers.rb.stampPARSE_STAMP := build/stamps/spinel_parse.c.stamp.PHONY: all parse bootstrap codegen rbs_extract test retest fast-test clean-test-results regen-expected bench optcarrot clean install uninstall deps FORCE.PHONY: all parse bootstrap codegen rbs_extract rbs-test regen-rbs-expected test retest fast-test clean-test-results regen-expected bench optcarrot clean install uninstall deps FORCE# `make all` includes spinel_rbs_extract when vendor/rbs has been# fetched (via `make deps`). Without vendor/rbs the extractor isTEST_TARGETS := $(patsubst test/%.rb,build/test-results/%.ok,$(TESTS))# `make test` is incremental via mtime tracking on .ok files;# `make retest` wipes them for a forced rerun.test: $(TEST_TARGETS)# `make retest` wipes them for a forced rerun. The rbs-test prereq# golden-checks the RBS extractor (cheap, runs every invocation).test: rbs-test $(TEST_TARGETS) @if [ -z "$(TIMEOUT_BIN)" ]; then echo "Note: no 'timeout' command found; running without time limits."; fi @if [ -t 1 ]; then printf '\n'; fi @pass=$$(grep -l '^PASS' build/test-results/*.ok 2>/dev/null | wc -l); \fast-test: clean-test-results @$(MAKE) --no-print-directory test OPT=-O0 LTO=0# ---- RBS extractor golden tests ----# spinel_rbs_extract is a pure text transform (*.rbs -> seed lines on# stdout), so it golden-tests cleanly without Ruby at test time. Each# test/rbs/<name>.rbs has a committed test/rbs/<name>.seed.expected;# `rbs-test` diffs live output against it. Regenerate after intentional# extractor changes with `make regen-rbs-expected` and commit the diff.# Skips (rather than fails) when vendor/rbs hasn't been fetched, so a# `make deps`-less checkout can still run the rest of `make test`.RBS_TEST_SRCS := $(sort $(wildcard test/rbs/*.rbs))ifeq ($(wildcard $(RBS_INC)/rbs/parser.h),)rbs-test: @echo "rbs-test: skipped (vendor/rbs not fetched; run 'make deps')"regen-rbs-expected: @echo "regen-rbs-expected: skipped (vendor/rbs not fetched; run 'make deps')"elserbs-test: spinel_rbs_extract$(EXE) @fail=0; n=0; \ for f in $(RBS_TEST_SRCS); do \ n=$$((n+1)); \ exp="$${f%.rbs}.seed.expected"; \ if [ ! -f "$$exp" ]; then echo "rbs-test: MISSING golden $$exp"; fail=1; continue; fi; \ d=$$(./spinel_rbs_extract$(EXE) "$$f" 2>/dev/null | diff -u "$$exp" - 2>&1); \ if [ -z "$$d" ]; then \ if [ -t 1 ]; then printf .; fi; \ else \ echo; echo "rbs-test FAIL: $$f"; echo "$$d"; fail=1; \ fi; \ done; \ if [ -t 1 ]; then printf '\n'; fi; \ if [ $$fail -ne 0 ]; then echo "RBS extractor tests: FAIL"; exit 1; fi; \ echo "RBS extractor tests: $$n pass"regen-rbs-expected: spinel_rbs_extract$(EXE) @for f in $(RBS_TEST_SRCS); do \ ./spinel_rbs_extract$(EXE) "$$f" > "$${f%.rbs}.seed.expected"; \ echo "regen: $${f%.rbs}.seed.expected"; \ doneendif# The .ok target is the test's stamp; mtime tracking gives per-test# caching for free. Order-only spinel_parse$(EXE) / spinel_analyze$(EXE)# / spinel_codegen$(EXE) stop a bootstrap relink from invalidating every test.test/rbs/README.mdaddedView file
Loading diff…
test/rbs/arrays.rbsaddedView file
Loading diff…
test/rbs/arrays.seed.expectedaddedView file
Loading diff…
test/rbs/dropped_members.rbsaddedView file
Loading diff…
test/rbs/dropped_members.seed.expectedaddedView file
Loading diff…
test/rbs/dropped_sigs.rbsaddedView file
Loading diff…
test/rbs/dropped_sigs.seed.expectedaddedView file
Loading diff…
test/rbs/dropped_types.rbsaddedView file
Loading diff…
test/rbs/dropped_types.seed.expectedaddedView file
Loading diff…
test/rbs/hashes.rbsaddedView file
Loading diff…
test/rbs/hashes.seed.expectedaddedView file
Loading diff…
test/rbs/ivars.rbsaddedView file
Loading diff…
test/rbs/ivars.seed.expectedaddedView file
Loading diff…
test/rbs/members.rbsaddedView file
Loading diff…
test/rbs/members.seed.expectedaddedView file
Loading diff…
test/rbs/nominal.rbsaddedView file
Loading diff…
test/rbs/nominal.seed.expectedaddedView file
Loading diff…
test/rbs/nullable.rbsaddedView file
Loading diff…
test/rbs/nullable.seed.expectedaddedView file
Loading diff…
test/rbs/overloads.rbsaddedView file
Loading diff…
test/rbs/overloads.seed.expectedaddedView file
Loading diff…
test/rbs/scalars.rbsaddedView file
Loading diff…
test/rbs/scalars.seed.expectedaddedView file
Loading diff…
test/rbs/union_poly.rbsaddedView file
Loading diff…
test/rbs/union_poly.seed.expectedaddedView file
Loading diff…
test/rbs/unqualified.rbsaddedView file
Loading diff…
test/rbs/unqualified.seed.expectedaddedView file
Loading diff…