guix-gc.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # GNU Guix --- Functional package management for GNU
  2. # Copyright © 2013, 2015, 2017, 2018 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"
  33. do
  34. if guix gc $option whatever; then false; else true; fi
  35. done
  36. # This should fail.
  37. if guix gc --verify=foo; then false; else true; fi
  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. if guix gc --references /dev/null;
  46. then false; else true; fi
  47. # Check derivers.
  48. guix gc --derivers "$out" | grep "$drv"
  49. # Add then reclaim a .drv file.
  50. drv="`guix build idutils -d`"
  51. test -f "$drv"
  52. guix gc --list-dead | grep "$drv"
  53. guix gc --delete "$drv"
  54. ! test -f "$drv"
  55. # Add a .drv, register it as a root.
  56. drv="`guix build --root=guix-gc-root lsh -d`"
  57. test -f "$drv" && test -L guix-gc-root
  58. guix gc --list-live | grep "$drv"
  59. if guix gc --delete "$drv";
  60. then false; else true; fi
  61. rm guix-gc-root
  62. guix gc --list-dead | grep "$drv"
  63. guix gc --delete "$drv"
  64. ! test -f "$drv"
  65. # Try a random collection.
  66. guix gc -C 1KiB
  67. # Check trivial error cases.
  68. if guix gc --delete /dev/null;
  69. then false; else true; fi
  70. # Bug #19757
  71. out="`guix build guile-bootstrap`"
  72. test -d "$out"
  73. guix gc --delete "$out"
  74. ! test -d "$out"
  75. out="`guix build guile-bootstrap`"
  76. test -d "$out"
  77. guix gc --delete "$out/"
  78. ! test -d "$out"
  79. out="`guix build guile-bootstrap`"
  80. test -d "$out"
  81. guix gc --delete "$out/bin/guile"