plt/graphical-ui.ss
;; graphical-ui
;; Implements a user interface for SchemeUnit tests using the MrEd toolkit.

(module graphical-ui mzscheme
  (require (lib "class.ss")
           "test.ss"
           "gui/controller.ss"
           "gui/model.ss"
           "gui/view.ss")

  (provide embed-graphical-ui
           test/graphical-ui)

  (define (test? x)
    (or (schemeunit-test-case? x)
        (and (schemeunit-test-suite? x)
             (andmap test? (schemeunit-test-suite-tests x)))))
  
  (define (embed-graphical-ui test display-window)
    (embed-graphical-ui* test display-window #t))
  
  (define (embed-graphical-ui* test display-window embedded?)
    (unless (test? test)
      (error 'embed-graphical-ui
             "not a SchemeUnit test: ~e"
             test))
    (instantiate controller% ()
      (model-case% model-case%)
      (model-suite% model-suite%)
      (view% view%)
      (display-window display-window)
      (embedded? embedded?)
      (test test)))
  
  (define test/graphical-ui
    (case-lambda 
      [(test)
       (test/graphical-ui test #t)]
      [(test run?)
       (let ((gui (embed-graphical-ui* test (make-view-frame) #f)))
         (when run? (send gui run))
         (void))]))
  
  )