guix-lint.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # GNU Guix --- Functional package management for GNU
  2. # Copyright © 2014 Cyril Roelandt <tipecaml@gmail.com>
  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 lint' command-line utility.
  20. #
  21. guix lint --version
  22. # Choose a module directory not below any %LOAD-PATH component. This is
  23. # necessary when testing '-L' with a relative file name.
  24. module_dir="$(mktemp -d)"
  25. mkdir -p "$module_dir"
  26. trap "rm -rf $module_dir" EXIT
  27. cat > "$module_dir/foo.scm"<<EOF
  28. (define-module (foo)
  29. #:use-module (guix packages)
  30. #:use-module (gnu packages base))
  31. (define-public dummy
  32. (package (inherit hello)
  33. (name "dummy")
  34. (version "42")
  35. (synopsis "dummy package")
  36. (description "dummy package. Only used for testing purposes.")))
  37. EOF
  38. GUIX_PACKAGE_PATH="$module_dir"
  39. export GUIX_PACKAGE_PATH
  40. grep_warning ()
  41. {
  42. res=`echo "$1" | grep -E -c "(synopsis|description) should"`
  43. echo $res
  44. }
  45. # Three issues with the dummy package:
  46. # 1) the synopsis starts with the package name;
  47. # 2) the synopsis starts with a lower-case letter;
  48. # 3) the description has a single space following the end-of-sentence period.
  49. out=`guix lint -c synopsis,description dummy 2>&1`
  50. test `grep_warning "$out"` -eq 3
  51. out=`guix lint -c synopsis dummy 2>&1`
  52. test `grep_warning "$out"` -eq 2
  53. out=`guix lint -c description dummy 2>&1`
  54. test `grep_warning "$out"` -eq 1
  55. out=`guix lint -c description,synopsis dummy 2>&1`
  56. test `grep_warning "$out"` -eq 3
  57. guix lint -c synopsis,invalid-checker dummy 2>&1 | \
  58. grep -q 'invalid-checker: invalid checker'
  59. # Make sure specifying multiple packages works.
  60. guix lint -c inputs-should-be-native dummy dummy@42 dummy
  61. # Use --load-path instead.
  62. unset GUIX_PACKAGE_PATH
  63. out=`guix lint -L $module_dir -c synopsis,description dummy 2>&1`
  64. test `grep_warning "$out"` -eq 3
  65. # Make sure specifying multiple packages works.
  66. guix lint -L $module_dir -c inputs-should-be-native dummy dummy@42 dummy
  67. # Test '-L' with a relative file name. 'guix lint' will see "t-xyz/foo.scm"
  68. # (instead of "foo.scm") and will thus fail to find it in %LOAD-PATH. Check
  69. # that it does find it anyway. See <https://bugs.gnu.org/42543>.
  70. (cd "$module_dir"/.. ; guix lint -c formatting -L "$(basename "$module_dir")" dummy@42) 2>&1 > "$module_dir/out"
  71. test -z "$(cat "$module_dir/out")"