From 0832cc89dc19a6770fc52203eb7219b8072e0fb4 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 28 Aug 2014 19:53:41 -0700 Subject: [PATCH] 85 - trace testing ahoy (http://akkartik.name/post/tracing-tests) --- mu.arc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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*))