jolt/test/spec/exceptions-spec.janet
Yogthos 6abbea3835 Fix 4 clojure.core bugs surfaced by JVM certification
The corpus certifier (test/conformance) flagged four cases where jolt's
hand-written :expected matched a real defect rather than Clojure. Fixed in the
jolt-core overlay, corrected the spec :expected, re-certified against JVM Clojure:

- ex-message: returns nil for a non-throwable (dropped the lenient string branch);
  still returns the message for ex-info. (jolt-l8e8)
- munge: preserves the argument's type — a symbol munges to a symbol, not a string.
  (jolt-hc35)
- print: (print nil) emits "nil", not "" (top-level nil guard; str yields "").
  (jolt-pqio)
- bounded-count: uses the counted? fast path (full count), else counts up to n via
  seq — was (min n (count coll)), wrong for counted colls. Added an uncounted-coll
  spec case. (jolt-2507)

Removed the 4 :bug entries from known-divergences.edn (now certified), regenerated
corpus + profile, re-minted the Chez bootstrap seed (clojure.core changed). Gates:
Janet 155/0, JVM certify clean, both Chez corpus gates 2534 (floors raised),
bootstrap 6/6, fixpoint intact.
2026-06-20 11:06:33 -04:00

46 lines
2.3 KiB
Text

# Specification: exceptions — try/catch/finally, throw, ex-info.
(use ../support/harness)
(defspec "exceptions / try-catch"
["catch :default" ":caught"
"(try (throw (ex-info \"boom\" {})) (catch :default e :caught))"]
["catch by class" ":caught"
"(try (throw (ex-info \"boom\" {})) (catch Exception e :caught))"]
["catch binds error" "\"boom\""
"(try (throw (ex-info \"boom\" {})) (catch :default e (ex-message e)))"]
["no throw -> body" "1"
"(try 1 (catch :default e :caught))"]
["finally runs on ok" "2"
"(let [a (atom 0)] (try 2 (finally (reset! a 9))) )"]
["finally runs on throw" "9"
"(let [a (atom 0)] (try (throw (ex-info \"x\" {})) (catch :default e nil) (finally (reset! a 9))) @a)"]
["catch value of body" "5"
"(try (+ 2 3) (catch :default e 0))"]
# a malformed catch clause (binding not a symbol, or clause too short) is a
# clean error, not a silent nil or an internal crash (jolt-kg6p).
["malformed catch: non-symbol binding" :throws "(try 1 (catch e (* e 10)))"]
["malformed catch: literal binding" :throws "(try 1 (catch e 5))"]
["malformed catch: too short" :throws "(try 1 (catch Exception))"])
(defspec "exceptions / assert"
["assert true -> ok" ":ok" "(do (assert true) :ok)"]
["assert expr -> ok" ":ok" "(do (assert (= 1 1)) :ok)"]
["assert false throws" :throws "(assert false)"]
["assert nil throws" :throws "(assert nil)"])
(defspec "exceptions / ex-info"
["ex-message" "\"oops\"" "(ex-message (ex-info \"oops\" {}))"]
["ex-data" "{:k 1}" "(ex-data (ex-info \"oops\" {:k 1}))"]
["ex-data via catch" "{:code 42}"
"(try (throw (ex-info \"e\" {:code 42})) (catch :default e (ex-data e)))"]
["ex-cause" "true"
"(let [c (ex-info \"root\" {})] (= c (ex-cause (ex-info \"outer\" {} c))))"]
["propagates to outer" "\"inner\""
"(try (try (throw (ex-info \"inner\" {})) (finally nil)) (catch :default e (ex-message e)))"]
["catch binds thrown value" "42"
"(try (throw 42) (catch :default e e))"]
["rethrow preserves ex" "\"inner\""
"(try (try (throw (ex-info \"inner\" {})) (catch :default e (throw e))) (catch :default e (ex-message e)))"]
["ex-data on non-ex" "nil" "(ex-data 42)"]
["ex-cause on non-ex" "nil" "(ex-cause {:k 1})"]
["ex-message of string" "nil" "(ex-message \"hi\")"])