HS: null-safety piece 1 — eval-hs-error recognizer + helper (+18 tests unlocked)

Add recognizer for expect(await error("HS")).toBe("MSG") pattern in
generate-sx-tests.py, plus eval-hs-error SX helper in the generated
test file. All 18 runtimeErrors tests now generate real test cases
instead of SKIP stubs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-25 12:10:19 +00:00
parent fb72c4ab9c
commit 3316d402fd
2 changed files with 113 additions and 18 deletions

View File

@@ -88,6 +88,27 @@
(raise _e))))
(handler me-val))))))
;; Evaluate a hyperscript expression, catch the first error raised, and
;; return its message string. Used by runtimeErrors tests.
;; Returns nil if no error is raised (test would then fail equality).
(define eval-hs-error
(fn (src)
(let ((sx (hs-to-sx (hs-compile src))))
(let ((handler (eval-expr-cek
(list (quote fn) (list (quote me))
(list (quote let) (list (list (quote it) nil) (list (quote event) nil)) sx)))))
(guard
(_e
(true
(if
(string? _e)
_e
(if
(and (list? _e) (= (first _e) "hs-return"))
nil
(str _e)))))
(begin (handler nil) nil))))))
;; ── add (19 tests) ──
(defsuite "hs-upstream-add"
(deftest "can add a value to a set"
@@ -2153,41 +2174,75 @@
;; ── core/runtimeErrors (18 tests) ──
(defsuite "hs-upstream-core/runtimeErrors"
(deftest "reports basic function invocation null errors properly"
(error "SKIP (untranslated): reports basic function invocation null errors properly"))
(assert= (eval-hs-error "x()") "'x' is null")
(assert= (eval-hs-error "x.y()") "'x' is null")
(assert= (eval-hs-error "x.y.z()") "'x.y' is null")
)
(deftest "reports basic function invocation null errors properly w/ of"
(error "SKIP (untranslated): reports basic function invocation null errors properly w/ of"))
(assert= (eval-hs-error "z() of y of x") "'z' is null")
)
(deftest "reports basic function invocation null errors properly w/ possessives"
(error "SKIP (untranslated): reports basic function invocation null errors properly w/ possessives"))
(assert= (eval-hs-error "x's y()") "'x' is null")
(assert= (eval-hs-error "x's y's z()") "'x's y' is null")
)
(deftest "reports null errors on add command properly"
(error "SKIP (untranslated): reports null errors on add command properly"))
(assert= (eval-hs-error "add .foo to #doesntExist") "'#doesntExist' is null")
(assert= (eval-hs-error "add @foo to #doesntExist") "'#doesntExist' is null")
(assert= (eval-hs-error "add {display:none} to #doesntExist") "'#doesntExist' is null")
)
(deftest "reports null errors on decrement command properly"
(error "SKIP (untranslated): reports null errors on decrement command properly"))
(assert= (eval-hs-error "decrement #doesntExist's innerHTML") "'#doesntExist' is null")
)
(deftest "reports null errors on default command properly"
(error "SKIP (untranslated): reports null errors on default command properly"))
(assert= (eval-hs-error "default #doesntExist's innerHTML to 'foo'") "'#doesntExist' is null")
)
(deftest "reports null errors on hide command properly"
(error "SKIP (untranslated): reports null errors on hide command properly"))
(assert= (eval-hs-error "hide #doesntExist") "'#doesntExist' is null")
)
(deftest "reports null errors on increment command properly"
(error "SKIP (untranslated): reports null errors on increment command properly"))
(assert= (eval-hs-error "increment #doesntExist's innerHTML") "'#doesntExist' is null")
)
(deftest "reports null errors on measure command properly"
(error "SKIP (untranslated): reports null errors on measure command properly"))
(assert= (eval-hs-error "measure #doesntExist") "'#doesntExist' is null")
)
(deftest "reports null errors on put command properly"
(error "SKIP (untranslated): reports null errors on put command properly"))
(assert= (eval-hs-error "put 'foo' into #doesntExist") "'#doesntExist' is null")
(assert= (eval-hs-error "put 'foo' into #doesntExist's innerHTML") "'#doesntExist' is null")
(assert= (eval-hs-error "put 'foo' into #doesntExist.innerHTML") "'#doesntExist' is null")
(assert= (eval-hs-error "put 'foo' before #doesntExist") "'#doesntExist' is null")
(assert= (eval-hs-error "put 'foo' after #doesntExist") "'#doesntExist' is null")
(assert= (eval-hs-error "put 'foo' at the start of #doesntExist") "'#doesntExist' is null")
(assert= (eval-hs-error "put 'foo' at the end of #doesntExist") "'#doesntExist' is null")
)
(deftest "reports null errors on remove command properly"
(error "SKIP (untranslated): reports null errors on remove command properly"))
(assert= (eval-hs-error "remove .foo from #doesntExist") "'#doesntExist' is null")
(assert= (eval-hs-error "remove @foo from #doesntExist") "'#doesntExist' is null")
(assert= (eval-hs-error "remove #doesntExist from #doesntExist") "'#doesntExist' is null")
)
(deftest "reports null errors on send command properly"
(error "SKIP (untranslated): reports null errors on send command properly"))
(assert= (eval-hs-error "send 'foo' to #doesntExist") "'#doesntExist' is null")
)
(deftest "reports null errors on sets properly"
(error "SKIP (untranslated): reports null errors on sets properly"))
(assert= (eval-hs-error "set x's y to true") "'x' is null")
(assert= (eval-hs-error "set x's @y to true") "'x' is null")
)
(deftest "reports null errors on settle command properly"
(error "SKIP (untranslated): reports null errors on settle command properly"))
(assert= (eval-hs-error "settle #doesntExist") "'#doesntExist' is null")
)
(deftest "reports null errors on show command properly"
(error "SKIP (untranslated): reports null errors on show command properly"))
(assert= (eval-hs-error "show #doesntExist") "'#doesntExist' is null")
)
(deftest "reports null errors on toggle command properly"
(error "SKIP (untranslated): reports null errors on toggle command properly"))
(assert= (eval-hs-error "toggle .foo on #doesntExist") "'#doesntExist' is null")
(assert= (eval-hs-error "toggle between .foo and .bar on #doesntExist") "'#doesntExist' is null")
(assert= (eval-hs-error "toggle @foo on #doesntExist") "'#doesntExist' is null")
)
(deftest "reports null errors on transition command properly"
(error "SKIP (untranslated): reports null errors on transition command properly"))
(assert= (eval-hs-error "transition #doesntExist's *visibility to 0") "'#doesntExist' is null")
)
(deftest "reports null errors on trigger command properly"
(error "SKIP (untranslated): reports null errors on trigger command properly"))
(assert= (eval-hs-error "trigger 'foo' on #doesntExist") "'#doesntExist' is null")
)
)
;; ── core/scoping (20 tests) ──