mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-12-24 21:38:07 -05:00
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.
This commit is contained in:
parent
438bb042ff
commit
ccbce84809
3 changed files with 53 additions and 19 deletions
|
@ -324,6 +324,7 @@ SH_TESTS = \
|
||||||
tests/guix-build.sh \
|
tests/guix-build.sh \
|
||||||
tests/guix-download.sh \
|
tests/guix-download.sh \
|
||||||
tests/guix-gc.sh \
|
tests/guix-gc.sh \
|
||||||
|
tests/guix-hash.sh \
|
||||||
tests/guix-package.sh
|
tests/guix-package.sh
|
||||||
|
|
||||||
TESTS = $(SCM_TESTS) $(SH_TESTS)
|
TESTS = $(SCM_TESTS) $(SH_TESTS)
|
||||||
|
|
|
@ -98,23 +98,28 @@ (define (parse-options)
|
||||||
(alist-cons 'argument arg result))
|
(alist-cons 'argument arg result))
|
||||||
%default-options))
|
%default-options))
|
||||||
|
|
||||||
(let* ((opts (parse-options))
|
(define (eof->null x)
|
||||||
(args (filter-map (match-lambda
|
(if (eof-object? x)
|
||||||
(('argument . value)
|
#vu8()
|
||||||
value)
|
x))
|
||||||
(_ #f))
|
|
||||||
(reverse opts)))
|
|
||||||
(fmt (assq-ref opts 'format)))
|
|
||||||
|
|
||||||
(match args
|
(let* ((opts (parse-options))
|
||||||
((file)
|
(args (filter-map (match-lambda
|
||||||
(catch 'system-error
|
(('argument . value)
|
||||||
(lambda ()
|
value)
|
||||||
(format #t "~a~%"
|
(_ #f))
|
||||||
(call-with-input-file file
|
(reverse opts)))
|
||||||
(compose fmt sha256 get-bytevector-all))))
|
(fmt (assq-ref opts 'format)))
|
||||||
(lambda args
|
|
||||||
(leave (_ "~a~%")
|
(match args
|
||||||
(strerror (system-error-errno args))))))
|
((file)
|
||||||
(_
|
(catch 'system-error
|
||||||
(leave (_ "wrong number of arguments~%"))))))
|
(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~%"))))))
|
||||||
|
|
28
tests/guix-hash.sh
Normal file
28
tests/guix-hash.sh
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
# GNU Guix --- Functional package management for GNU
|
||||||
|
# Copyright © 2013 Ludovic Courtès <ludo@gnu.org>
|
||||||
|
#
|
||||||
|
# This file is part of GNU Guix.
|
||||||
|
#
|
||||||
|
# GNU Guix is free software; you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
# your option) any later version.
|
||||||
|
#
|
||||||
|
# GNU Guix is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#
|
||||||
|
# Test the `guix hash' command-line utility.
|
||||||
|
#
|
||||||
|
|
||||||
|
guix hash --version
|
||||||
|
|
||||||
|
test `guix hash /dev/null` = 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73
|
||||||
|
test `guix hash -f nix-base32 /dev/null` = 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73
|
||||||
|
test `guix hash -f hex /dev/null` = e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||||
|
test `guix hash -f base32 /dev/null` = 4oymiquy7qobjgx36tejs35zeqt24qpemsnzgtfeswmrw6csxbkq
|
Loading…
Reference in a new issue