Skip to content

Commit 7d3b94d

Browse files
borkdudemfikes
authored andcommitted
CLJS-2975: unstrument returns symbol of non-instrumented var
Fixed by checking if var is spec'ed in stest/instrument.
1 parent 0cba371 commit 7d3b94d

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

src/main/cljs/cljs/spec/test/alpha.cljc

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,16 @@ returns the set of all symbols naming vars in those nses."
5656
(defmacro instrument-1
5757
[[quote s] opts]
5858
(when-let [v (ana-api/resolve &env s)]
59-
(when (and (nil? (:const v))
60-
#?(:cljs (nil? (:macro v))))
61-
(swap! instrumented-vars conj (:name v))
62-
`(let [checked# (#'instrument-1* '~s (var ~s) ~opts)]
63-
(when checked# (set! ~s checked#))
64-
'~(:name v)))))
59+
(let [var-name (:name v)]
60+
(when (and (nil? (:const v))
61+
#?(:cljs (nil? (:macro v)))
62+
(contains? #?(:clj (s/speced-vars)
63+
:cljs (cljs.spec.alpha$macros/speced-vars))
64+
var-name))
65+
(swap! instrumented-vars conj var-name)
66+
`(let [checked# (#'instrument-1* '~s (var ~s) ~opts)]
67+
(when checked# (set! ~s checked#))
68+
'~var-name)))))
6569

6670
(defmacro unstrument-1
6771
[[quote s]]

src/test/cljs/cljs/spec/test_test.cljs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(ns cljs.spec.test-test
22
(:require-macros [cljs.spec.test.test-macros])
3-
(:require [cljs.test :as test :refer-macros [deftest is are run-tests]]
3+
(:require [cljs.test :as test :refer-macros [deftest testing
4+
is are run-tests]]
45
[cljs.spec.alpha :as s]
56
[cljs.spec.test.alpha :as stest]
67
[cljs.spec.test.test-ns1]
@@ -109,3 +110,10 @@
109110
(is (nil? @#'stest/*instrument-enabled*))
110111
(fn-2953 "abc"))))
111112
(is @#'stest/*instrument-enabled*))
113+
114+
(defn fn-2975 [x])
115+
116+
(deftest test-2975
117+
(testing "instrument and unstrument return empty coll when no fdef exists"
118+
(is (empty? (stest/instrument `fn-2975)))
119+
(is (empty? (stest/unstrument `fn-2975)))))

0 commit comments

Comments
 (0)