From e78d4fc5b3cead6f4cec447c2daebda6eaa3489c Mon Sep 17 00:00:00 2001 From: Mike Fikes Date: Thu, 1 Nov 2018 17:42:56 -0400 Subject: [PATCH] CLJS-2953: stest/with-instrument-disabled prints warning of private use --- src/main/cljs/cljs/spec/test/alpha.cljc | 8 ++++++-- src/test/cljs/cljs/spec/test_test.cljs | 12 ++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/cljs/cljs/spec/test/alpha.cljc b/src/main/cljs/cljs/spec/test/alpha.cljc index 636db8e20e..1fcf813d62 100644 --- a/src/main/cljs/cljs/spec/test/alpha.cljc +++ b/src/main/cljs/cljs/spec/test/alpha.cljc @@ -46,8 +46,12 @@ returns the set of all symbols naming vars in those nses." (defmacro with-instrument-disabled "Disables instrument's checking of calls, within a scope." [& body] - `(binding [*instrument-enabled* nil] - ~@body)) + `(let [orig# @#'*instrument-enabled*] + (set! *instrument-enabled* nil) + (try + ~@body + (finally + (set! *instrument-enabled* orig#))))) (defmacro instrument-1 [[quote s] opts] diff --git a/src/test/cljs/cljs/spec/test_test.cljs b/src/test/cljs/cljs/spec/test_test.cljs index 0bf9294a55..1c31a34db0 100644 --- a/src/test/cljs/cljs/spec/test_test.cljs +++ b/src/test/cljs/cljs/spec/test_test.cljs @@ -97,3 +97,15 @@ (stest/enumerate-namespace 'cljs.spec.test.test-ns1))) (is (= '#{cljs.spec.test.test-ns2/z} (stest/enumerate-namespace 'cljs.spec.test.test-ns2)))) + +(defn fn-2953 [x] ::ret-val) + +(s/fdef fn-2953 :args (s/cat :x int?)) + +(deftest test-cljs-2953 + (stest/instrument `fn-2953) + (is @#'stest/*instrument-enabled*) + (is (= ::ret-val (stest/with-instrument-disabled + (is (nil? @#'stest/*instrument-enabled*)) + (fn-2953 "abc")))) + (is @#'stest/*instrument-enabled*))