From ccbce84809db80e6d9bc42e96f9edb2071152b56 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sat, 11 May 2013 15:09:56 +0200 Subject: tests: Add `guix hash' test. * guix/scripts/hash.scm (guix-hash)[eof->null]: New procedure. Use it to convert the EOF object to the empty bytevector. * tests/guix-hash.sh: New file. * Makefile.am (SH_TESTS): Add it. --- guix/scripts/hash.scm | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'guix/scripts') diff --git a/guix/scripts/hash.scm b/guix/scripts/hash.scm index deded63136..1b14aaadd0 100644 --- a/guix/scripts/hash.scm +++ b/guix/scripts/hash.scm @@ -98,23 +98,28 @@ (define (parse-options) (alist-cons 'argument arg result)) %default-options)) - (let* ((opts (parse-options)) - (args (filter-map (match-lambda - (('argument . value) - value) - (_ #f)) - (reverse opts))) - (fmt (assq-ref opts 'format))) + (define (eof->null x) + (if (eof-object? x) + #vu8() + x)) - (match args - ((file) - (catch 'system-error - (lambda () - (format #t "~a~%" - (call-with-input-file file - (compose fmt sha256 get-bytevector-all)))) - (lambda args - (leave (_ "~a~%") - (strerror (system-error-errno args)))))) - (_ - (leave (_ "wrong number of arguments~%")))))) + (let* ((opts (parse-options)) + (args (filter-map (match-lambda + (('argument . value) + value) + (_ #f)) + (reverse opts))) + (fmt (assq-ref opts 'format))) + + (match args + ((file) + (catch 'system-error + (lambda () + (format #t "~a~%" + (call-with-input-file file + (compose fmt sha256 eof->null get-bytevector-all)))) + (lambda args + (leave (_ "~a~%") + (strerror (system-error-errno args)))))) + (_ + (leave (_ "wrong number of arguments~%")))))) -- cgit v1.2.3