jolt/test/integration/embedded-stdlib-test.janet
Yogthos f3f2c63ee7 bake the .clj stdlib into the binary
The Clojure stdlib namespaces (clojure.string/set/walk/edn/zip, jolt.http/
interop/shell/nrepl) were loaded cwd-relative, so the built binary couldn't
load them outside the repo. Now stdlib_embed slurps them all at build time into
a {ns -> source} map frozen in the image, and the loader falls back to it when a
namespace isn't found on disk. The artifact is self-contained — clojure.string
works from any directory.

Drops the one-off nREPL source embed (jolt.nrepl is covered by this now). The
baked-in stdlib is excluded from uberscript bundles since it's part of the
runtime. clojure.core is unchanged (Janet, auto-referred).

Test: embedded-stdlib-test requires from the embedded copy with FS roots cleared.
2026-06-05 23:51:03 -04:00

33 lines
1.4 KiB
Text

# The .clj stdlib (clojure.string, clojure.set, jolt.interop, …) is baked into the
# image at build time, so it loads even when the files aren't on disk. We simulate
# the shipped-binary-elsewhere case by clearing the filesystem source roots, so a
# require can only be satisfied by the embedded copy.
(use ../../src/jolt/api)
(use ../../src/jolt/types)
(def ctx (init))
(ctx-set-current-ns ctx "user")
(put (ctx :env) :source-paths @[]) # no FS roots — embedded fallback only
(var fails 0)
(defn check [label expr expected]
(let [r (protect (eval-string ctx expr))
got (if (r 0) (normalize-pvecs (r 1)) (string "ERR " (r 1)))]
(if (= got expected) (print " ok " label)
(do (++ fails) (printf " FAIL %s: want %q, got %q" label expected got)))))
(assert (> (length (get (ctx :env) :embedded-sources)) 0) "embedded-sources should be populated")
(check "clojure.string from embedded"
"(do (require (quote [clojure.string :as s])) (s/upper-case \"hi\"))" "HI")
(check "clojure.set from embedded"
"(do (require (quote [clojure.set :as set])) (vec (set/union #{1} #{2})))" [2 1])
(check "clojure.walk from embedded"
"(do (require (quote [clojure.walk :as w])) (w/keywordize-keys {\"a\" 1}))" {:a 1})
(check "jolt.interop from embedded"
"(do (require (quote [jolt.interop :as j])) (j/janet-type 1))" :number)
(if (> fails 0)
(error (string "embedded-stdlib-test: " fails " failing check(s)"))
(print "\nAll embedded-stdlib tests passed!"))