diff options
| -rw-r--r-- | guix/store.scm | 5 | ||||
| -rw-r--r-- | tests/builders.scm | 13 | ||||
| -rw-r--r-- | tests/derivations.scm | 30 |
3 files changed, 32 insertions, 16 deletions
diff --git a/guix/store.scm b/guix/store.scm index 1ecb2cc359d..b5259946728 100644 --- a/guix/store.scm +++ b/guix/store.scm | |||
| @@ -42,6 +42,7 @@ | |||
| 42 | 42 | ||
| 43 | open-connection | 43 | open-connection |
| 44 | set-build-options | 44 | set-build-options |
| 45 | valid-path? | ||
| 45 | add-text-to-store | 46 | add-text-to-store |
| 46 | add-to-store | 47 | add-to-store |
| 47 | build-derivations | 48 | build-derivations |
| @@ -374,6 +375,10 @@ again until #t is returned or an error is raised." | |||
| 374 | (or done? (loop (process-stderr server)))) | 375 | (or done? (loop (process-stderr server)))) |
| 375 | (read-arg return s)))))) | 376 | (read-arg return s)))))) |
| 376 | 377 | ||
| 378 | (define-operation (valid-path? (string path)) | ||
| 379 | "Return #t when PATH is a valid store path." | ||
| 380 | boolean) | ||
| 381 | |||
| 377 | (define-operation (add-text-to-store (string name) (string text) | 382 | (define-operation (add-text-to-store (string name) (string text) |
| 378 | (string-list references)) | 383 | (string-list references)) |
| 379 | "Add TEXT under file NAME in the store." | 384 | "Add TEXT under file NAME in the store." |
diff --git a/tests/builders.scm b/tests/builders.scm index 17bae2c7548..762944ba73a 100644 --- a/tests/builders.scm +++ b/tests/builders.scm | |||
| @@ -38,9 +38,11 @@ | |||
| 38 | (let* ((url "http://ftp.gnu.org/gnu/hello/hello-2.8.tar.gz") | 38 | (let* ((url "http://ftp.gnu.org/gnu/hello/hello-2.8.tar.gz") |
| 39 | (hash (nix-base32-string->bytevector | 39 | (hash (nix-base32-string->bytevector |
| 40 | "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6")) | 40 | "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6")) |
| 41 | (drv-path (http-fetch %store url 'sha256 hash))) | 41 | (drv-path (http-fetch %store url 'sha256 hash)) |
| 42 | (out-path (derivation-path->output-path drv-path))) | ||
| 42 | (and (build-derivations %store (list drv-path)) | 43 | (and (build-derivations %store (list drv-path)) |
| 43 | (file-exists? (derivation-path->output-path drv-path))))) | 44 | (file-exists? out-path) |
| 45 | (valid-path? %store out-path)))) | ||
| 44 | 46 | ||
| 45 | (test-assert "gnu-build-system" | 47 | (test-assert "gnu-build-system" |
| 46 | (and (build-system? gnu-build-system) | 48 | (and (build-system? gnu-build-system) |
| @@ -52,10 +54,11 @@ | |||
| 52 | "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6")) | 54 | "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6")) |
| 53 | (tarball (http-fetch %store url 'sha256 hash)) | 55 | (tarball (http-fetch %store url 'sha256 hash)) |
| 54 | (build (gnu-build %store "hello-2.8" tarball | 56 | (build (gnu-build %store "hello-2.8" tarball |
| 55 | `(("gawk" ,(nixpkgs-derivation "gawk")))))) | 57 | `(("gawk" ,(nixpkgs-derivation "gawk"))))) |
| 58 | (out (derivation-path->output-path build))) | ||
| 56 | (and (build-derivations %store (list (pk 'hello-drv build))) | 59 | (and (build-derivations %store (list (pk 'hello-drv build))) |
| 57 | (file-exists? (string-append (derivation-path->output-path build) | 60 | (valid-path? %store out) |
| 58 | "/bin/hello"))))) | 61 | (file-exists? (string-append out "/bin/hello"))))) |
| 59 | 62 | ||
| 60 | (test-end "builders") | 63 | (test-end "builders") |
| 61 | 64 | ||
diff --git a/tests/derivations.scm b/tests/derivations.scm index 1e9a136d04c..3fc7097a87d 100644 --- a/tests/derivations.scm +++ b/tests/derivations.scm | |||
| @@ -71,6 +71,7 @@ | |||
| 71 | (let* ((file (search-path %load-path "language/tree-il/spec.scm")) | 71 | (let* ((file (search-path %load-path "language/tree-il/spec.scm")) |
| 72 | (drv (add-to-store %store "flat-test" #t #f "sha256" file))) | 72 | (drv (add-to-store %store "flat-test" #t #f "sha256" file))) |
| 73 | (and (eq? 'regular (stat:type (stat drv))) | 73 | (and (eq? 'regular (stat:type (stat drv))) |
| 74 | (valid-path? %store drv) | ||
| 74 | (equal? (call-with-input-file file get-bytevector-all) | 75 | (equal? (call-with-input-file file get-bytevector-all) |
| 75 | (call-with-input-file drv get-bytevector-all))))) | 76 | (call-with-input-file drv get-bytevector-all))))) |
| 76 | 77 | ||
| @@ -78,15 +79,18 @@ | |||
| 78 | (let* ((dir (dirname (search-path %load-path "language/tree-il/spec.scm"))) | 79 | (let* ((dir (dirname (search-path %load-path "language/tree-il/spec.scm"))) |
| 79 | (drv (add-to-store %store "dir-tree-test" #t #t "sha256" dir))) | 80 | (drv (add-to-store %store "dir-tree-test" #t #t "sha256" dir))) |
| 80 | (and (eq? 'directory (stat:type (stat drv))) | 81 | (and (eq? 'directory (stat:type (stat drv))) |
| 82 | (valid-path? %store drv) | ||
| 81 | (equal? (directory-contents dir) | 83 | (equal? (directory-contents dir) |
| 82 | (directory-contents drv))))) | 84 | (directory-contents drv))))) |
| 83 | 85 | ||
| 84 | (test-assert "derivation with no inputs" | 86 | (test-assert "derivation with no inputs" |
| 85 | (let ((builder (add-text-to-store %store "my-builder.sh" | 87 | (let* ((builder (add-text-to-store %store "my-builder.sh" |
| 86 | "#!/bin/sh\necho hello, world\n" | 88 | "#!/bin/sh\necho hello, world\n" |
| 87 | '()))) | 89 | '())) |
| 88 | (store-path? (derivation %store "foo" (%current-system) builder | 90 | (drv-path (derivation %store "foo" (%current-system) builder |
| 89 | '() '(("HOME" . "/homeless")) '())))) | 91 | '() '(("HOME" . "/homeless")) '()))) |
| 92 | (and (store-path? drv-path) | ||
| 93 | (valid-path? %store drv-path)))) | ||
| 90 | 94 | ||
| 91 | (test-assert "build derivation with 1 source" | 95 | (test-assert "build derivation with 1 source" |
| 92 | (let*-values (((builder) | 96 | (let*-values (((builder) |
| @@ -105,8 +109,9 @@ | |||
| 105 | (and succeeded? | 109 | (and succeeded? |
| 106 | (let ((path (derivation-output-path | 110 | (let ((path (derivation-output-path |
| 107 | (assoc-ref (derivation-outputs drv) "out")))) | 111 | (assoc-ref (derivation-outputs drv) "out")))) |
| 108 | (string=? (call-with-input-file path read-line) | 112 | (and (valid-path? %store path) |
| 109 | "hello, world"))))) | 113 | (string=? (call-with-input-file path read-line) |
| 114 | "hello, world")))))) | ||
| 110 | 115 | ||
| 111 | (test-assert "fixed-output derivation" | 116 | (test-assert "fixed-output derivation" |
| 112 | (let* ((builder (add-text-to-store %store "my-fixed-builder.sh" | 117 | (let* ((builder (add-text-to-store %store "my-fixed-builder.sh" |
| @@ -164,7 +169,8 @@ | |||
| 164 | (build-derivations %store (list drv-path)))) | 169 | (build-derivations %store (list drv-path)))) |
| 165 | (and succeeded? | 170 | (and succeeded? |
| 166 | (let ((p (derivation-path->output-path drv-path))) | 171 | (let ((p (derivation-path->output-path drv-path))) |
| 167 | (file-exists? (string-append p "/good")))))) | 172 | (and (valid-path? %store p) |
| 173 | (file-exists? (string-append p "/good"))))))) | ||
| 168 | 174 | ||
| 169 | (test-skip (if (%guile-for-build) 0 4)) | 175 | (test-skip (if (%guile-for-build) 0 4)) |
| 170 | 176 | ||
| @@ -187,12 +193,14 @@ | |||
| 187 | (mkdir %output) | 193 | (mkdir %output) |
| 188 | #f)) ; fail! | 194 | #f)) ; fail! |
| 189 | (drv-path (build-expression->derivation %store "fail" (%current-system) | 195 | (drv-path (build-expression->derivation %store "fail" (%current-system) |
| 190 | builder '()))) | 196 | builder '())) |
| 197 | (out-path (derivation-path->output-path drv-path))) | ||
| 191 | (guard (c ((nix-protocol-error? c) | 198 | (guard (c ((nix-protocol-error? c) |
| 192 | ;; Note that the output path may exist at this point, but it | 199 | ;; Note that the output path may exist at this point, but it |
| 193 | ;; is invalid. | 200 | ;; is invalid. |
| 194 | (not (not (string-match "build .* failed" | 201 | (and (string-match "build .* failed" |
| 195 | (nix-protocol-error-message c)))))) | 202 | (nix-protocol-error-message c)) |
| 203 | (not (valid-path? %store out-path))))) | ||
| 196 | (build-derivations %store (list drv-path)) | 204 | (build-derivations %store (list drv-path)) |
| 197 | #f))) | 205 | #f))) |
| 198 | 206 | ||
