debug-test.ss
(module debug-test mzscheme
    
  (require 
   (planet "io.ss" ("dherman" "io.plt" 1 6))
   (planet "test.ss" ("schematics" "schemeunit.plt" 2 0))
   (file "base.ss")
   (file "debug.ss")
   )
  
  (provide
   debug-tests
   )
  
  (define debug-tests
    (test-suite
     "All tests for debug"
     
     (test-case
      "Debug passes expression value through correctly"
      (with-output-to-string
       (check equal?
              (debug "Message" (+ 1 2 3))
              6)))
     
     (test-equal?
      "Debug prints message correctly"
      (with-output-to-string
       (debug "Message" (+ 1 2 3)))
      (format "D,\"Message\",6~n"))

     (test-equal?
      "Debug does not print when debug-enabled? is set to #f"
      (with-debug-enabled? #f
        (with-output-to-string
            (debug "Message" (+ 1 2 3))))
      (format ""))

     (test-equal?
      "let-debug prints correctly"
      (with-output-to-string
        (let-debug ([a 1]
                    [b 2])
          (+ a b)))
      "D,\"a\",1\nD,\"b\",2\n")

     (test-equal?
      "let*-debug support nesting"
      (with-output-to-string
        (let*-debug ([a 1]
                     [b (+ a 1)])
          (+ a b)))
      "D,\"a\",1\nD,\"b\",2\n")

     (test-equal?
      "letrec-debug support mutual recursion"
      (with-output-to-string
        (letrec-debug ([odd?
                        (lambda (n)
                          (if (zero? n)
                              #t
                              (even? (sub1 n))))]
                       [even?
                        (lambda (n)
                          (if (zero? n)
                              #f
                              (odd? (sub1 n))))])
          (odd? 7)))
      "D,\"odd?\",#<procedure:...ib/debug-test.ss:58:24>\nD,\"even?\",#<procedure:...ib/debug-test.ss:63:24>\n")

     (test-equal?
      "define-debug prints expected value"
      (with-output-to-string
        (define-debug a 2))
      "D,\"a\",2\n")
     ))
  )