Skip to content
Browse files

Fixed issues TRACE-3 to TTRACE-7

  • Loading branch information...
1 parent c797648 commit 78b8d93bb41f76d3530e3efbf375c07f28f6ad40 @lprefontaine lprefontaine committed Mar 14, 2014
Showing with 25 additions and 11 deletions.
  1. +1 −1 project.clj
  2. +7 −6 src/main/clojure/clojure/tools/trace.clj
  3. +17 −4 src/test/clojure/clojure/tools/test_trace.clj
View
2 project.clj
@@ -1,4 +1,4 @@
-(defproject tools.trace "0.7.6-SNAPSHOT"
+(defproject tools.trace "0.7.7-SNAPSHOT"
:description "A Clojure tracing facility in Clojure"
:parent [org.clojure/pom.contrib "0.1.2"]
:url "https://github.com/clojure/tools.trace"
View
13 src/main/clojure/clojure/tools/trace.clj
@@ -108,7 +108,7 @@ symbol name of the function."
(let [doc-string (if (string? (first definition)) (first definition) "")
fn-form (if (string? (first definition)) (rest definition) definition)]
`(do
- (def ~name)
+ (declare ~name)
(let [f# (fn ~@fn-form)]
(defn ~name ~doc-string [& args#]
(trace-fn-call '~name f# args#))))))
@@ -272,9 +272,10 @@ such as clojure.core/+"
(try
(let [ctor (.getConstructor (class this) (into-array [java.lang.String]))
arg (first args)]
- (string? arg)
- (doto (.newInstance ctor (into-array [arg])) (.setStackTrace stack-trace))
- :else (doto (.newInstance ctor (into-array [(str arg)])) (.setStackTrace stack-trace)))
+ (cond
+ (string? arg)
+ (doto (.newInstance ctor (into-array [arg])) (.setStackTrace stack-trace))
+ :else (doto (.newInstance ctor (into-array [(str arg)])) (.setStackTrace stack-trace))))
(catch Exception e# this))))
(extend-type java.lang.Object
@@ -327,7 +328,7 @@ such as clojure.core/+"
(let [^clojure.lang.Var v (if (var? v) v (resolve v))
ns (.ns v)
s (.sym v)]
- (if (and (ifn? @v) (-> v meta :macro not))
+ (if (and (ifn? @v) (-> v meta :macro not) (-> v meta ::traced not))
(let [f @v
vname (symbol (str ns "/" s))]
(doto v
@@ -377,7 +378,7 @@ such as clojure.core/+"
[ns]
(let [ns (the-ns ns)]
(when-not ('#{clojure.core clojure.tools.trace} (.name ns))
- (let [ns-fns (->> ns ns-interns vals)]
+ (let [ns-fns (->> ns ns-interns vals (filter (comp fn? var-get)))]
(doseq [f ns-fns]
(trace-var* f))))))
View
21 src/test/clojure/clojure/tools/test_trace.clj
@@ -65,7 +65,8 @@
(binding [*ns* trace-ns-test-namespace]
(eval '(clojure.core/refer-clojure))
(eval '(defn foo [] :foo))
- (eval '(defn bar [] (foo))))
+ (eval '(defn bar [] (foo)))
+ (eval '(def baz :baz)))
(deftest test-trace-foo
(trace-vars trace.test.namesp/bar)
@@ -92,9 +93,21 @@
(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))
+ (trace-vars trace.test.namesp/bar)
+ (trace-vars trace.test.namesp/bar)
+ (trace-vars trace.test.namesp/bar)
+ (untrace-vars trace.test.namesp/bar)
+ (is (not (traced? 'trace.test.namesp/bar))))
+
+(deftest test-trace-ns-does-not-trace-non-fns
+ (is (not (traced? 'trace.test.namesp/bar)))
+ (is (not (traced? 'trace.test.namesp/baz)))
+ (trace-ns trace-ns-test-namespace)
+ (is (traced? 'trace.test.namesp/bar))
+ (is (not (traced? 'trace.test.namesp/baz)))
+ (untrace-ns trace-ns-test-namespace)
+ (is (not (traced? 'trace.test.namesp/bar)))
+ (is (not (traced? 'trace.test.namesp/baz))))
(deftest istraceable
(is (traceable? 'trace.test.namesp/bar)))
-
-(run-tests)

0 comments on commit 78b8d93

Please sign in to comment.
Something went wrong with that request. Please try again.