Commit 93e1bc67

93e1bc678f01Merged

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

Description

build: regen-expected target + .expected fallback in test harness

Adds a regen-expected Make target that runs each test/*.rb under the reference Ruby and writes the captured stdout to test/.rb.expected (CRLF normalized).

The per-test .ok recipe now prefers test/.rb.expected when it exists, skipping the per-run Ruby invocation. When .expected is missing the recipe falls back to the existing Ruby path, so this commit is a no-op for behavior — the speedup arrives in the follow-up commit that actually checks in the .expected files.

Motivation: in CI, especially on Windows mingw64 ruby, hundreds of ruby test/foo.rb invocations add up. Pre-computing the expected output once and committing it to the repo lets CI skip Ruby entirely for tests that have a .expected.

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

Details

Commit
93e1bc678f01
Parent
f8dd3556c646

MakefilemodifiedView file

@@ -91,7 +91,7 @@
9191 PRISM_OBJ = $(patsubst $(PRISM_DIR)/src/%.c,build/prism/%.o,$(PRISM_SRC))
9292 PRISM_LIB = build/libprism.a
9393
94-.PHONY: all parse bootstrap codegen test test-run clean-test-results bench clean install uninstall deps
94+.PHONY: all parse bootstrap codegen test test-run clean-test-results regen-expected bench clean install uninstall deps
9595
9696 all: parse regexp spinel_codegen$(EXE)
9797
@@ -231,13 +231,17 @@
231231 ./spinel_codegen$(EXE) "$$ast" "$$cfile" 2>/dev/null && \
232232 $(CC) $(CFLAGS) -Werror $(SEC_FLAGS) -Ilib "$$cfile" $(SP_RT_LIB) $(LDFLAGS) -lm $(GC_FLAGS) -o "$$bin" 2>/dev/null; \
233233 if [ $$? -eq 0 ]; then \
234- $(TIMEOUT10) $(REF_RUBY) "$<" >"$$exp" 2>/dev/null; \
235- ruby_rc=$$?; \
236- if [ $$ruby_rc -ne 0 ] && [ "$(REF_RUBY)" != "ruby" ]; then \
237- $(TIMEOUT10) ruby "$<" >"$$exp" 2>/dev/null; \
234+ if [ -f "$<.expected" ]; then \
235+ cp "$<.expected" "$$exp.n"; \
236+ else \
237+ $(TIMEOUT10) $(REF_RUBY) "$<" >"$$exp" 2>/dev/null; \
238+ ruby_rc=$$?; \
239+ if [ $$ruby_rc -ne 0 ] && [ "$(REF_RUBY)" != "ruby" ]; then \
240+ $(TIMEOUT10) ruby "$<" >"$$exp" 2>/dev/null; \
241+ fi; \
242+ LC_ALL=C sed 's/\r$$//' "$$exp" >"$$exp.n"; \
238243 fi; \
239244 $(TIMEOUT10) "$$bin" >"$$act" 2>/dev/null; \
240- LC_ALL=C sed 's/\r$$//' "$$exp" >"$$exp.n"; \
241245 LC_ALL=C sed 's/\r$$//' "$$act" >"$$act.n"; \
242246 if cmp -s "$$exp.n" "$$act.n"; then \
243247 echo PASS > "$@"; \
@@ -256,6 +260,26 @@
256260 clean-test-results:
257261 @rm -rf build/test-results
258262
263+# ---- Expected-output regeneration ----
264+# Capture each test's reference Ruby output into test/<name>.rb.expected.
265+# Once committed, the test target uses the .expected file directly and
266+# skips the per-test ruby invocation — useful in CI where ruby's startup
267+# (especially mingw64 ruby on Windows) adds up across hundreds of tests.
268+# Regenerate after adding or modifying tests; commit the result.
269+
270+EXPECTED_FILES := $(patsubst test/%.rb,test/%.rb.expected,$(TESTS))
271+
272+regen-expected: $(EXPECTED_FILES)
273+
274+test/%.rb.expected: test/%.rb
275+ @$(TIMEOUT10) $(REF_RUBY) $< >[email protected] 2>/dev/null; \
276+ rc=$$?; \
277+ if [ $$rc -ne 0 ] && [ "$(REF_RUBY)" != "ruby" ]; then \
278+ $(TIMEOUT10) ruby $< >[email protected] 2>/dev/null; \
279+ fi; \
280+ LC_ALL=C sed 's/\r$$//' [email protected] > $@; \
282+
259283 bench: spinel_parse$(EXE) $(SP_RT_LIB) spinel_codegen$(EXE)
260284 @if [ -z "$(TIMEOUT_BIN)" ]; then echo "Note: no 'timeout' command found; running without time limits."; fi
261285 @total=$$(ls benchmark/*.rb | wc -l); \