aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStuart Halloway <stu@thinkrelevance.com>2009-08-05 17:00:17 -0500
committerStuart Halloway <stu@thinkrelevance.com>2009-08-05 17:00:17 -0500
commit2d0079c159a37740173bbe289daca41e48723bfd (patch)
treed164adc5447834943be2248d16266c8716f8a810
parent6c95fe90829cc66f81345a011dc25fc487e4cf0b (diff)
minor fix to deftrace: traced functions can now refer to themselves
-rw-r--r--src/clojure/contrib/test_contrib.clj3
-rw-r--r--src/clojure/contrib/test_contrib/test_trace.clj12
-rw-r--r--src/clojure/contrib/trace.clj9
3 files changed, 20 insertions, 4 deletions
diff --git a/src/clojure/contrib/test_contrib.clj b/src/clojure/contrib/test_contrib.clj
index a846ab17..59859e1f 100644
--- a/src/clojure/contrib/test_contrib.clj
+++ b/src/clojure/contrib/test_contrib.clj
@@ -19,7 +19,8 @@
(def test-names
[:complex-numbers :fnmap :macro-utils :monads :pprint.pretty
:pprint.cl-format :str-utils :shell-out :test-graph
- :test-dataflow :test-java-utils :test-lazy-seqs])
+ :test-dataflow :test-java-utils :test-lazy-seqs
+ :test-trace])
(def test-namespaces
(map #(symbol (str "clojure.contrib.test-contrib." (name %)))
diff --git a/src/clojure/contrib/test_contrib/test_trace.clj b/src/clojure/contrib/test_contrib/test_trace.clj
new file mode 100644
index 00000000..4b283056
--- /dev/null
+++ b/src/clojure/contrib/test_contrib/test_trace.clj
@@ -0,0 +1,12 @@
+(ns clojure.contrib.test-contrib.test-trace
+ (:use clojure.test
+ [clojure.contrib trace str-utils]))
+
+(deftrace call-myself [n]
+ (when-not (< n 1)
+ (call-myself (dec n))))
+
+(deftest test-tracing-a-function-that-calls-itself
+ (let [output (with-out-str (call-myself 1))]
+ (is (re-find #"^TRACE t\d+: (call-myself 1)\nTRACE t\d+: | (call-myself 0)\nTRACE t\d+: | => nil\nTRACE t\d+: => nil$"
+ output)))) \ No newline at end of file
diff --git a/src/clojure/contrib/trace.clj b/src/clojure/contrib/trace.clj
index 70a20dbb..1ac00a70 100644
--- a/src/clojure/contrib/trace.clj
+++ b/src/clojure/contrib/trace.clj
@@ -77,6 +77,9 @@ code is doing."}
arguments. Nested calls to deftrace'd functions will print a
tree-like structure."
[name & definition]
- `(let [f# (fn ~@definition)]
- (defn ~name [& args#]
- (trace-fn-call '~name f# args#))))
+ `(do
+ (def ~name)
+ (let [f# (fn ~@definition)]
+ (defn ~name [& args#]
+ (trace-fn-call '~name f# args#)))))
+