1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-06-10 23:49:50 +02:00

gpgscm: Improve test framework.

* tests/gpgscm/lib.scm (echo): Move...
* tests/gpgscm/tests.scm (echo): ... here.
(info, error, skip): And use echo here.
(file-exists?): New function.
(tr:spawn): Check that source exists and if the sink has been created.
(tr:call-with-content): Hand in optional arguments.

Signed-off-by: Justus Winter <justus@g10code.com>
This commit is contained in:
Justus Winter 2016-06-21 12:21:10 +02:00
parent 5fbbc4b334
commit 65081c31e7
2 changed files with 19 additions and 13 deletions

View File

@ -120,10 +120,6 @@
(assert (string-contains? "Hallo" "llo")) (assert (string-contains? "Hallo" "llo"))
(assert (not (string-contains? "Hallo" "olla"))) (assert (not (string-contains? "Hallo" "olla")))
(define (echo . msg)
(for-each (lambda (x) (display x) (display " ")) msg)
(newline))
;; Read a word from port P. ;; Read a word from port P.
(define (read-word . p) (define (read-word . p)
(list->string (list->string

View File

@ -30,17 +30,20 @@
(get-output-string p))) (get-output-string p)))
;; Reporting. ;; Reporting.
(define (info msg) (define (echo . msg)
(display msg) (for-each (lambda (x) (display x) (display " ")) msg)
(newline) (newline))
(define (info . msg)
(apply echo msg)
(flush-stdio)) (flush-stdio))
(define (error msg) (define (error . msg)
(info msg) (apply info msg)
(exit 1)) (exit 1))
(define (skip msg) (define (skip . msg)
(info msg) (apply info msg)
(exit 77)) (exit 77))
(define (make-counter) (define (make-counter)
@ -136,6 +139,9 @@
;; ;;
;; File management. ;; File management.
;; ;;
(define (file-exists? name)
(call-with-input-file name (lambda (port) #t)))
(define (file=? a b) (define (file=? a b)
(file-equal a b #t)) (file-equal a b #t))
@ -361,6 +367,8 @@
(define (tr:spawn input command) (define (tr:spawn input command)
(lambda (tmpfiles source) (lambda (tmpfiles source)
(if (and (member '**in** command) (not source))
(error (string-append (stringify cmd) " needs an input")))
(let* ((t (make-temporary-file)) (let* ((t (make-temporary-file))
(cmd (map (lambda (x) (cmd (map (lambda (x)
(cond (cond
@ -368,6 +376,8 @@
((equal? '**out** x) t) ((equal? '**out** x) t)
(else x))) command))) (else x))) command)))
(call-popen cmd input) (call-popen cmd input)
(if (and (member '**out** command) (not (file-exists? t)))
(error (string-append (stringify cmd) " did not produce '" t "'.")))
(list (cons t tmpfiles) t)))) (list (cons t tmpfiles) t))))
(define (tr:write-to pathname) (define (tr:write-to pathname)
@ -396,7 +406,7 @@
(error "mismatch")) (error "mismatch"))
(list tmpfiles source))) (list tmpfiles source)))
(define (tr:call-with-content function) (define (tr:call-with-content function . args)
(lambda (tmpfiles source) (lambda (tmpfiles source)
(function (call-with-input-file source read-all)) (apply function `(,(call-with-input-file source read-all) ,@args))
(list tmpfiles source))) (list tmpfiles source)))