guix-package: Reduce start-up time for queries.
[jackhill/guix/guix.git] / tests / guix-package.sh
CommitLineData
233e7676 1# GNU Guix --- Functional package management for GNU
cc57f25d 2# Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org>
acc08466 3# Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
0afdc485 4#
233e7676 5# This file is part of GNU Guix.
0afdc485 6#
233e7676 7# GNU Guix is free software; you can redistribute it and/or modify it
0afdc485
LC
8# under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 3 of the License, or (at
10# your option) any later version.
11#
233e7676 12# GNU Guix is distributed in the hope that it will be useful, but
0afdc485
LC
13# WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
233e7676 18# along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
0afdc485
LC
19
20#
21# Test the `guix-package' command-line utility.
22#
23
24guix-package --version
25
24e262f0
LC
26readlink_base ()
27{
28 basename `readlink "$1"`
29}
30
0afdc485
LC
31profile="t-profile-$$"
32rm -f "$profile"
33
0ec1af59 34trap 'rm "$profile" "$profile-"[0-9]* ; rm -rf t-home-'"$$" EXIT
7a6548cb 35
1ffa7090 36boot_guile="`guix-build -e '(@ (gnu packages bootstrap) %bootstrap-guile)'`"
0ec1af59
LC
37
38guix-package --bootstrap -p "$profile" -i "$boot_guile"
0afdc485
LC
39test -L "$profile" && test -L "$profile-1-link"
40test -f "$profile/bin/guile"
41
1c67d639 42# Installing the same package a second time does nothing.
24e262f0 43guix-package --bootstrap -p "$profile" -i "$boot_guile"
1c67d639
LC
44test -L "$profile" && test -L "$profile-1-link"
45! test -f "$profile-2-link"
46test -f "$profile/bin/guile"
0afdc485 47
ad1ebab3
LC
48# Check whether we have network access.
49if guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null
50then
1ffa7090 51 boot_make="`guix-build -e '(@@ (gnu packages base) gnu-make-boot0)'`"
24e262f0 52 guix-package --bootstrap -p "$profile" -i "$boot_make"
ad1ebab3
LC
53 test -L "$profile-2-link"
54 test -f "$profile/bin/make" && test -f "$profile/bin/guile"
0afdc485 55
733b4130 56
ad1ebab3
LC
57 # Check whether `--list-installed' works.
58 # XXX: Change the tests when `--install' properly extracts the package
59 # name and version string.
60 installed="`guix-package -p "$profile" --list-installed | cut -f1 | xargs echo | sort`"
61 case "x$installed" in
62 "guile-bootstrap make-boot0")
63 true;;
64 "make-boot0 guile-bootstrap")
65 true;;
66 "*")
67 false;;
68 esac
733b4130 69
ad1ebab3 70 test "`guix-package -p "$profile" -I 'g.*e' | cut -f1`" = "guile-bootstrap"
733b4130 71
acc08466
NK
72 # Search.
73 test "`guix-package -s "GNU Hello" | cut -f1`" = "hello"
74 test "`guix-package -s "n0t4r341p4ck4g3"`" = ""
75
ad1ebab3 76 # Remove a package.
cc57f25d 77 guix-package --bootstrap -p "$profile" -r "guile-bootstrap"
ad1ebab3
LC
78 test -L "$profile-3-link"
79 test -f "$profile/bin/make" && ! test -f "$profile/bin/guile"
24e262f0
LC
80
81 # Roll back.
82 guix-package --roll-back -p "$profile"
83 test "`readlink_base "$profile"`" = "$profile-2-link"
84 test -x "$profile/bin/guile" && test -x "$profile/bin/make"
85 guix-package --roll-back -p "$profile"
86 test "`readlink_base "$profile"`" = "$profile-1-link"
87 test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
88
d9307267
LC
89 # Move to the empty profile.
90 for i in `seq 1 3`
91 do
92 guix-package --bootstrap --roll-back -p "$profile"
93 ! test -f "$profile/bin"
94 ! test -f "$profile/lib"
95 test "`readlink_base "$profile"`" = "$profile-0-link"
96 done
24e262f0 97
82fe08ed 98 # Reinstall after roll-back to the empty profile.
24e262f0 99 guix-package --bootstrap -p "$profile" -i "$boot_make"
82fe08ed
LC
100 test "`readlink_base "$profile"`" = "$profile-1-link"
101 test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
24e262f0 102
82fe08ed 103 # Roll-back to generation 0, and install---all at once.
24e262f0 104 guix-package --bootstrap -p "$profile" --roll-back -i "$boot_guile"
82fe08ed
LC
105 test "`readlink_base "$profile"`" = "$profile-1-link"
106 test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
107
108 # Install Make.
109 guix-package --bootstrap -p "$profile" -i "$boot_make"
110 test "`readlink_base "$profile"`" = "$profile-2-link"
24e262f0 111 test -x "$profile/bin/guile" && test -x "$profile/bin/make"
9241172c
LC
112
113 # Make a "hole" in the list of generations, and make sure we can
114 # roll back "over" it.
82fe08ed 115 rm "$profile-1-link"
9241172c 116 guix-package --bootstrap -p "$profile" --roll-back
82fe08ed 117 test "`readlink_base "$profile"`" = "$profile-0-link"
ad1ebab3 118fi
0afdc485 119
9518856b 120# Make sure the `:' syntax works.
2a5ab9dc 121guix-package --bootstrap -i "binutils:lib" -p "$profile" -n
9518856b 122
64fc89b6
LC
123# Check whether `--list-available' returns something sensible.
124guix-package -A 'gui.*e' | grep guile
125
67668155 126#
0ec1af59 127# Try with the default profile.
67668155 128#
0ec1af59
LC
129
130XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
131export XDG_CACHE_HOME
132HOME="t-home-$$"
133export HOME
134
135mkdir -p "$HOME"
136
137guix-package --bootstrap -i "$boot_guile"
138test -L "$HOME/.guix-profile"
139test -f "$HOME/.guix-profile/bin/guile"
24e262f0 140
67668155
LC
141if guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null
142then
143 guix-package --bootstrap -i "$boot_make"
144 test -f "$HOME/.guix-profile/bin/make"
145 first_environment="`cd $HOME/.guix-profile ; pwd`"
146
147 guix-package --bootstrap --roll-back
148 test -f "$HOME/.guix-profile/bin/guile"
149 ! test -f "$HOME/.guix-profile/bin/make"
150 test "`cd $HOME/.guix-profile ; pwd`" = "$first_environment"
151fi
152
d9307267
LC
153# Move to the empty profile.
154default_profile="`readlink "$HOME/.guix-profile"`"
155for i in `seq 1 3`
156do
157 guix-package --bootstrap --roll-back
158 ! test -f "$HOME/.guix-profile/bin"
159 ! test -f "$HOME/.guix-profile/lib"
160 test "`readlink "$default_profile"`" = "$default_profile-0-link"
161done
3b9c0020
LC
162
163# Extraneous argument.
164! guix-package install foo-bar