tests: Test fixed-output derivations with several hash algorithms.

* tests/derivations.scm ("fixed-output derivation"): Test several hash
algorithms.
This commit is contained in:
Ludovic Courtès 2020-05-18 21:59:58 +02:00
parent 73b27eaa64
commit 9418aaa00d
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
1 changed files with 24 additions and 15 deletions

View File

@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -324,20 +324,29 @@
#:hash hash #:hash-algo 'sha256))) #:hash hash #:hash-algo 'sha256)))
(fixed-output-derivation? drv))) (fixed-output-derivation? drv)))
(test-assert "fixed-output derivation" (test-equal "fixed-output derivation"
(let* ((builder (add-text-to-store %store "my-fixed-builder.sh" '(sha1 sha256 sha512)
"echo -n hello > $out" '())) (map (lambda (hash-algorithm)
(hash (sha256 (string->utf8 "hello"))) (let* ((builder (add-text-to-store %store "my-fixed-builder.sh"
(drv (derivation %store "fixed" "echo -n hello > $out" '()))
%bash `(,builder) (sha256 (sha256 (string->utf8 "hello")))
#:sources `(,builder) ;optional (hash (bytevector-hash
#:hash hash #:hash-algo 'sha256)) (string->utf8 "hello")
(succeeded? (build-derivations %store (list drv)))) (lookup-hash-algorithm hash-algorithm)))
(and succeeded? (drv (derivation %store
(let ((p (derivation->output-path drv))) (string-append
(and (equal? (string->utf8 "hello") "fixed-" (symbol->string hash-algorithm))
(call-with-input-file p get-bytevector-all)) %bash `(,builder)
(bytevector? (query-path-hash %store p))))))) #:sources `(,builder) ;optional
#:hash hash
#:hash-algo hash-algorithm)))
(build-derivations %store (list drv))
(let ((p (derivation->output-path drv)))
(and (bytevector=? (string->utf8 "hello")
(call-with-input-file p get-bytevector-all))
(bytevector? (query-path-hash %store p))
hash-algorithm))))
'(sha1 sha256 sha512)))
(test-assert "fixed-output derivation: output paths are equal" (test-assert "fixed-output derivation: output paths are equal"
(let* ((builder1 (add-text-to-store %store "fixed-builder1.sh" (let* ((builder1 (add-text-to-store %store "fixed-builder1.sh"