How to build unit tests in Guile that output to the TAP standard?

I would like to have a Guile script that implements functions that output test result messages in accordance with the TAP protocol.

+3
source share
2 answers

The following script, which will be called guiletap.scm, implements the often required 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
+2
source

There is also ggspec , the Guile unit testing framework, which can output the results in a (subset) of the TAP format. To do this, place all the test scripts (Scheme) in a subdirectory of the project with the name specand run:

$ ggspec -f tap

ggspec - , , . . , (spec/lib-spec.scm) .

: ggspec.

+2

Source: https://habr.com/ru/post/1696955/


All Articles