guix-hash.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # GNU Guix --- Functional package management for GNU
  2. # Copyright © 2013, 2014, 2016 Ludovic Courtès <ludo@gnu.org>
  3. # Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
  4. #
  5. # This file is part of GNU Guix.
  6. #
  7. # GNU Guix is free software; you can redistribute it and/or modify it
  8. # under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 3 of the License, or (at
  10. # your option) any later version.
  11. #
  12. # GNU Guix is distributed in the hope that it will be useful, but
  13. # WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. # Test the `guix hash' command-line utility.
  21. #
  22. guix hash --version
  23. tmpdir="guix-hash-$$"
  24. trap 'rm -rf "$tmpdir"' EXIT
  25. test `guix hash /dev/null` = 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73
  26. test `echo -n | guix hash -` = 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73
  27. test `guix hash -f nix-base32 /dev/null` = 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73
  28. test `guix hash -f hex /dev/null` = e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
  29. test `guix hash -f base32 /dev/null` = 4oymiquy7qobjgx36tejs35zeqt24qpemsnzgtfeswmrw6csxbkq
  30. mkdir "$tmpdir"
  31. echo -n executable > "$tmpdir/exe"
  32. chmod +x "$tmpdir/exe"
  33. ( cd "$tmpdir" ; ln -s exe symlink )
  34. mkdir "$tmpdir/subdir"
  35. test `guix hash -r "$tmpdir"` = 10k1lw41wyrjf9mxydi0is5nkpynlsvgslinics4ppir13g7d74p
  36. # Without '-r', this should fail.
  37. if guix hash "$tmpdir"
  38. then false; else true; fi
  39. # This should fail because /dev/null is a character device, which
  40. # the archive format doesn't support.
  41. if guix hash -r /dev/null
  42. then false; else true; fi
  43. # Adding a .git directory
  44. mkdir "$tmpdir/.git"
  45. touch "$tmpdir/.git/foo"
  46. # ...changes the hash
  47. test `guix hash -r $tmpdir` = 0a50z04zyzf7pidwxv0nwbj82pgzbrhdy9562kncnvkcfvb48m59
  48. # ...but remains the same when using `-x'
  49. test `guix hash -r $tmpdir -x` = 10k1lw41wyrjf9mxydi0is5nkpynlsvgslinics4ppir13g7d74p
  50. # Without '-r', this should fail.
  51. if guix hash "$tmpdir"
  52. then false; else true; fi