size: Avoid '_' as a pattern variable in 'match'.
[jackhill/guix/guix.git] / tests / size.scm
CommitLineData
fcc58db6 1;;; GNU Guix --- Functional package management for GNU
a371aa22 2;;; Copyright © 2015, 2016 Ludovic Courtès <ludo@gnu.org>
fcc58db6
LC
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-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)
686784d0 27 #:use-module (gnu packages)
fcc58db6
LC
28 #:use-module (gnu packages bootstrap)
29 #:use-module (ice-9 match)
30 #:use-module (srfi srfi-1)
31 #:use-module (srfi srfi-64))
32
33(define %store
34 (open-connection-for-tests))
35
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))))
40
41\f
42(test-begin "size")
43
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))))
53
54 (mbegin %store-monad
55 (built-derivations (list file2))
56 (mlet %store-monad ((profiles (store-profile
a371aa22 57 (list (derivation->output-path file2))))
686784d0
LC
58 (bash (interned-file
59 (search-bootstrap-binary
60 "bash" (%current-system)) "bash"
61 #:recursive? #t))
fcc58db6 62 (guile (package->derivation %bootstrap-guile)))
686784d0
LC
63 (define (lookup-profile item)
64 (find (matching-profile (if (derivation? item)
65 (derivation->output-path item)
66 item))
fcc58db6
LC
67 profiles))
68
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.
686784d0 77 (return (and (= (length profiles) 4)
fcc58db6
LC
78 (match* ((file1 => profile1)
79 (file2 => profile2)
686784d0
LC
80 (guile => profile3)
81 (bash => profile4)) ;dependency of GUILE
fcc58db6
LC
82 (and (> (profile-closure-size profile2) 0)
83 (= (profile-closure-size profile2)
84 (+ (profile-self-size profile1)
85 (profile-self-size profile2)
686784d0
LC
86 (profile-self-size profile3)
87 (profile-self-size profile4))))))))))))
fcc58db6
LC
88
89(test-end "size")
90
fcc58db6
LC
91;;; Local Variables:
92;;; eval: (put 'match* 'scheme-indent-function 1)
93;;; End: