distro: Change the module name space to (gnu ...).
[jackhill/guix/guix.git] / tests / guix-package.sh
1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2012, 2013 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 #
20 # Test the `guix-package' command-line utility.
21 #
22
23 guix-package --version
24
25 readlink_base ()
26 {
27 basename `readlink "$1"`
28 }
29
30 profile="t-profile-$$"
31 rm -f "$profile"
32
33 trap 'rm "$profile" "$profile-"[0-9]* ; rm -rf t-home-'"$$" EXIT
34
35 boot_guile="`guix-build -e '(@ (gnu packages bootstrap) %bootstrap-guile)'`"
36
37 guix-package --bootstrap -p "$profile" -i "$boot_guile"
38 test -L "$profile" && test -L "$profile-1-link"
39 test -f "$profile/bin/guile"
40
41 # Installing the same package a second time does nothing.
42 guix-package --bootstrap -p "$profile" -i "$boot_guile"
43 test -L "$profile" && test -L "$profile-1-link"
44 ! test -f "$profile-2-link"
45 test -f "$profile/bin/guile"
46
47 # Check whether we have network access.
48 if guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null
49 then
50 boot_make="`guix-build -e '(@@ (gnu packages base) gnu-make-boot0)'`"
51 guix-package --bootstrap -p "$profile" -i "$boot_make"
52 test -L "$profile-2-link"
53 test -f "$profile/bin/make" && test -f "$profile/bin/guile"
54
55
56 # Check whether `--list-installed' works.
57 # XXX: Change the tests when `--install' properly extracts the package
58 # name and version string.
59 installed="`guix-package -p "$profile" --list-installed | cut -f1 | xargs echo | sort`"
60 case "x$installed" in
61 "guile-bootstrap make-boot0")
62 true;;
63 "make-boot0 guile-bootstrap")
64 true;;
65 "*")
66 false;;
67 esac
68
69 test "`guix-package -p "$profile" -I 'g.*e' | cut -f1`" = "guile-bootstrap"
70
71 # Remove a package.
72 guix-package --bootstrap -p "$profile" -r "guile-bootstrap"
73 test -L "$profile-3-link"
74 test -f "$profile/bin/make" && ! test -f "$profile/bin/guile"
75
76 # Roll back.
77 guix-package --roll-back -p "$profile"
78 test "`readlink_base "$profile"`" = "$profile-2-link"
79 test -x "$profile/bin/guile" && test -x "$profile/bin/make"
80 guix-package --roll-back -p "$profile"
81 test "`readlink_base "$profile"`" = "$profile-1-link"
82 test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
83
84 # Failed attempt to roll back because there's no previous generation.
85 if guix-package --roll-back -p "$profile";
86 then false; else true; fi
87
88 # Reinstall after roll-back to generation 1.
89 guix-package --bootstrap -p "$profile" -i "$boot_make"
90 test "`readlink_base "$profile"`" = "$profile-4-link"
91 test -x "$profile/bin/guile" && test -x "$profile/bin/make"
92
93 # Roll-back to generation 3[*], and install---all at once.
94 # [*] FIXME: Eventually, this should roll-back to generation 1.
95 guix-package --bootstrap -p "$profile" --roll-back -i "$boot_guile"
96 test "`readlink_base "$profile"`" = "$profile-5-link"
97 test -x "$profile/bin/guile" && test -x "$profile/bin/make"
98
99 # Make a "hole" in the list of generations, and make sure we can
100 # roll back "over" it.
101 rm "$profile-4-link"
102 guix-package --bootstrap -p "$profile" --roll-back
103 test "`readlink_base "$profile"`" = "$profile-3-link"
104 fi
105
106 # Make sure the `:' syntax works.
107 guix-package --bootstrap -i "binutils:lib" -p "$profile" -n
108
109 # Check whether `--list-available' returns something sensible.
110 guix-package -A 'gui.*e' | grep guile
111
112 # Try with the default profile.
113
114 XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
115 export XDG_CACHE_HOME
116 HOME="t-home-$$"
117 export HOME
118
119 mkdir -p "$HOME"
120
121 guix-package --bootstrap -i "$boot_guile"
122 test -L "$HOME/.guix-profile"
123 test -f "$HOME/.guix-profile/bin/guile"
124
125 # Failed attempt to roll back.
126 if guix-package --bootstrap --roll-back;
127 then false; else true; fi