doc: Mention 'sync' after 'dd'.
[guix.git] / tests / size.scm
blob575b1abfdd69b084acaaf9560296f0eceb63c3da
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015, 2016, 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/>.
19 (define-module (test-size)
20   #:use-module (guix store)
21   #:use-module (guix monads)
22   #:use-module (guix packages)
23   #:use-module (guix derivations)
24   #:use-module (guix gexp)
25   #:use-module (guix tests)
26   #:use-module (guix scripts size)
27   #:use-module (gnu packages)
28   #:use-module (gnu packages bootstrap)
29   #:use-module (ice-9 match)
30   #:use-module (srfi srfi-1)
31   #:use-module (srfi srfi-64))
33 (define %store
34   (open-connection-for-tests))
36 (define-syntax-rule (test-assertm name exp)
37   (test-assert name
38     (run-with-store %store exp
39                     #:guile-for-build (%guile-for-build))))
42 (test-begin "size")
44 (test-assertm "store-profile"
45   (mlet* %store-monad ((file1 (gexp->derivation "file1"
46                                                 #~(symlink #$%bootstrap-guile
47                                                            #$output)))
48                        (file2 (text-file* "file2"
49                                           "the file => " file1)))
50     (define (matching-profile item)
51       (lambda (profile)
52         (string=? item (profile-file profile))))
54     (mbegin %store-monad
55       (built-derivations (list file2))
56       (mlet %store-monad ((profiles (store-profile
57                                      (list (derivation->output-path file2))))
58                           (bash     (interned-file
59                                      (search-bootstrap-binary
60                                       "bash" (%current-system)) "bash"
61                                       #:recursive? #t))
62                           (guile    (package->derivation %bootstrap-guile)))
63         (define (lookup-profile item)
64           (find (matching-profile (if (derivation? item)
65                                       (derivation->output-path item)
66                                       item))
67                 profiles))
69         (letrec-syntax ((match* (syntax-rules (=>)
70                                   ((_ ((drv => profile) rest ...) body)
71                                    (match (lookup-profile drv)
72                                      ((? profile? profile)
73                                       (match* (rest ...) body))))
74                                   ((_ () body)
75                                    body))))
76           ;; Make sure we get all three profiles with sensible values.
77           (return (and (= (length profiles) 4)
78                        (match* ((file1 => profile1)
79                                 (file2 => profile2)
80                                 (guile => profile3)
81                                 (bash  => profile4)) ;dependency of GUILE
82                          (and (> (profile-closure-size profile2) 0)
83                               (= (profile-closure-size profile2)
84                                  (+ (profile-self-size profile1)
85                                     (profile-self-size profile2)
86                                     (profile-self-size profile3)
87                                     (profile-self-size profile4))))))))))))
89 (test-assertm "store-profile with multiple items"
90   (mlet* %store-monad ((file1 (gexp->derivation "file1"
91                                                 #~(symlink #$%bootstrap-guile
92                                                            #$output)))
93                        (file2 (text-file* "file2"
94                                           "the file => " file1)))
95     (mbegin %store-monad
96       (built-derivations (list file2))
97       (mlet %store-monad ((profiles  (store-profile
98                                       (list (derivation->output-path file2)
99                                             (derivation->output-path file1))))
100                           (reference (store-profile
101                                       (list (derivation->output-path file2)))))
102         (return (and (= (length profiles) 4)
103                      (lset= equal? profiles reference)))))))
105 (test-end "size")
107 ;;; Local Variables:
108 ;;; eval: (put 'match* 'scheme-indent-function 1)
109 ;;; End: