#! /bin/sh
#|
exec racket -tm "$0" ${1+"$@"}
|#

#lang racket

;; ---------------------------------------------------------------------------------------------------
;; runs ./game-tester on all in<n>.xml files in game-tests and compares the output with out<n>.xml

(provide main)

;; systems require: 
;; it relies on a script in xdiff-xml that compares XML outputs in the
;; context of SwDev projects
(define test-directory (make-parameter #f))
(define xml-diff       (make-parameter #f))
(define xclient        (make-parameter #f))

;; ---------------------------------------------------------------------------------------------------
;; implementation 

(define (main . x)
  (define files
    (parameterize ((current-directory (test-directory)))
      (for/list ((f (directory-list)) #:when (regexp-match #px"in(\\d).xml$" (path->string f)))
	(second (regexp-match #px"in(\\d).xml$" (path->string f))))))
  (for ((n files))
    (test n)))

;; String [Nat] -> Boolean 
(define (test n)
  (displayln "-----------------------------------------------------------------------------")
  (printf    "testing in~a.xml, out~a.xml\n" n n)
  (define client (format (xclient) (test-directory) n))
  (define xdiff  (format (xml-diff) (test-directory) n))
  (system (format "~a | ~a " client xdiff))
  (void))


;; ---------------------------------------------------------------------------------------------------
;; a script that runs client on all in<n>.xml files and compares the expected XML output wuth outN.xml

(test-directory "largest-alpha/")
(xml-diff       "./xdiff-xml - ~aout~a.xml")
(xclient        "./game-tester < ~ain~a.xml")

