summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/derivations.scm52
-rw-r--r--tests/guix-home.sh12
-rw-r--r--tests/read-print.scm7
3 files changed, 68 insertions, 3 deletions
diff --git a/tests/derivations.scm b/tests/derivations.scm
index 3912fd31d8..66c777cfe7 100644
--- a/tests/derivations.scm
+++ b/tests/derivations.scm
@@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2012-2022 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2012-2023 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -256,6 +256,21 @@
(build-derivations %store (list drv))
#f)))
+(test-assert "'download' built-in builder, no fixed-output hash"
+ ;; 'guix perform-download' should bail out with a message saying "not a
+ ;; fixed-output derivation".
+ (with-http-server '((200 "This should not be downloaded."))
+ (let* ((drv (derivation %store "download-without-hash"
+ "builtin:download" '()
+ #:env-vars `(("url"
+ . ,(object->string (%local-url))))
+ #:hash-algo 'sha256
+ #:hash #f)))
+ (guard (c ((store-protocol-error? c)
+ (string-contains (store-protocol-error-message c) "failed")))
+ (build-derivations %store (list drv))
+ #f))))
+
(test-assert "'download' built-in builder, check mode"
;; Make sure rebuilding the 'builtin:download' derivation in check mode
;; works. See <http://bugs.gnu.org/25089>.
@@ -316,6 +331,13 @@
#:hash hash #:hash-algo 'sha256)))
(fixed-output-derivation? drv)))
+(test-assert "fixed-output-derivation?, no hash"
+ ;; A derivation that has #:hash-algo and #:hash #f is *not* fixed-output.
+ (let* ((drv (derivation %store "not-quite-fixed"
+ "builtin:download" '()
+ #:hash #f #:hash-algo 'sha256)))
+ (not (fixed-output-derivation? drv))))
+
(test-equal "fixed-output derivation"
'(sha1 sha256 sha512)
(map (lambda (hash-algorithm)
@@ -374,6 +396,18 @@
(call-with-input-file p get-bytevector-all))
(bytevector? (query-path-hash %store p)))))))
+(test-assert "fixed-output derivation, invalid hash size"
+ (guard (c ((store-protocol-error? c)
+ (string-contains-ci (store-protocol-error-message c)
+ "invalid SHA512 hash")))
+ (derivation %store "download-with-invalid-hash"
+ "builtin:download" '()
+ #:env-vars `(("url"
+ . ,(object->string "http://example.org")))
+ #:hash-algo 'sha512
+ #:hash #vu8(1 2 3))
+ #f))
+
(test-assert "derivation with a fixed-output input"
;; A derivation D using a fixed-output derivation F doesn't has the same
;; output path when passed F or F', as long as F and F' have the same output
@@ -543,6 +577,22 @@
read-derivation)))
(equal? drv* drv)))
+(test-assert "read-derivation with hash = #f"
+ ;; Passing #:hash-algo together with #:hash #f is accepted and #:hash-algo
+ ;; is preserved. However it is not a fixed-output derivation. It used to
+ ;; be that 'read-derivation' would incorrectly return #vu8() instead of #f
+ ;; for the hash in this case:
+ ;; <https://lists.gnu.org/archive/html/guix-devel/2023-01/msg00040.html>.
+ (let* ((drv1 (derivation %store "almost-fixed-output"
+ "builtin:download" '()
+ #:env-vars `(("url" . "http://example.org"))
+ #:hash-algo 'sha256
+ #:hash #f))
+ (drv2 (call-with-input-file (derivation-file-name drv1)
+ read-derivation)))
+ (and (not (eq? drv1 drv2)) ;ensure memoization doesn't kick in
+ (equal? drv1 drv2))))
+
(test-assert "multiple-output derivation, derivation-path->output-path"
(let* ((builder (add-text-to-store %store "builder.sh"
"echo one > $out ; echo two > $second"
diff --git a/tests/guix-home.sh b/tests/guix-home.sh
index 423ebf6f33..3151f66683 100644
--- a/tests/guix-home.sh
+++ b/tests/guix-home.sh
@@ -1,5 +1,5 @@
# GNU Guix --- Functional package management for GNU
-# Copyright © 2021 Andrew Tropin <andrew@trop.in>
+# Copyright © 2021-2023 Andrew Tropin <andrew@trop.in>
# Copyright © 2021 Oleg Pykhalov <go.wigust@gmail.com>
# Copyright © 2022 Ludovic Courtès <ludo@gnu.org>
#
@@ -62,6 +62,7 @@ trap 'chmod -Rf +w "$test_directory"; rm -rf "$test_directory"' EXIT
(gnu home)
(gnu home services)
(gnu home services shells)
+ (gnu packages bash)
(gnu services))
(home-environment
@@ -82,6 +83,10 @@ trap 'chmod -Rf +w "$test_directory"; rm -rf "$test_directory"' EXIT
(simple-service 'add-environment-variable
home-environment-variables-service-type
`(("TODAY" . "26 messidor")
+ ("SHELL" . ,(file-append bash "/bin/bash"))
+ ("BUILDHOST_TIME" . ,#~(strftime "%c"
+ (localtime (current-time))))
+ ("STRING_WITH_ESCAPES" . "chars: \" /\\")
("LITERAL" . ,(literal-string "${abc}"))))
(simple-service 'home-bash-service-extension-test
@@ -149,8 +154,13 @@ EOF
# the content of bashrc-test-config.sh"
grep -q "the content of ~/.config/test.conf" "${HOME}/.config/test.conf"
grep '^export PS1="\$GUIX_ENVIRONMENT λ "$' "${HOME}/.bash_profile"
+
( . "${HOME}/.guix-home/setup-environment"; test "$TODAY" = "26 messidor" )
( . "${HOME}/.guix-home/setup-environment"; test "$LITERAL" = '${abc}' )
+ ( . "${HOME}/.guix-home/setup-environment";
+ test "$STRING_WITH_ESCAPES" = "chars: \" /\\")
+ ( . "${HOME}/.guix-home/setup-environment";
+ echo "$SHELL" | grep "/gnu/store/.*/bin/bash" )
# This one should still be here.
grep "stay around" "$HOME/.config/random-file"
diff --git a/tests/read-print.scm b/tests/read-print.scm
index ea52a52145..79a4101be6 100644
--- a/tests/read-print.scm
+++ b/tests/read-print.scm
@@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2021-2022 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2021-2023 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -143,6 +143,11 @@ expressions."
#:max-width 11)
(test-pretty-print "\
+(begin
+ 1+ 1- 123/ 456*
+ (1+ 41))")
+
+(test-pretty-print "\
(lambda (x y)
;; This is a procedure.
(let ((z (+ x y)))