Root causes of server [http-load] errors: 1. _import_hook passed pre-computed string key to library_loaded_p which calls library_name_key(string) → sx_to_list(string) → crash. Fix: pass original list spec, not the string key. 2. resolve_library_path didn't check web/lib/ for (sx dom), (sx browser), (web boot-helpers). These libraries use namespace prefixes that don't match their file locations. Server startup errors: 190 → 0. 2683/2684 tests pass (1 known: define-library import clause — spec gap). New test file: spec/tests/test-import-bind.sx Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
76 lines
1.9 KiB
Plaintext
76 lines
1.9 KiB
Plaintext
;; Tests for import binding — catching bind_import_set bugs
|
|
|
|
;; Test 1: basic define-library + import (same session)
|
|
(define-library (test basic-lib)
|
|
(export double greet)
|
|
(begin
|
|
(define double (fn (x) (* x 2)))
|
|
(define greet "hi")))
|
|
|
|
(import (test basic-lib))
|
|
|
|
(deftest "import binds exported functions"
|
|
(assert= (double 5) 10))
|
|
|
|
(deftest "import binds exported values"
|
|
(assert= greet "hi"))
|
|
|
|
;; Test 2: library with import clause inside define-library
|
|
;; This is what engine.sx does — import clause triggers suspension.
|
|
;; The define-library handler should process import clauses.
|
|
(define-library (test dep-lib)
|
|
(export triple)
|
|
(begin
|
|
(define triple (fn (x) (* x 3)))))
|
|
|
|
(define-library (test uses-dep)
|
|
(export six-times)
|
|
(import (test dep-lib))
|
|
(begin
|
|
(define six-times (fn (x) (triple (double x))))))
|
|
|
|
(import (test uses-dep))
|
|
|
|
(deftest "define-library import clause binds into library env"
|
|
(assert= (six-times 2) 12))
|
|
|
|
;; Test 3: import after cek_run suspension
|
|
(define-library (test suspended-lib)
|
|
(export add10)
|
|
(begin
|
|
(define add10 (fn (x) (+ x 10)))))
|
|
|
|
(import (test suspended-lib))
|
|
|
|
(deftest "import after suspension binds correctly"
|
|
(assert= (add10 5) 15))
|
|
|
|
;; Test 4: library-loaded? works
|
|
(deftest "library-loaded? accepts list spec"
|
|
(assert= (library-loaded? (quote (test basic-lib))) true))
|
|
|
|
;; Test 5: re-import binds
|
|
(define-library (test reimport)
|
|
(export val99)
|
|
(begin
|
|
(define val99 99)))
|
|
|
|
(import (test reimport))
|
|
|
|
(deftest "re-import of loaded library binds exports"
|
|
(assert= val99 99))
|
|
|
|
;; Test 6: bind_import_set with library loaded by _import_hook
|
|
;; When the hook loads a library, the library key in the registry
|
|
;; may be a string "web engine" rather than a list (web engine).
|
|
;; bind_import_set must handle both.
|
|
(define-library (test string-key-lib)
|
|
(export sval)
|
|
(begin
|
|
(define sval 42)))
|
|
|
|
(import (test string-key-lib))
|
|
|
|
(deftest "import works with string-keyed library"
|
|
(assert= sval 42))
|