projects/guix·blob sysadmin-team · refs

163 lines · 5.0 KiB

1# GNU Guix --- Functional package management for GNU
2# Copyright © 2023 Ludovic Courtès <[email protected]>
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 refresh' command-line utility.
21#
22
23guix refresh --version
24
25manifest="t-guix-refresh-manifest-$$.scm"
26module_dir="t-guix-refresh-modules-$$"
27trap 'rm -f "$manifest"; rm -rf "$module_dir"' EXIT
28
29# Tell the 'test' updater what to simulate.
30export GUIX_TEST_UPDATER_TARGETS
31idutils_version="$(guix package -A ^idutils$ | cut -f2)"
32GUIX_TEST_UPDATER_TARGETS='
33 (("guile" "3" (("12.5" "file:///dev/null")
34 ("1.6.4" "file:///dev/null")
35 ("3.13.3" "file:///dev/null")))
36 ("libreoffice" "" (("1.0" "file:///dev/null")))
37 ("idutils" "" (("'$idutils_version'" "file:///dev/null")))
38 ("the-test-package" "" (("5.5" "file://'$PWD/$module_dir'/source"
39 ("grep" "sed" "libreoffice")))))'
40
41# No newer version available.
42guix refresh -t test idutils # XXX: should return non-zero?
43case "$(guix refresh -t test idutils 2>&1)" in
44 *"$idutils_version"*"already the latest version"*) true;;
45 *) false;;
46esac
47
48# No-op when updating to same version.
49case "$(guix refresh -t test -u idutils \
50--target-version=$idutils_version 2>&1)" in
51 *downgrading*) false;;
52 *updating*) false;;
53 *) true;;
54esac
55
56guix refresh -t test libreoffice # XXX: should return non-zero?
57case "$(guix refresh -t test libreoffice 2>&1)" in
58 *"greater than the latest known version"*"1.0"*) true;;
59 *) false;;
60esac
61
62# Various ways to specify packages.
63cat > "$manifest" <<EOF
64(specifications->manifest (list "[email protected]"))
65EOF
66default_IFS="$IFS"
67IFS=_
68for spec in "guile" \
69 "[email protected]" \
70 "-e_(@ (gnu packages guile) guile-3.0)" \
71 "-m_$manifest" \
72 "-r_guile" \
73 "-s_core"
74do
75 guix refresh -t test $spec
76 case "$(guix refresh -t test $spec 2>&1)" in
77 *"would be upgraded"*"12.5"*)
78 true;;
79 *)
80 false;;
81 esac
82done
83IFS="$default_IFS"
84
85# Actually updating.
86mkdir "$module_dir"
87echo hello > "$module_dir/source"
88cat > "$module_dir/sample.scm"<<EOF
89(define-module (sample)
90 #:use-module (guix packages)
91 #:use-module (guix download)
92 #:use-module (gnu packages base))
93
94(define-public my-thing
95 (package
96 (inherit hello)
97 (name "the-test-package")
98 (version "4.3")
99 (source (origin
100 (method url-fetch)
101 (uri (string-append "mirror://gnu/hello/hello-" version
102 ".tar.gz"))
103 (sha256
104 (base32
105 "086vqwk2wl8zfs47sq2xpjc9k066ilmb8z6dn0q6ymwjzlm196cd"))))
106 (inputs (list coreutils tar))
107 (properties '((updater-ignored-inputs . ("libreoffice"))))))
108EOF
109guix refresh -t test -L "$module_dir" the-test-package
110guix refresh -t test -L "$module_dir" the-test-package -u \
111 --keyring="$module_dir/keyring.kbx" # so we don't create $HOME/.config
112grep 'version "5.5"' "$module_dir/sample.scm"
113grep "$(guix hash -H sha256 -f nix-base32 "$module_dir/source")" "$module_dir/sample.scm"
114grep '(inputs (list grep sed))' "$module_dir/sample.scm"
115
116# Specifying a target version.
117guix refresh -t test guile=2.0.0 # XXX: should return non-zero?
118case "$(guix refresh -t test guile=2.0.0 2>&1)" in
119 *"failed to find"*"2.0.0"*) true;;
120 *) false;;
121esac
122
123guix refresh -t test guile --target-version=2.0.0 # XXX: should return non-zero?
124case "$(guix refresh -t test guile --target-version=2.0.0 2>&1)" in
125 *"failed to find"*"2.0.0"*) true;;
126 *) false;;
127esac
128
129guix refresh -t test guile=~2.0.0 # XXX: should return non-zero?
130case "$(guix refresh -t test guile=~2.0.0 2>&1)" in
131 *"failed to find"*"2.0.0"*) true;;
132 *) false;;
133esac
134
135# Partial target version => select the newest release prefixed by it.
136case "$(guix refresh -t test guile --target-version=3 2>&1)" in
137 *"would be upgraded"*"3.13.3"*) true;;
138 *) false;;
139esac
140
141# Partial spec version => select the newest release prefixed by it.
142case "$(guix refresh -t test guile=~3 2>&1)" in
143 *"would be upgraded"*"3.13.3"*) true;;
144 *) false;;
145esac
146
147# Conflicting --target-version and spec: spec wins
148case "$(guix refresh -t test guile=~3 2>&1)" in
149 *"would be upgraded"*"3.13.3"*) true;;
150 *) false;;
151esac
152
153for spec in "guile=1.6.4" "guile@3=1.6.4"
154do
155 guix refresh -t test "$spec"
156 case "$(guix refresh -t test "$spec" 2>&1)" in
157 *"would be downgraded"*"1.6.4"*) true;;
158 *) false;;
159 esac
160done
161
162# Listing updaters. This should work whether or not networking is available.
163guix refresh --list-updaters