guix-style.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # GNU Guix --- Functional package management for GNU
  2. # Copyright © 2022 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 'guix style'.
  20. #
  21. set -e
  22. guix style --version
  23. tmpdir="guix-style-$$"
  24. trap 'rm -r "$tmpdir"' EXIT
  25. tmpfile="$tmpdir/os.scm"
  26. mkdir "$tmpdir"
  27. cat > "$tmpfile" <<EOF
  28. ;;; This is a header with three semicolons.
  29. ;;;
  30. (define-module (foo bar)
  31. #:use-module (guix)
  32. #:use-module (gnu))
  33. ;; One blank line and a page break.
  34. ;; And now, the OS.
  35. (operating-system
  36. (host-name "komputilo")
  37. (locale "eo_EO.UTF-8")
  38. ;; User accounts.
  39. (users (cons (user-account
  40. (name "alice")
  41. (comment "Bob's sister")
  42. (group "users")
  43. ;; Groups fit on one line.
  44. (supplementary-groups '("wheel" "audio" "video")))
  45. %base-user-accounts))
  46. ;; The services.
  47. (services
  48. (cons (service mcron-service-type) %base-services)))
  49. EOF
  50. cp "$tmpfile" "$tmpfile.bak"
  51. initial_hash="$(guix hash "$tmpfile")"
  52. guix style -f "$tmpfile"
  53. if test "$initial_hash" != "$(guix hash "$tmpfile")"
  54. then
  55. cat "$tmpfile"
  56. diff -u "$tmpfile.bak" "$tmpfile"
  57. false
  58. fi
  59. # Introduce random changes and try again.
  60. sed -i "$tmpfile" -e's/ \+/ /g'
  61. test "$initial_hash" != "$(guix hash "$tmpfile")"
  62. guix style -f "$tmpfile"
  63. test "$initial_hash" = "$(guix hash "$tmpfile")"