views:

112

answers:

1

I would like to have a Guile script, which implements functions, which output test result messages according to the TAP protocol.

+2  A: 

The following script, to be named guiletap.scm, implements the frequently-needed functions for using the TAP protocol when running tests.

; Define functions for running Guile-written tests under the TAP protocol.
; Copyright © 2008 by Omer Zak
; Released under the GNU LGPL 2.1 or (at your option) any later version.
;;;
;;; To invoke it:
;;; (use-modules (guiletap))
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-module (guiletap))
(export plan)
(export ok)
(export bail_out)
(export diag)
(export is_ok)

(use-modules (ice-9 format))

; n is the number of tests.
(define plan
  (lambda (n) (display (format "1..~d~%" n))))

; n -        test number
; testdesc - test descriptor
; res -      result which is #f at failure, other at success.
(define ok
  (lambda (n testdesc res)
    (if (not res)(display "not "))
    (display (format "ok ~d - ~a~%" n testdesc))))

; testdesc - test descriptor
(define bail_out
  (lambda (testdesc)
    (display (format "Bail out! - ~a~%" testdesc))))

; diagmsg - diagnostic message
(define diag
  (lambda (diagmsg)
    (display (format "# ~a~%" diagmsg))))

; n -        test number
; testdesc - test descriptor
; expres -   expected test result
; actres -   actual test result
(define is_ok
  (lambda (n testdesc expres actres)
    (ok n testdesc (equal? expres actres))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; !!! TODO:
; !!! To be implemented also:
; plan_no_plan
; plan_skip_all [REASON]
;
; is RESULT EXPECTED [NAME]
; isnt RESULT EXPECTED [NAME]
; like RESULT PATTERN [NAME]
; unlike RESULT PATTERN [NAME]
; pass [NAME]
; fail [NAME]
;
; skip CONDITION [REASON] [NB_TESTS=1]
; Specify TODO mode by setting $TODO:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End of guiletap.scm
Omer Zak