eval/inject improved; testing won t fail on non existing javascript engine

This commit is contained in:
2026-05-28 00:07:21 +02:00
parent 8fe47a7ed4
commit e89ab88670
6 changed files with 185 additions and 66 deletions
+47
View File
@@ -21,6 +21,48 @@
(unless (regexp-match? #rx"__cmp" effectful-chain)
(error 'jsmaker-regression "effectful chained comparison should use temporaries, got: ~a" effectful-chain))
(define-syntax with-id->el
(syntax-rules ()
((_ id el expr)
(js (let ((el (send document getElementById (eval id))))
expr)))))
(define (runtime-eval-macro-function id html)
(with-id->el id el
(begin
(set! (js-dot el innerHTML) (eval html))
#t)))
(define runtime-eval-macro-program
(runtime-eval-macro-function 't "BEE"))
(unless (and (regexp-match? #rx"getElementById\\(\"t\"\\)" runtime-eval-macro-program)
(regexp-match? #rx"innerHTML = \"BEE\"" runtime-eval-macro-program)
(regexp-match? #rx"return true;" runtime-eval-macro-program))
(error 'jsmaker-regression
"runtime eval inside a user macro should keep use-site lexical bindings, got: ~a"
runtime-eval-macro-program))
(define-syntax with-id->el/inject
(syntax-rules ()
((_ id el expr)
(js (let ((el (send document getElementById (inject id))))
expr)))))
(define (runtime-inject-macro-function id html)
(with-id->el/inject id el
(begin
(set! (js-dot el innerHTML) (inject html))
#t)))
(define runtime-inject-macro-program
(runtime-inject-macro-function 't "BEE"))
(unless (and (regexp-match? #rx"getElementById\\(\"t\"\\)" runtime-inject-macro-program)
(regexp-match? #rx"innerHTML = \"BEE\"" runtime-inject-macro-program)
(regexp-match? #rx"return true;" runtime-inject-macro-program))
(error 'jsmaker-regression
"runtime inject inside a user macro should keep use-site lexical bindings, got: ~a"
runtime-inject-macro-program))
(define simple-let-star
(js (let* ((x 10)
(y (+ x x)))
@@ -75,6 +117,11 @@
(js-expression-test 'runtime-eval-lexical-let
(js/expression (let ([a (eval (* x y))]) (* a a)))
"40000"))
(let ([x 10]
[y 20])
(js-expression-test 'runtime-inject-lexical-let
(js/expression (let ([a (inject (* x y))]) (* a a)))
"40000"))
(js-expression-test 'substring (js/expression (substring "abcdef" 1 4)) "\"bcd\"")
(js-expression-test 'equal-list (js/expression (equal? (list 1 2) (list 1 2))) "true")
(js-expression-test 'cond-test-only (js/expression (cond [0] [else 2])) "0")
+17 -7
View File
@@ -8,8 +8,12 @@
js-program-test
write-js-test-file
run-jsmaker-regression
notice-line
warning-line)
(define (notice-line who fmt . args)
(displayln (string-append "NOTE: " (apply format fmt args))))
(define (warning-line who fmt . args)
(displayln (string-append "WARNING: " (apply format fmt args))
(current-error-port)))
@@ -79,10 +83,16 @@
(error who "JavaScript regression failed with ~a; see ~a"
(js-engine-name engine) js-path))]
[else
(warning-line who "No JavaScript engine was found; regression tests were generated but not executed.")
(warning-line who "Generated JavaScript test file: ~a" js-path)
(warning-line who "Tried engines: ~a" (string-join (map symbol->string (known-js-engine-names)) ", "))
(warning-line who "Set JSMAKER_ENGINE to auto/node/deno/bun/qjs/d8/jsc/js/chromium or set JSMAKER_ENGINE_PATH.")
(warning-line who "For backwards compatibility, JSMAKER_NODE can point to a Node executable.")
(when (or (getenv "JSMAKER_REQUIRE_ENGINE") (getenv "JSMAKER_REQUIRE_NODE"))
(error who "JavaScript engine required by environment setting"))]))
(if (or (getenv "JSMAKER_REQUIRE_ENGINE") (getenv "JSMAKER_REQUIRE_NODE"))
(begin
(warning-line who "No JavaScript engine was found; regression tests were generated but not executed.")
(warning-line who "Generated JavaScript test file: ~a" js-path)
(warning-line who "Tried engines: ~a" (string-join (map symbol->string (known-js-engine-names)) ", "))
(warning-line who "Set JSMAKER_ENGINE to auto/node/deno/bun/qjs/d8/jsc/js/chromium or set JSMAKER_ENGINE_PATH.")
(warning-line who "For backwards compatibility, JSMAKER_NODE can point to a Node executable.")
(error who "JavaScript engine required by environment setting"))
(begin
(notice-line who "No JavaScript engine was found; using non-failing-javascript-stub.")
(notice-line who "Generated JavaScript test file: ~a" js-path)
(notice-line who "Generated tests were not executed by a JavaScript runtime.")
(notice-line who "Set JSMAKER_REQUIRE_ENGINE=1 to make a missing JavaScript engine fail.")))]))
+3 -2
View File
@@ -6,7 +6,8 @@
;; Compatibility wrapper for the older single-engine test runner name.
;; It now delegates to the generic framework/executor layer. When no engine
;; is available, the framework generates the JavaScript test file and reports a
;; skip/warning unless JSMAKER_REQUIRE_ENGINE or JSMAKER_REQUIRE_NODE is set.
;; is available, the framework generates the JavaScript test file and uses an
;; explicit non-failing-javascript-stub unless JSMAKER_REQUIRE_ENGINE or
;; JSMAKER_REQUIRE_NODE is set.
(define (run-jsmaker-node-regression who tests js-path)
(run-jsmaker-regression who tests js-path))