about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-08-28 19:53:41 -0700
committerKartik K. Agaram <vc@akkartik.com>2014-08-28 19:53:41 -0700
commit0832cc89dc19a6770fc52203eb7219b8072e0fb4 (patch)
treeaf9e15ef0cd72a6175bc05f504abb34b2c954bf0
parentc532f0ab5f2bac171dad9a0ed86fb56800f7740f (diff)
downloadmu-0832cc89dc19a6770fc52203eb7219b8072e0fb4.tar.gz
85 - trace testing ahoy (http://akkartik.name/post/tracing-tests)
-rw-r--r--mu.arc26
1 files changed, 26 insertions, 0 deletions
diff --git a/mu.arc b/mu.arc
index a850363e..8d727a8e 100644
--- a/mu.arc
+++ b/mu.arc
@@ -5,6 +5,32 @@
   (each f (as cons initialization-fns*)
     (f)))
 
+(mac on-init body
+  `(enq (fn () ,@body)
+        initialization-fns*))
+
+(on-init
+  (= traces* nil))
+(def trace (label . args)
+  (push (list label (apply tostring:prn args))
+        traces*))
+(def assert-trace-contains (label string)
+  (assert (pos (fn ((curr-label curr-msg))
+                 (and (is label curr-label)
+                      (posmatch string curr-msg)))
+               traces*)
+          (tostring
+            (prn "Couldn't find " (tostring write.string) " in label:")
+            (each (curr-label curr-msg) traces*
+              (if (is label curr-label)
+                (prn "  " curr-msg))))))
+
+(reset)
+(trace "foo" "abc")
+(assert-trace-contains "foo" "abc")
+(assert-trace-contains "foo" "abd")
+(quit)
+
 (mac init-fn (name . body)
   `(enq (fn () (= (function* ',name) ',body))
         initialization-fns*))