#lang scheme/base

(require scheme/list
         (only-in mzlib/etc this-expression-source-directory)
         (planet schematics/sake:1)

(define here (this-expression-source-directory))
(define package-name
  (string-append (path->string (last (explode-path here))) ".plt"))

;; We can't use the Sake action:test as we want to use the
;; in this directory, not the one installed in the
;; PLaneT cache.
(define (schemeunit-action:test module-path binding)
  (let ([n-failures (run-tests (dynamic-require module-path binding))])
    (if (zero? n-failures)
         (make-exn:fail (format "~a test(s) failed" n-failures)

(define-task compile
  (action:compile ""))

(define-task test
  (schemeunit-action:test "" 'all-schemeunit-tests))

(define-task planet-install
  (when (file-exists? "schemeunit.plt")
    (delete-file "schemeunit.plt"))
  (action:planet-archive ".")
  (rename-file-or-directory package-name "schemeunit.plt")
  (action:planet-remove "schematics" "schemeunit.plt" 3 5)
  (action:planet-install "schematics" "schemeunit.plt" 3 5))

(define-task all

(define-task default