;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2018 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; ;;; GNU Guix is free software; you can redistribute it and/or modify it ;;; under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 3 of the License, or (at ;;; your option) any later version. ;;; ;;; GNU Guix is distributed in the hope that it will be useful, but ;;; WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with GNU Guix. If not, see . (define-module (test-glob) #:use-module (guix glob) #:use-module (srfi srfi-64)) (test-begin "glob") (define-syntax test-string->sglob (syntax-rules (=>) ((_ pattern => result rest ...) (begin (test-equal (format #f "string->sglob, ~s" pattern) result (string->sglob pattern)) (test-string->sglob rest ...))) ((_) #t))) (define-syntax test-glob-match (syntax-rules (matches and not) ((_ (pattern-string matches strings ... (and not others ...)) rest ...) (begin (test-assert (format #f "glob-match? ~s" pattern-string) (let ((pattern (string->compiled-sglob pattern-string))) (and (glob-match? pattern strings) ... (not (glob-match? pattern others)) ...))) (test-glob-match rest ...))) ((_) #t))) (test-string->sglob "foo" => "foo" "?foo*" => '(? "foo" *) "foo[1-5]" => '("foo" (range #\1 #\5)) "foo[abc]bar" => '("foo" (set #\a #\b #\c) "bar") "foo[a[b]c]bar" => '("foo" (set #\a #\[ #\b #\] #\c) "bar") "[123]x" => '((set #\1 #\2 #\3) "x") "[a-z]" => '((range #\a #\z))) (test-glob-match ("foo" matches "foo" (and not "foobar" "barfoo")) ("foo*" matches "foo" "foobar" (and not "xfoo")) ("foo??bar" matches "fooxxbar" "fooZZbar" (and not "foobar" "fooxxxbar" "fooxxbarzz")) ("foo?" matches "foox" (and not "fooxx")) ("ab[0-9]c" matches "ab0c" "ab7c" "ab9c" (and not "ab-c" "ab00c" "ab3")) ("ab[cdefg]" matches "abc" "abd" "abg" (and not "abh" "abcd" "ab["))) (test-end "glob") 3 of the License, or (at # your option) any later version. # # GNU Guix is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. # # Test the `guix gc' command-line utility. # guix gc --version trap "rm -f guix-gc-root" EXIT rm -f guix-gc-root # Below we are using 'drv' and 'out' to contain store file names. If 'drv' # and 'out' are environment variables, 'list-runtime-roots' will "see" them # and thus prevent $drv and $out from being garbage-collected. Using 'unset' # allows us to make sure these are truly local shell variables and not # environments variables. unset drv unset out # For some operations, passing extra arguments is an error. for option in "" "-C 500M" "--verify" "--optimize" "--list-roots" do guix gc $option whatever && false done # This should fail. guix gc --verify=foo && false # Check the references of a .drv. drv="`guix build guile-bootstrap -d`" out="`guix build guile-bootstrap`" test -f "$drv" && test -d "$out" guix gc --references "$drv" | grep -e -bash guix gc --references "$out" guix gc --references "$out/bin/guile" guix gc --references /dev/null && false # Check derivers. guix gc --derivers "$out" | grep "$drv" # Add then reclaim a .drv file. drv="`guix build idutils -d`" test -f "$drv" guix gc --list-dead | grep "$drv" guix gc --delete "$drv" test ! -f "$drv" # Add a .drv, register it as a root. drv="`guix build --root=guix-gc-root lsh -d`" test -f "$drv" && test -L guix-gc-root guix gc --list-roots | grep "$PWD/guix-gc-root" guix gc --list-live | grep "$drv" guix gc --delete "$drv" && false rm guix-gc-root guix gc --list-dead | grep "$drv" guix gc --delete "$drv" test ! -f "$drv" # Try a random collection. guix gc -C 1KiB # Check trivial error cases. guix gc --delete /dev/null && false # Bug #19757 out="`guix build guile-bootstrap`" test -d "$out" guix gc --delete "$out" test ! -d "$out" out="`guix build guile-bootstrap`" test -d "$out" guix gc --delete "$out/" test ! -d "$out" out="`guix build guile-bootstrap`" test -d "$out" guix gc --delete "$out/bin/guile"