Skip to content

Instantly share code, notes, and snippets.

@bhb
Created May 30, 2018 18:02
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/e8328ce1c15c3fc6f5f4ea71cabfa076 to your computer and use it in GitHub Desktop.
Save bhb/e8328ce1c15c3fc6f5f4ea71cabfa076 to your computer and use it in GitHub Desktop.
instrumentation with clojure.spec
➜ ~ clojure -Sdeps "{:deps {com.bhauman/rebel-readline {:mvn/version \"0.1.3\"}}}" -m rebel-readline.main
[Rebel readline] Type :repl/help for online help info
user=> (require '[clojure.spec.alpha :as s])
nil
user=> (s/fdef foo :args (s/cat :x int? :y string?))
user/foo
user=> (defn foo [x y] (prn {:x x :y y}) {y x})
#'user/foo
user=> (require '[clojure.spec.test.alpha :as st])
nil
user=> (st/instrument)
[user/foo]
user=> (foo 1 "")
{:x 1, :y ""}
{"" 1}
user=> (foo "a" "b")
ExceptionInfo Call to #'user/foo did not conform to spec:
In: [0] val: "a" fails at: [:args :x] predicate: int?
clojure.core/ex-info (core.clj:4739)
user=>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment