download: Add X.org mirrors.
[jackhill/guix/guix.git] / tests / store.scm
CommitLineData
233e7676 1;;; GNU Guix --- Functional package management for GNU
0f3d2504 2;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org>
3259877d 3;;;
233e7676 4;;; This file is part of GNU Guix.
3259877d 5;;;
233e7676 6;;; GNU Guix is free software; you can redistribute it and/or modify it
3259877d
LC
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;;;
233e7676 11;;; GNU Guix is distributed in the hope that it will be useful, but
3259877d
LC
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
233e7676 17;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
3259877d
LC
18
19
20(define-module (test-store)
21 #:use-module (guix store)
22 #:use-module (guix utils)
23 #:use-module (guix base32)
0f3d2504
LC
24 #:use-module (guix packages)
25 #:use-module (guix derivations)
1ffa7090 26 #:use-module (gnu packages bootstrap)
3259877d
LC
27 #:use-module (ice-9 match)
28 #:use-module (srfi srfi-1)
29 #:use-module (srfi srfi-11)
30 #:use-module (srfi srfi-64))
31
32;; Test the (guix store) module.
33
34(define %store
35 (false-if-exception (open-connection)))
36
37(when %store
38 ;; Make sure we build everything by ourselves.
39 (set-build-options %store #:use-substitutes? #f))
40
41(define %seed
42 (seed->random-state (logxor (getpid) (car (gettimeofday)))))
43
44(define (random-text)
45 (number->string (random (expt 2 256) %seed) 16))
46
47\f
48(test-begin "store")
49
50(test-skip (if %store 0 10))
51
52(test-assert "dead-paths"
53 (let ((p (add-text-to-store %store "random-text"
54 (random-text) '())))
55 (member p (dead-paths %store))))
56
57;; FIXME: Find a test for `live-paths'.
58;;
59;; (test-assert "temporary root is in live-paths"
60;; (let* ((p1 (add-text-to-store %store "random-text"
61;; (random-text) '()))
62;; (b (add-text-to-store %store "link-builder"
63;; (format #f "echo ~a > $out" p1)
64;; '()))
65;; (d1 (derivation %store "link" (%current-system)
66;; "/bin/sh" `("-e" ,b) '()
67;; `((,b) (,p1))))
68;; (p2 (derivation-path->output-path d1)))
69;; (and (add-temp-root %store p2)
70;; (build-derivations %store (list d1))
71;; (valid-path? %store p1)
72;; (member (pk p2) (live-paths %store)))))
73
74(test-assert "dead path can be explicitly collected"
75 (let ((p (add-text-to-store %store "random-text"
76 (random-text) '())))
77 (let-values (((paths freed) (delete-paths %store (list p))))
78 (and (equal? paths (list p))
79 (> freed 0)
80 (not (file-exists? p))))))
81
0f3d2504
LC
82(test-assert "no substitutes"
83 (let* ((s (open-connection))
84 (d1 (package-derivation s %bootstrap-guile (%current-system)))
85 (d2 (package-derivation s %bootstrap-glibc (%current-system)))
86 (o (map derivation-path->output-path (list d1 d2))))
87 (set-build-options s #:use-substitutes? #f)
88 (and (not (has-substitutes? s d1))
89 (not (has-substitutes? s d2))
90 (null? (substitutable-paths s o))
91 (null? (substitutable-path-info s o)))))
92
3259877d
LC
93(test-end "store")
94
95\f
96(exit (= (test-runner-fail-count (test-runner-current)) 0))