Commit | Line | Data |
---|---|---|
341c6fdd LC |
1 | ;;; Guix --- Nix package management from Guile. -*- coding: utf-8 -*- |
2 | ;;; Copyright (C) 2012 Ludovic Courtès <ludo@gnu.org> | |
3 | ;;; | |
4 | ;;; This file is part of Guix. | |
5 | ;;; | |
6 | ;;; Guix is free software; you can redistribute it and/or modify it | |
7 | ;;; under the terms of the GNU General Public License as published by | |
8 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
9 | ;;; your option) any later version. | |
10 | ;;; | |
11 | ;;; Guix is distributed in the hope that it will be useful, but | |
12 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | ;;; GNU General Public License for more details. | |
15 | ;;; | |
16 | ;;; You should have received a copy of the GNU General Public License | |
17 | ;;; along with Guix. If not, see <http://www.gnu.org/licenses/>. | |
18 | ||
19 | ||
20 | (define-module (test-derivations) | |
21 | #:use-module (guix derivations) | |
26bbbb95 | 22 | #:use-module (guix store) |
de4c3f26 | 23 | #:use-module (guix utils) |
fb3eec83 | 24 | #:use-module (srfi srfi-11) |
341c6fdd LC |
25 | #:use-module (srfi srfi-26) |
26 | #:use-module (srfi srfi-64) | |
fb3eec83 | 27 | #:use-module (rnrs io ports) |
749c6567 | 28 | #:use-module (rnrs bytevectors) |
fb3eec83 | 29 | #:use-module (ice-9 rdelim)) |
341c6fdd | 30 | |
26bbbb95 LC |
31 | (define %store |
32 | (false-if-exception (open-connection))) | |
33 | ||
341c6fdd LC |
34 | (test-begin "derivations") |
35 | ||
36 | (test-assert "parse & export" | |
33594aa4 LC |
37 | (let* ((f (search-path %load-path "tests/test.drv")) |
38 | (b1 (call-with-input-file f get-bytevector-all)) | |
341c6fdd LC |
39 | (d1 (read-derivation (open-bytevector-input-port b1))) |
40 | (b2 (call-with-bytevector-output-port (cut write-derivation d1 <>))) | |
41 | (d2 (read-derivation (open-bytevector-input-port b2)))) | |
42 | (and (equal? b1 b2) | |
43 | (equal? d1 d2)))) | |
44 | ||
de4c3f26 | 45 | (test-skip (if %store 0 3)) |
26bbbb95 LC |
46 | |
47 | (test-assert "derivation with no inputs" | |
48 | (let ((builder (add-text-to-store %store "my-builder.sh" | |
49 | "#!/bin/sh\necho hello, world\n" | |
50 | '()))) | |
51 | (store-path? (derivation %store "foo" "x86_64-linux" builder | |
52 | '() '(("HOME" . "/homeless")) '())))) | |
53 | ||
fb3eec83 LC |
54 | (test-assert "build derivation with 1 source" |
55 | (let*-values (((builder) | |
56 | (add-text-to-store %store "my-builder.sh" | |
de4c3f26 | 57 | "echo hello, world > \"$out\"\n" |
fb3eec83 LC |
58 | '())) |
59 | ((drv-path drv) | |
60 | (derivation %store "foo" "x86_64-linux" | |
61 | "/bin/sh" `(,builder) | |
62 | '(("HOME" . "/homeless")) | |
63 | `((,builder)))) | |
64 | ((succeeded?) | |
65 | (build-derivations %store (list drv-path)))) | |
66 | (and succeeded? | |
67 | (let ((path (derivation-output-path | |
68 | (assoc-ref (derivation-outputs drv) "out")))) | |
69 | (string=? (call-with-input-file path read-line) | |
70 | "hello, world"))))) | |
71 | ||
749c6567 LC |
72 | (test-assert "fixed-output derivation" |
73 | (let* ((builder (add-text-to-store %store "my-fixed-builder.sh" | |
74 | "echo -n hello > $out" '())) | |
75 | (hash (sha256 (string->utf8 "hello"))) | |
76 | (drv-path (derivation %store "fixed" "x86_64-linux" | |
77 | "/bin/sh" `(,builder) | |
78 | '() `((,builder)) | |
79 | #:hash hash #:hash-algo 'sha256)) | |
80 | (succeeded? (build-derivations %store (list drv-path)))) | |
81 | (and succeeded? | |
82 | (let ((p (derivation-path->output-path drv-path))) | |
83 | (equal? (string->utf8 "hello") | |
84 | (call-with-input-file p get-bytevector-all)))))) | |
85 | ||
de4c3f26 LC |
86 | \f |
87 | (define %coreutils | |
88 | (false-if-exception (nixpkgs-derivation "coreutils"))) | |
89 | ||
90 | (test-skip (if %coreutils 0 1)) | |
91 | ||
92 | (test-assert "build derivation with coreutils" | |
93 | (let* ((builder | |
94 | (add-text-to-store %store "build-with-coreutils.sh" | |
95 | "echo $PATH ; mkdir --version ; mkdir $out ; touch $out/good" | |
96 | '())) | |
97 | (drv-path | |
98 | (derivation %store "foo" "x86_64-linux" | |
99 | "/bin/sh" `(,builder) | |
100 | `(("PATH" . | |
101 | ,(string-append | |
102 | (derivation-path->output-path %coreutils) | |
103 | "/bin"))) | |
104 | `((,builder) | |
105 | (,%coreutils)))) | |
106 | (succeeded? | |
107 | (build-derivations %store (list drv-path)))) | |
108 | (and succeeded? | |
109 | (let ((p (derivation-path->output-path drv-path))) | |
110 | (file-exists? (string-append p "/good")))))) | |
111 | ||
d9085c23 LC |
112 | (test-skip (if (%guile-for-build) 0 2)) |
113 | ||
114 | (test-assert "build-expression->derivation without inputs" | |
115 | (let* ((builder '(begin | |
116 | (mkdir %output) | |
117 | (call-with-output-file (string-append %output "/test") | |
118 | (lambda (p) | |
119 | (display '(hello guix) p))))) | |
120 | (drv-path (build-expression->derivation %store "goo" "x86_64-linux" | |
121 | builder '())) | |
122 | (succeeded? (build-derivations %store (list drv-path)))) | |
123 | (and succeeded? | |
124 | (let ((p (derivation-path->output-path drv-path))) | |
125 | (equal? '(hello guix) | |
126 | (call-with-input-file (string-append p "/test") read)))))) | |
127 | ||
128 | (test-assert "build-expression->derivation with one input" | |
129 | (let* ((builder '(call-with-output-file %output | |
130 | (lambda (p) | |
131 | (let ((cu (assoc-ref %build-inputs "cu"))) | |
132 | (close 1) | |
133 | (dup2 (port->fdes p) 1) | |
134 | (execl (string-append cu "/bin/uname") | |
135 | "uname" "-a"))))) | |
136 | (drv-path (build-expression->derivation %store "uname" "x86_64-linux" | |
137 | builder | |
138 | `(("cu" . ,%coreutils)))) | |
139 | (succeeded? (build-derivations %store (list drv-path)))) | |
140 | (and succeeded? | |
141 | (let ((p (derivation-path->output-path drv-path))) | |
142 | (string-contains (call-with-input-file p read-line) "GNU"))))) | |
143 | ||
26b969de LC |
144 | (test-skip (if (false-if-exception (getaddrinfo "ftp.gnu.org" "http")) |
145 | 0 | |
146 | 1)) | |
147 | ||
148 | (test-assert "build-expression->derivation for fixed-output derivation" | |
149 | (let* ((url "http://ftp.gnu.org/gnu/hello/hello-2.8.tar.gz") | |
150 | (builder `(begin | |
151 | (use-modules (web client) (web uri) | |
152 | (rnrs io ports)) | |
153 | (let ((bv (http-get (string->uri ,url) | |
154 | #:decode-body? #f))) | |
155 | (call-with-output-file %output | |
156 | (lambda (p) | |
157 | (put-bytevector p bv)))))) | |
158 | (drv-path (build-expression->derivation | |
159 | %store "hello-2.8.tar.gz" "x86_64-linux" builder '() | |
160 | #:hash (nix-base32-string->bytevector | |
161 | "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6") | |
162 | #:hash-algo 'sha256)) | |
163 | (succeeded? (build-derivations %store (list drv-path)))) | |
164 | (and succeeded? | |
165 | (file-exists? (derivation-path->output-path drv-path))))) | |
166 | ||
341c6fdd LC |
167 | (test-end) |
168 | ||
169 | \f | |
170 | (exit (= (test-runner-fail-count (test-runner-current)) 0)) | |
171 | ||
172 | ;;; Local Variables: | |
173 | ;;; eval: (put 'test-assert 'scheme-indent-function 1) | |
174 | ;;; End: |