summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyril Roelandt <tipecaml@gmail.com>2014-10-12 01:58:29 +0200
committerCyril Roelandt <tipecaml@gmail.com>2014-10-16 00:50:27 +0200
commitdd7c013d4be0fea8db61c909f5ba6f877c143fd3 (patch)
tree9af11d891f6eb2d6650139f0641849a20fd7624f
parent51861587c670c390b3420f0da6a86111b386f750 (diff)
guix lint: add the --checkers option.
* guix/scripts/lint.scm: add the "--checkers" option. * doc/guix.texi (Invoking guix lint): Document it. * tests/guix-lint.sh: New file * Makefile.am (SCM_TESTS): Add it.
-rw-r--r--Makefile.am3
-rw-r--r--doc/guix.texi5
-rw-r--r--guix/scripts/lint.scm122
-rw-r--r--tests/guix-lint.sh75
4 files changed, 151 insertions, 54 deletions
diff --git a/Makefile.am b/Makefile.am
index 4b823ec76c5..b13fcbc0533 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -186,7 +186,8 @@ SH_TESTS = \
186 tests/guix-package.sh \ 186 tests/guix-package.sh \
187 tests/guix-system.sh \ 187 tests/guix-system.sh \
188 tests/guix-archive.sh \ 188 tests/guix-archive.sh \
189 tests/guix-authenticate.sh 189 tests/guix-authenticate.sh \
190 tests/guix-lint.sh
190 191
191if BUILD_DAEMON 192if BUILD_DAEMON
192 193
diff --git a/doc/guix.texi b/doc/guix.texi
index bbe84ab2759..4c59d9f6969 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -2855,6 +2855,11 @@ The @var{options} may be zero or more of the following:
2855 2855
2856@table @code 2856@table @code
2857 2857
2858@item --checkers
2859@itemx -c
2860Only enable the checkers specified in a comma-separated list using the
2861names returned by @code{--list-checkers}.
2862
2858@item --list-checkers 2863@item --list-checkers
2859@itemx -l 2864@itemx -l
2860List and describe all the available checkers that will be run on packages 2865List and describe all the available checkers that will be run on packages
diff --git a/guix/scripts/lint.scm b/guix/scripts/lint.scm
index fd9fd7b9314..5c1ea360b7e 100644
--- a/guix/scripts/lint.scm
+++ b/guix/scripts/lint.scm
@@ -36,44 +36,6 @@
36 36
37 37
38;;; 38;;;
39;;; Command-line options.
40;;;
41
42(define %default-options
43 ;; Alist of default option values.
44 '())
45
46(define (show-help)
47 (display (_ "Usage: guix lint [OPTION]... [PACKAGE]...
48Run a set of checkers on the specified package; if none is specified, run the checkers on all packages.\n"))
49 (display (_ "
50 -h, --help display this help and exit"))
51 (display (_ "
52 -l, --list-checkers display the list of available lint checkers"))
53 (display (_ "
54 -V, --version display version information and exit"))
55 (newline)
56 (show-bug-report-information))
57
58(define %options
59 ;; Specification of the command-line options.
60 ;; TODO: add some options:
61 ;; * --checkers=checker1,checker2...: only run the specified checkers
62 ;; * --certainty=[low,medium,high]: only run checkers that have at least this
63 ;; 'certainty'.
64 (list (option '(#\h "help") #f #f
65 (lambda args
66 (show-help)
67 (exit 0)))
68 (option '(#\l "list-checkers") #f #f
69 (lambda args
70 (list-checkers-and-exit)))
71 (option '(#\V "version") #f #f
72 (lambda args
73 (show-version-and-exit "guix lint")))))
74
75
76;;;
77;;; Helpers 39;;; Helpers
78;;; 40;;;
79(define* (emit-warning package message #:optional field) 41(define* (emit-warning package message #:optional field)
@@ -223,11 +185,67 @@ Run a set of checkers on the specified package; if none is specified, run the ch
223 (description "Validate package synopsis") 185 (description "Validate package synopsis")
224 (check check-synopsis-style)))) 186 (check check-synopsis-style))))
225 187
226(define (run-checkers package) 188(define (run-checkers package checkers)
227 ;; Run all the checkers on PACKAGE. 189 ;; Run the given CHECKERS on PACKAGE.
228 (for-each (lambda (checker) 190 (for-each (lambda (checker)
229 ((lint-checker-check checker) package)) 191 ((lint-checker-check checker) package))
230 %checkers)) 192 checkers))
193
194
195;;;
196;;; Command-line options.
197;;;
198
199(define %default-options
200 ;; Alist of default option values.
201 '())
202
203(define (show-help)
204 (display (_ "Usage: guix lint [OPTION]... [PACKAGE]...
205Run a set of checkers on the specified package; if none is specified, run the checkers on all packages.\n"))
206 (display (_ "
207 -c, --checkers=CHECKER1,CHECKER2...
208 only run the specificed checkers"))
209 (display (_ "
210 -h, --help display this help and exit"))
211 (display (_ "
212 -l, --list-checkers display the list of available lint checkers"))
213 (display (_ "
214 -V, --version display version information and exit"))
215 (newline)
216 (show-bug-report-information))
217
218
219(define %options
220 ;; Specification of the command-line options.
221 ;; TODO: add some options:
222 ;; * --certainty=[low,medium,high]: only run checkers that have at least this
223 ;; 'certainty'.
224 (list (option '(#\c "checkers") #t #f
225 (lambda (opt name arg result arg-handler)
226 (let ((names (string-split arg #\,)))
227 (for-each (lambda (c)
228 (when (not (member c (map lint-checker-name
229 %checkers)))
230 (leave (_ "~a: invalid checker") c)))
231 names)
232 (values (alist-cons 'checkers
233 (filter (lambda (checker)
234 (member (lint-checker-name checker)
235 names))
236 %checkers)
237 result)
238 #f))))
239 (option '(#\h "help") #f #f
240 (lambda args
241 (show-help)
242 (exit 0)))
243 (option '(#\l "list-checkers") #f #f
244 (lambda args
245 (list-checkers-and-exit)))
246 (option '(#\V "version") #f #f
247 (lambda args
248 (show-version-and-exit "guix lint")))))
231 249
232 250
233;;; 251;;;
@@ -238,23 +256,21 @@ Run a set of checkers on the specified package; if none is specified, run the ch
238 (define (parse-options) 256 (define (parse-options)
239 ;; Return the alist of option values. 257 ;; Return the alist of option values.
240 (args-fold* args %options 258 (args-fold* args %options
241 (lambda (opt name arg result) 259 (lambda (opt name arg result arg-handler)
242 (leave (_ "~A: unrecognized option~%") name)) 260 (leave (_ "~A: unrecognized option~%") name))
243 (lambda (arg result) 261 (lambda (arg result arg-handler)
244 (alist-cons 'argument arg result)) 262 (alist-cons 'argument arg result))
245 %default-options)) 263 %default-options #f))
246 264
247 (let* ((opts (parse-options)) 265 (let* ((opts (parse-options))
248 (args (filter-map (match-lambda 266 (args (filter-map (match-lambda
249 (('argument . value) 267 (('argument . value)
250 value) 268 value)
251 (_ #f)) 269 (_ #f))
252 (reverse opts)))) 270 (reverse opts)))
253 271 (checkers (or (assoc-ref opts 'checkers) %checkers)))
254 272 (if (null? args)
255 (if (null? args) 273 (fold-packages (lambda (p r) (run-checkers p checkers)) '())
256 (fold-packages (lambda (p r) (run-checkers p)) '()) 274 (for-each (lambda (spec)
257 (for-each 275 (run-checkers (specification->package spec) checkers))
258 (lambda (spec) 276 args))))
259 (run-checkers spec))
260 (map specification->package args)))))
diff --git a/tests/guix-lint.sh b/tests/guix-lint.sh
new file mode 100644
index 00000000000..5623d53ce50
--- /dev/null
+++ b/tests/guix-lint.sh
@@ -0,0 +1,75 @@
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
25module_dir="t-guix-lint-$$"
26mkdir "$module_dir"
27trap "rm -rf $module_dir" EXIT
28
29
30cat > "$module_dir/foo.scm"<<EOF
31(define-module (foo)
32 #:use-module (guix packages)
33 #:use-module (gnu packages base))
34
35(define-public dummy
36 (package (inherit hello)
37 (name "dummy")
38 (version "42")
39 (synopsis "dummy package")
40 (description "dummy package only used for testing purposes.")))
41EOF
42
43export GUIX_PACKAGE_PATH=$module_dir
44export GUIX_PACKAGE_PATH
45
46grep_warning ()
47{
48 res=`echo "$1" | grep -E -c "(synopsis|description) should"`
49 echo $res
50}
51
52# Three issues with the dummy package:
53# 1) the synopsis starts with the package name;
54# 2) the synopsis starts with a lower-case letter;
55# 3) the description starts with a lower-case letter.
56
57out=`guix lint dummy 2>&1`
58if [ `grep_warning "$out"` -ne 3 ]
59then false; else true; fi
60
61out=`guix lint -c synopsis dummy 2>&1`
62if [ `grep_warning "$out"` -ne 2 ]
63then false; else true; fi
64
65out=`guix lint -c description dummy 2>&1`
66if [ `grep_warning "$out"` -ne 1 ]
67then false; else true; fi
68
69out=`guix lint -c description,synopsis dummy 2>&1`
70if [ `grep_warning "$out"` -ne 3 ]
71then false; else true; fi
72
73if guix lint -c synopsis,invalid-checker dummy 2>&1 | \
74 grep -q 'invalid-checker: invalid checker'
75then true; else false; fi