Commit 573c514c

573c514cf9a4Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

build: prefer miniruby for test/bench reference, fall back to ruby

make test and make bench compared spinel output to system ruby. On boxes with an older system Ruby (e.g. 3.2 vs the test using a Ruby 3.4 feature like it block param) the comparison would fail even though the spinel-emitted binary was correct. matz's box has miniruby (Ruby 4.1.0dev built with +PRISM) on PATH, which models the latest semantics.

Add a REF_RUBY make variable that auto-detects miniruby and falls back to ruby. The harness then runs the reference Ruby per file; if it exits non-zero (the bootstrap miniruby can't load extension libs like stringio), fall back to system ruby for that file. Net effect:

  • it / => and other newer-Ruby tests pass under miniruby.
  • stringio / other extension-library tests still pass under ruby.
  • Environments without miniruby (CI image, fresh checkouts) take the existing direct-ruby path — no behaviour change.
  • Override on the command line via REF_RUBY=ruby make test to force the legacy behaviour.

After: make test reports 218/218 green locally (was 217/218 with numbered_block_params spuriously failing on Ruby 3.2.3).

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
573c514cf9a4
Parent
69d70c813157

MakefilemodifiedView file

@@ -49,6 +49,16 @@
4949 TIMEOUT10 := $(if $(TIMEOUT_BIN),$(TIMEOUT_BIN) 10,)
5050 TIMEOUT60 := $(if $(TIMEOUT_BIN),$(TIMEOUT_BIN) 60,)
5151
52+# Reference Ruby for `make test` / `make bench` output comparison.
53+# Prefer `miniruby` (Ruby's bootstrap interpreter; matz's local copy is
54+# 4.1.0dev with +PRISM, so newer features like `it` block param work)
55+# when available; the test/bench harness falls back to `ruby` per-file
56+# if miniruby exits non-zero — covers tests that `require` extension
57+# libraries (stringio, etc.) which the bootstrap miniruby can't load.
58+# Environments without miniruby use `ruby` directly. Override via
59+# `REF_RUBY=ruby make test` if a specific primary is wanted.
60+REF_RUBY ?= $(shell command -v miniruby >/dev/null 2>&1 && echo miniruby || echo ruby)
61+
5262 # Prism library: prefer vendor/prism (fetched via `make deps`), then
5363 # fall back to the Prism gem if one is installed. Override by setting
5464 # PRISM_DIR=/path/to/prism on the command line.
@@ -166,7 +176,10 @@
166176 ./spinel_codegen$(EXE) /tmp/_sp_t.ast /tmp/_sp_t.c 2>/dev/null && \
167177 $(CC) $(CFLAGS) -Werror $(SEC_FLAGS) -Ilib /tmp/_sp_t.c $(SP_RT_LIB) $(LDFLAGS) -lm $(GC_FLAGS) -o /tmp/_sp_t_bin$(EXE) 2>/dev/null; \
168178 if [ $$? -eq 0 ]; then \
169- expected=$$($(TIMEOUT10) ruby "$$f" 2>/dev/null); \
179+ expected=$$($(TIMEOUT10) $(REF_RUBY) "$$f" 2>/dev/null); \
180+ if [ $$? -ne 0 ] && [ "$(REF_RUBY)" != "ruby" ]; then \
181+ expected=$$($(TIMEOUT10) ruby "$$f" 2>/dev/null); \
182+ fi; \
170183 actual=$$($(TIMEOUT10) /tmp/_sp_t_bin$(EXE) 2>/dev/null); \
171184 if [ "$$expected" = "$$actual" ]; then \
172185 pass=$$((pass+1)); \
@@ -190,8 +203,12 @@
190203 $(TIMEOUT10) ./spinel_codegen$(EXE) /tmp/_sp_b.ast /tmp/_sp_b.c 2>/dev/null && \
191204 $(CC) $(CFLAGS) -Werror $(SEC_FLAGS) -Ilib /tmp/_sp_b.c $(SP_RT_LIB) $(LDFLAGS) -lm $(GC_FLAGS) -o /tmp/_sp_b_bin$(EXE) 2>/dev/null; \
192205 if [ $$? -eq 0 ]; then \
193- expected=$$($(TIMEOUT60) ruby "$$f" 2>/dev/null); \
206+ expected=$$($(TIMEOUT60) $(REF_RUBY) "$$f" 2>/dev/null); \
194207 ruby_rc=$$?; \
208+ if [ $$ruby_rc -ne 0 ] && [ "$(REF_RUBY)" != "ruby" ]; then \
209+ expected=$$($(TIMEOUT60) ruby "$$f" 2>/dev/null); \
210+ ruby_rc=$$?; \
211+ fi; \
195212 if [ $$ruby_rc -eq 124 ]; then \
196213 echo "SKIP: $$bn (ruby timeout)"; skip=$$((skip+1)); \
197214 else \