Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by
From https://gist.github.com/borkdude/a7c38295f19a0dd2a68a7da21d634661


;; 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)


These tests pass in Clojure, but not in ClojureScript.
Probably due to side effects at macro expansion time.
Mike Fikes noted in #cljs-dev Slack that the order of analyzing the finally block is different in Clojure than in ClojureScript.

I ran into this issue when implementing with-instrumentation and with-unstrumentation macros for Clojure and ClojureScript. They worked in Clojure as expected, but in ClojureScript the above issue was manifested.

1 Answer

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJS-2949 (reported by borkdude)
...