guix-refresh.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. # GNU Guix --- Functional package management for GNU
  2. # Copyright © 2023 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. # Test the 'guix refresh' command-line utility.
  20. #
  21. guix refresh --version
  22. manifest="t-guix-refresh-manifest-$$.scm"
  23. module_dir="t-guix-refresh-modules-$$"
  24. trap 'rm -f "$manifest"; rm -rf "$module_dir"' EXIT
  25. # Tell the 'test' updater what to simulate.
  26. export GUIX_TEST_UPDATER_TARGETS
  27. idutils_version="$(guix package -A ^idutils$ | cut -f2)"
  28. GUIX_TEST_UPDATER_TARGETS='
  29. (("guile" "3" (("12.5" "file:///dev/null")
  30. ("1.6.4" "file:///dev/null")))
  31. ("libreoffice" "" (("1.0" "file:///dev/null")))
  32. ("idutils" "" (("'$idutils_version'" "file:///dev/null")))
  33. ("the-test-package" "" (("5.5" "file://'$PWD/$module_dir'/source"
  34. ("grep" "sed" "libreoffice")))))'
  35. # No newer version available.
  36. guix refresh -t test idutils # XXX: should return non-zero?
  37. case "$(guix refresh -t test idutils 2>&1)" in
  38. *"$idutils_version"*"already the latest version"*) true;;
  39. *) false;;
  40. esac
  41. guix refresh -t test libreoffice # XXX: should return non-zero?
  42. case "$(guix refresh -t test libreoffice 2>&1)" in
  43. *"greater than the latest known version"*"1.0"*) true;;
  44. *) false;;
  45. esac
  46. # Various ways to specify packages.
  47. cat > "$manifest" <<EOF
  48. (specifications->manifest (list "guile@3.0"))
  49. EOF
  50. default_IFS="$IFS"
  51. IFS=_
  52. for spec in "guile" \
  53. "guile@3.0" \
  54. "-e_(@ (gnu packages guile) guile-3.0)" \
  55. "-m_$manifest" \
  56. "-r_guile" \
  57. "-s_core"
  58. do
  59. guix refresh -t test $spec
  60. case "$(guix refresh -t test $spec 2>&1)" in
  61. *"would be upgraded"*"12.5"*)
  62. true;;
  63. *)
  64. false;;
  65. esac
  66. done
  67. IFS="$default_IFS"
  68. # Actually updating.
  69. mkdir "$module_dir"
  70. echo hello > "$module_dir/source"
  71. cat > "$module_dir/sample.scm"<<EOF
  72. (define-module (sample)
  73. #:use-module (guix packages)
  74. #:use-module (guix download)
  75. #:use-module (gnu packages base))
  76. (define-public my-thing
  77. (package
  78. (inherit hello)
  79. (name "the-test-package")
  80. (version "4.3")
  81. (source (origin
  82. (method url-fetch)
  83. (uri (string-append "mirror://gnu/hello/hello-" version
  84. ".tar.gz"))
  85. (sha256
  86. (base32
  87. "086vqwk2wl8zfs47sq2xpjc9k066ilmb8z6dn0q6ymwjzlm196cd"))))
  88. (inputs (list coreutils tar))
  89. (properties '((updater-ignored-inputs . ("libreoffice"))))))
  90. EOF
  91. guix refresh -t test -L "$module_dir" the-test-package
  92. guix refresh -t test -L "$module_dir" the-test-package -u \
  93. --keyring="$module_dir/keyring.kbx" # so we don't create $HOME/.config
  94. grep 'version "5.5"' "$module_dir/sample.scm"
  95. grep "$(guix hash -H sha256 -f nix-base32 "$module_dir/source")" "$module_dir/sample.scm"
  96. grep '(inputs (list grep sed))' "$module_dir/sample.scm"
  97. # Specifying a target version.
  98. guix refresh -t test guile=2.0.0 # XXX: should return non-zero?
  99. case "$(guix refresh -t test guile=2.0.0 2>&1)" in
  100. *"failed to find"*"2.0.0"*) true;;
  101. *) false;;
  102. esac
  103. for spec in "guile=1.6.4" "guile@3=1.6.4"
  104. do
  105. guix refresh -t test "$spec"
  106. case "$(guix refresh -t test "$spec" 2>&1)" in
  107. *"would be downgraded"*"1.6.4"*) true;;
  108. *) false;;
  109. esac
  110. done
  111. # Listing updaters. This should work whether or not networking is available.
  112. guix refresh --list-updaters