Skip to content

Commit

Permalink
Added traced? and untraced? fns (issue TTRACE-1)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucprefontaine committed Nov 14, 2012
1 parent 1eeaf1d commit 140724f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/main/clojure/clojure/tools/trace.clj
Expand Up @@ -313,6 +313,18 @@ such as clojure.core/+"
(defmacro untrace-ns
"Untrace all fns in the given name space."
[ns]
`(untrace-ns* ~ns))
`(untrace-ns* ~ns))

(defn traced?
"Returns true if the given var is currently traced, false otherwise"
[v]
(let [^clojure.lang.Var v (if (var? v) v (resolve v))]
(-> v meta ::traced nil? not)))

(defn traceable?
"Returns true if the given var can be traced, false otherwise"
[v]
(let [^clojure.lang.Var v (if (var? v) v (resolve v))]
(and (ifn? @v) (-> v meta :macro not))))


13 changes: 11 additions & 2 deletions src/test/clojure/clojure/tools/test_trace.clj
Expand Up @@ -27,7 +27,7 @@
(trace-forms ((fn [] (let [ d (/ 3 0)] d)))))

(deftest test-with-docstring
(is (= (.endsWith (cleanup (:doc (meta (var fn-a)))) "fn-a Doc string") true)
(is (= (.endsWith ^String (cleanup (:doc (meta (var fn-a)))) "fn-a Doc string") true)
(is (= (cleanup (with-out-str (fn-a 1 2 3))) "TRACE t:# (fn-a 1 2 3)|TRACE t:# => 6|"))))

(deftest test-no-docstring
Expand Down Expand Up @@ -62,7 +62,7 @@
(deftest test-trace-all
(trace-vars trace.test.namesp/bar trace.test.namesp/foo)
(is (= (cleanup (with-out-str (trace.test.namesp/bar)))
"TRACE t:# (trace.test.namesp/bar)|TRACE t:# | (trace.test.namesp/foo)|TRACE t:# | => :foo|TRACE t:# => :foo|"))
"TRACE t:# (trace.test.namesp/bar)|TRACE t:# | (trace.test.namesp/foo)|TRACE t:# | => :foo|TRACE t:# => :foo|" ))
(untrace-vars trace.test.namesp/bar trace.test.namesp/foo)
(is (= (cleanup (with-out-str (trace.test.namesp/bar))) "")))

Expand All @@ -73,4 +73,13 @@
(untrace-ns trace-ns-test-namespace)
(is (= (cleanup (with-out-str (trace.test.namesp/bar))) "")))

(deftest istraced
(is (not (traced? 'trace.test.namesp/bar)))
(trace-vars trace.test.namesp/bar)
(is (traced? 'trace.test.namesp/bar))
(untrace-vars trace.test.namesp/bar))

(deftest istraceable
(is (traceable? 'trace.test.namesp/bar)))

(run-tests)

0 comments on commit 140724f

Please sign in to comment.