pack: Add unit test.
[jackhill/guix/guix.git] / tests / pack.scm
CommitLineData
850edd77
LC
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2017 Ludovic Courtès <ludo@gnu.org>
3;;;
4;;; This file is part of GNU Guix.
5;;;
6;;; GNU 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;;; GNU 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 GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19(define-module (test-pack)
20 #:use-module (guix scripts pack)
21 #:use-module (guix store)
22 #:use-module (guix derivations)
23 #:use-module (guix profiles)
24 #:use-module (guix monads)
25 #:use-module (guix grafts)
26 #:use-module (guix tests)
27 #:use-module (guix gexp)
28 #:use-module (gnu packages bootstrap)
29 #:use-module (srfi srfi-64))
30
31(define %store
32 (open-connection-for-tests))
33
34;; Globally disable grafts because they can trigger early builds.
35(%graft? #f)
36
37(define-syntax-rule (test-assertm name exp)
38 (test-assert name
39 (run-with-store %store exp
40 #:guile-for-build (%guile-for-build))))
41
42(define %gzip-compressor
43 ;; Compressor that uses the bootstrap 'gzip'.
44 ((@ (guix scripts pack) compressor) "gzip"
45 %bootstrap-coreutils&co "gz" '("gzip" "-6n")))
46
47(define %tar-bootstrap %bootstrap-coreutils&co)
48
49\f
50(test-begin "pack")
51
52(test-assertm "self-contained-tarball"
53 (mlet* %store-monad
54 ((profile (profile-derivation (packages->manifest
55 (list %bootstrap-guile))
56 #:hooks '()
57 #:locales? #f))
58 (tarball (self-contained-tarball "pack" profile
59 #:symlinks '(("/bin/Guile"
60 -> "bin/guile"))
61 #:compressor %gzip-compressor
62 #:tar %tar-bootstrap))
63 (check (gexp->derivation
64 "check-tarball"
65 #~(let ((guile (string-append "." #$profile "/bin")))
66 (setenv "PATH"
67 (string-append #$%tar-bootstrap "/bin"))
68 (system* "tar" "xvf" #$tarball)
69 (mkdir #$output)
70 (exit
71 (and (file-exists? (string-append guile "/guile"))
72 (string=? (string-append #$%bootstrap-guile "/bin")
73 (readlink guile))
74 (string=? (string-append (string-drop guile 1)
75 "/guile")
76 (readlink "bin/Guile"))))))))
77 (built-derivations (list check))))
78
79(test-end)