Skip to content

Instantly share code, notes, and snippets.

@borkdude
Last active October 29, 2018 09:55
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 borkdude/a7c38295f19a0dd2a68a7da21d634661 to your computer and use it in GitHub Desktop.
Save borkdude/a7c38295f19a0dd2a68a7da21d634661 to your computer and use it in GitHub Desktop.
instrument/unstrument in cljs
;; run with:
;; clj -Srepro -Sdeps '{:deps {org.clojure/clojurescript {:git/url "https://github.com/clojure/clojurescript" :sha "4fb83eff87cc456600a3fd21c111e99a41c61285"}}}' -m cljs.main -re node -i repro_test.cljs
(ns repro-test
(:require
[clojure.spec.alpha :as s]
[clojure.spec.test.alpha :as stest]
[clojure.test :as t :refer [deftest is testing]]))
(defn foo [n]
"ret")
(s/fdef foo
:args (s/cat :n number?)
:ret number?)
(deftest repro-test
(testing "unstrument in finally works"
(is (= "oops"
(try
(stest/instrument `foo)
(foo "string")
(catch js/Error e "oops")
(finally
(stest/unstrument `foo))))))
(testing "should be unstrumented after try/catch/finally"
(let [ret (try (foo "string")
(catch js/Error e "not-ret"))]
(is (= "ret" ret)) ;; FAILS
(testing "if ret wasn't ret, then foo was still instrumented. unstrumenting..."
(is (seq (s/unstrument `foo))) ;; FAILS
))))
(t/run-tests)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment