WIP:afs-service-commit
[jackhill/guix/guix.git] / tests / guix-lint.sh
CommitLineData
dd7c013d
CR
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
23guix lint --version
24
d10474c3
LC
25# Choose a module directory not below any %LOAD-PATH component. This is
26# necessary when testing '-L' with a relative file name.
27module_dir="$(mktemp -d)"
28
29mkdir -p "$module_dir"
dd7c013d
CR
30trap "rm -rf $module_dir" EXIT
31
32
33cat > "$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")
791e0126 43 (description "dummy package. Only used for testing purposes.")))
dd7c013d
CR
44EOF
45
c8af8572 46GUIX_PACKAGE_PATH="$module_dir"
dd7c013d
CR
47export GUIX_PACKAGE_PATH
48
49grep_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;
791e0126 58# 3) the description has a single space following the end-of-sentence period.
dd7c013d 59
a61cd1d0 60out=`guix lint -c synopsis,description dummy 2>&1`
dd7c013d
CR
61if [ `grep_warning "$out"` -ne 3 ]
62then false; else true; fi
63
64out=`guix lint -c synopsis dummy 2>&1`
65if [ `grep_warning "$out"` -ne 2 ]
66then false; else true; fi
67
68out=`guix lint -c description dummy 2>&1`
69if [ `grep_warning "$out"` -ne 1 ]
70then false; else true; fi
71
72out=`guix lint -c description,synopsis dummy 2>&1`
73if [ `grep_warning "$out"` -ne 3 ]
74then false; else true; fi
75
76if guix lint -c synopsis,invalid-checker dummy 2>&1 | \
77 grep -q 'invalid-checker: invalid checker'
78then true; else false; fi
8fbf5302
LC
79
80# Make sure specifying multiple packages works.
1b846da8 81guix lint -c inputs-should-be-native dummy dummy@42 dummy
7282f949 82
83
84# Use --load-path instead.
85unset GUIX_PACKAGE_PATH
86
87out=`guix lint -L $module_dir -c synopsis,description dummy 2>&1`
88if [ `grep_warning "$out"` -ne 3 ]
89then false; else true; fi
90
91# Make sure specifying multiple packages works.
92guix lint -L $module_dir -c inputs-should-be-native dummy dummy@42 dummy
d10474c3
LC
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"
98test -z "$(cat "$module_dir/out")"