Skip to content

Instantly share code, notes, and snippets.

@bhb
Last active November 25, 2018 23:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhb/6bd51f798f9eaa50850fb18c44aaa733 to your computer and use it in GitHub Desktop.
Save bhb/6bd51f798f9eaa50850fb18c44aaa733 to your computer and use it in GitHub Desktop.
Replacing default spec printer for experimentation
;; launch with
;; clj -Srepro -Sdeps '{:deps {org.clojure/test.check {:mvn/version "0.9.0"} org.clojure/clojure {:mvn/version "1.10.0-beta8"}}}'
(require '[clojure.spec.alpha :as s])
(require '[clojure.spec.test.alpha :as st])
;; instrumenting a function
(s/fdef foobar :args (s/cat :x int?))
(defn foobar [x] x)
(st/instrument)
;; set up an example spec printer
(set! s/*explain-out* (fn [e-data] (println "SPEC ERROR!")))
(foobar "")
;; Execution error - invalid arguments to user/foobar at (REPL:1).
;; SPEC ERROR!
(let [x])
;; launch with
;; clj -Srepro -Sdeps '{:deps {org.clojure/test.check {:mvn/version "0.9.0"} org.clojure/clojurescript {:mvn/version "1.10.439"}}}' --main cljs.main --repl
(require '[cljs.spec.alpha :as s])
(require '[cljs.spec.test.alpha :as st])
;; instrumenting a function
(s/fdef foobar :args (s/cat :x int?))
(defn foobar [x] x)
(st/instrument)
;; set up an example spec printer
(set! s/*explain-out* (fn [e-data] (println "SPEC ERROR!")))
(foobar "")
;; Expected:
;; Execution error - invalid arguments to user/foobar at (REPL:1).
;; SPEC ERROR!
;; Actual:
;; #error {:message "Call to #'cljs.user/foobar did not conform to spec.", :data #:cljs.spec.alpha{:problems [{:path [:x], :pred cljs.core/int?, :val "", :via [], :in [0]}], :spec #object[cljs.spec.alpha.t_cljs$spec$alpha1379], :value (""), :fn cljs.user/foobar, :args (""), :failure :instrument}}
;; cljs$core$ExceptionInfo (cljs/core.cljs:11154:11)
;; cljs.core.ex_info.cljs$core$IFn$_invoke$arity$3 (cljs/core.cljs:11186:5)
;; cljs.core.ex_info.cljs$core$IFn$_invoke$arity$2 (cljs/core.cljs:11184:16)
;; cljs.core/ex-info (cljs/core.cljs:11181:1)
;; cljs$spec$test$alpha$spec_checking_fnconform_BANG_ (cljs/spec/test/alpha.cljs:104:34)
;; G__1767__delegate (cljs/spec/test/alpha.cljs:118:42)
;; G__1767 (cljs/spec/test/alpha.cljs:115:20)
;; This also effects macroexpansion error reporting e.g. try
(let [x])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment