guix-gc.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # GNU Guix --- Functional package management for GNU
  2. # Copyright © 2013, 2015, 2017, 2018, 2019 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 gc' command-line utility.
  20. #
  21. guix gc --version
  22. trap "rm -f guix-gc-root" EXIT
  23. rm -f guix-gc-root
  24. # Below we are using 'drv' and 'out' to contain store file names. If 'drv'
  25. # and 'out' are environment variables, 'list-runtime-roots' will "see" them
  26. # and thus prevent $drv and $out from being garbage-collected. Using 'unset'
  27. # allows us to make sure these are truly local shell variables and not
  28. # environments variables.
  29. unset drv
  30. unset out
  31. # For some operations, passing extra arguments is an error.
  32. for option in "" "-C 500M" "--verify" "--optimize" "--list-roots"
  33. do
  34. ! guix gc $option whatever
  35. done
  36. # This should fail.
  37. ! guix gc --verify=foo
  38. # Check the references of a .drv.
  39. drv="`guix build guile-bootstrap -d`"
  40. out="`guix build guile-bootstrap`"
  41. test -f "$drv" && test -d "$out"
  42. guix gc --references "$drv" | grep -e -bash
  43. guix gc --references "$out"
  44. guix gc --references "$out/bin/guile"
  45. ! guix gc --references /dev/null;
  46. # Check derivers.
  47. guix gc --derivers "$out" | grep "$drv"
  48. # Add then reclaim a .drv file.
  49. drv="`guix build idutils -d`"
  50. test -f "$drv"
  51. guix gc --list-dead | grep "$drv"
  52. guix gc --delete "$drv"
  53. ! test -f "$drv"
  54. # Add a .drv, register it as a root.
  55. drv="`guix build --root=guix-gc-root lsh -d`"
  56. test -f "$drv" && test -L guix-gc-root
  57. guix gc --list-roots | grep "$PWD/guix-gc-root"
  58. guix gc --list-live | grep "$drv"
  59. ! guix gc --delete "$drv";
  60. rm guix-gc-root
  61. guix gc --list-dead | grep "$drv"
  62. guix gc --delete "$drv"
  63. ! test -f "$drv"
  64. # Try a random collection.
  65. guix gc -C 1KiB
  66. # Check trivial error cases.
  67. ! guix gc --delete /dev/null;
  68. # Bug #19757
  69. out="`guix build guile-bootstrap`"
  70. test -d "$out"
  71. guix gc --delete "$out"
  72. ! test -d "$out"
  73. out="`guix build guile-bootstrap`"
  74. test -d "$out"
  75. guix gc --delete "$out/"
  76. ! test -d "$out"
  77. out="`guix build guile-bootstrap`"
  78. test -d "$out"
  79. guix gc --delete "$out/bin/guile"