store: Add GC-related operations.
[jackhill/guix/guix.git] / tests / store.scm
CommitLineData
3259877d
LC
1;;; Guix --- Nix package management from Guile. -*- coding: utf-8 -*-
2;;; Copyright (C) 2012 Ludovic Courtès <ludo@gnu.org>
3;;;
4;;; This file is part of Guix.
5;;;
6;;; 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;;; 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 Guix. If not, see <http://www.gnu.org/licenses/>.
18
19
20(define-module (test-store)
21 #:use-module (guix store)
22 #:use-module (guix utils)
23 #:use-module (guix base32)
24 #:use-module (distro packages bootstrap)
25 #:use-module (ice-9 match)
26 #:use-module (srfi srfi-1)
27 #:use-module (srfi srfi-11)
28 #:use-module (srfi srfi-64))
29
30;; Test the (guix store) module.
31
32(define %store
33 (false-if-exception (open-connection)))
34
35(when %store
36 ;; Make sure we build everything by ourselves.
37 (set-build-options %store #:use-substitutes? #f))
38
39(define %seed
40 (seed->random-state (logxor (getpid) (car (gettimeofday)))))
41
42(define (random-text)
43 (number->string (random (expt 2 256) %seed) 16))
44
45\f
46(test-begin "store")
47
48(test-skip (if %store 0 10))
49
50(test-assert "dead-paths"
51 (let ((p (add-text-to-store %store "random-text"
52 (random-text) '())))
53 (member p (dead-paths %store))))
54
55;; FIXME: Find a test for `live-paths'.
56;;
57;; (test-assert "temporary root is in live-paths"
58;; (let* ((p1 (add-text-to-store %store "random-text"
59;; (random-text) '()))
60;; (b (add-text-to-store %store "link-builder"
61;; (format #f "echo ~a > $out" p1)
62;; '()))
63;; (d1 (derivation %store "link" (%current-system)
64;; "/bin/sh" `("-e" ,b) '()
65;; `((,b) (,p1))))
66;; (p2 (derivation-path->output-path d1)))
67;; (and (add-temp-root %store p2)
68;; (build-derivations %store (list d1))
69;; (valid-path? %store p1)
70;; (member (pk p2) (live-paths %store)))))
71
72(test-assert "dead path can be explicitly collected"
73 (let ((p (add-text-to-store %store "random-text"
74 (random-text) '())))
75 (let-values (((paths freed) (delete-paths %store (list p))))
76 (and (equal? paths (list p))
77 (> freed 0)
78 (not (file-exists? p))))))
79
80(test-end "store")
81
82\f
83(exit (= (test-runner-fail-count (test-runner-current)) 0))
84
85;;; Local Variables:
86;;; eval: (put 'test-assert 'scheme-indent-function 1)
87;;; End: