Add 'guix size'.
[jackhill/guix/guix.git] / tests / size.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015 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-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 bootstrap)
28 #:use-module (ice-9 match)
29 #:use-module (srfi srfi-1)
30 #:use-module (srfi srfi-64))
31
32 (define %store
33 (open-connection-for-tests))
34
35 (define-syntax-rule (test-assertm name exp)
36 (test-assert name
37 (run-with-store %store exp
38 #:guile-for-build (%guile-for-build))))
39
40 \f
41 (test-begin "size")
42
43 (test-assertm "store-profile"
44 (mlet* %store-monad ((file1 (gexp->derivation "file1"
45 #~(symlink #$%bootstrap-guile
46 #$output)))
47 (file2 (text-file* "file2"
48 "the file => " file1)))
49 (define (matching-profile item)
50 (lambda (profile)
51 (string=? item (profile-file profile))))
52
53 (mbegin %store-monad
54 (built-derivations (list file2))
55 (mlet %store-monad ((profiles (store-profile
56 (derivation->output-path file2)))
57 (guile (package->derivation %bootstrap-guile)))
58 (define (lookup-profile drv)
59 (find (matching-profile (derivation->output-path drv))
60 profiles))
61
62 (letrec-syntax ((match* (syntax-rules (=>)
63 ((_ ((drv => profile) rest ...) body)
64 (match (lookup-profile drv)
65 ((? profile? profile)
66 (match* (rest ...) body))))
67 ((_ () body)
68 body))))
69 ;; Make sure we get all three profiles with sensible values.
70 (return (and (= (length profiles) 3)
71 (match* ((file1 => profile1)
72 (file2 => profile2)
73 (guile => profile3))
74 (and (> (profile-closure-size profile2) 0)
75 (= (profile-closure-size profile2)
76 (+ (profile-self-size profile1)
77 (profile-self-size profile2)
78 (profile-self-size profile3))))))))))))
79
80 (test-end "size")
81
82 \f
83 (exit (= (test-runner-fail-count (test-runner-current)) 0))
84
85 ;;; Local Variables:
86 ;;; eval: (put 'match* 'scheme-indent-function 1)
87 ;;; End: