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