;;;;
;;;; test-srfi.stk  -- Test of various SRFIs
;;;;
;;;; Copyright © 2005-2022 Erick Gallesio - I3S-CNRS/ESSI <eg@essi.fr>
;;;;
;;;;
;;;; This program is free software; you can redistribute it and/or modify
;;;; it under the terms of the GNU General Public License as published by
;;;; the Free Software Foundation; either version 2 of the License, or
;;;; (at your option) any later version.
;;;;
;;;; This program is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;;; GNU General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU General Public License
;;;; along with this program; if not, write to the Free Software
;;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
;;;; USA.
;;;;
;;;;           Author: Erick Gallesio [eg@essi.fr]
;;;;    Creation date:  4-Aug-2005 10:34 (eg)
;;;;

(require "srfi-48")   ;; for ~F format


(test-section "SRFIs")

;;;
;;; Run all the tests in "./srfi" directory
;;
(load "../lib/srfis.stk")

(define trace-srfi
  (let ((count 0))
    (lambda (nb)
      (if nb
          ;; print the SRFI number
          (begin
            (when (zero? (modulo count 12))
              (eprintf "\n  ")
              (set! count 0))
            (eprintf "~5f" nb)
            (set! count (+ count 1)))
          ;; print spaces before failed/passed status
          (eprintf "~a   " (make-string (- 60  (* count 5)) #\space)))
      (flush-output-port *err*))))

(dotimes (nb (+ (last-implemented-srfi) 1))
  (let ((desc (find-srfi nb)))
    (when desc                            ;; We have an impl. for this SRFI
      (let ((test-file (format "./srfis/~a.stk" nb)))
        (when (file-exists? test-file)    ;; and we have a test for it
          ;; Add a subsection title (and a trace)
          (test-subsection (format "SRFI ~S - ~S ..." nb (%srfi-title desc)))
          (trace-srfi nb)
          ;; Require the SRFI by importing it and run its tests
          ;; (require-feature nb)
          (eval `(import (srfi ,nb)) (current-module))
          (load test-file))))))

(trace-srfi #f)

(test-section-end)
