diff options
author | Ludovic Courtès <ludo@gnu.org> | 2013-05-11 15:09:56 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2013-05-11 15:09:56 +0200 |
commit | ccbce84809db80e6d9bc42e96f9edb2071152b56 (patch) | |
tree | 6736eb07bd6377e4243c37de27f7b6cf981507ad /guix/scripts/hash.scm | |
parent | 438bb042ff31619f43960113e7cd9e1b2818ff1c (diff) | |
download | gnu-guix-ccbce84809db80e6d9bc42e96f9edb2071152b56.tar gnu-guix-ccbce84809db80e6d9bc42e96f9edb2071152b56.tar.gz |
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.
Diffstat (limited to 'guix/scripts/hash.scm')
-rw-r--r-- | guix/scripts/hash.scm | 43 |
1 files changed, 24 insertions, 19 deletions
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 @@ Supported formats: 'nix-base32' (default), 'base32', and 'base16' (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~%")))))) |