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.
This commit is contained in:
parent
51861587c6
commit
dd7c013d4b
|
@ -186,7 +186,8 @@ SH_TESTS = \
|
||||||
tests/guix-package.sh \
|
tests/guix-package.sh \
|
||||||
tests/guix-system.sh \
|
tests/guix-system.sh \
|
||||||
tests/guix-archive.sh \
|
tests/guix-archive.sh \
|
||||||
tests/guix-authenticate.sh
|
tests/guix-authenticate.sh \
|
||||||
|
tests/guix-lint.sh
|
||||||
|
|
||||||
if BUILD_DAEMON
|
if BUILD_DAEMON
|
||||||
|
|
||||||
|
|
|
@ -2855,6 +2855,11 @@ The @var{options} may be zero or more of the following:
|
||||||
|
|
||||||
@table @code
|
@table @code
|
||||||
|
|
||||||
|
@item --checkers
|
||||||
|
@itemx -c
|
||||||
|
Only enable the checkers specified in a comma-separated list using the
|
||||||
|
names returned by @code{--list-checkers}.
|
||||||
|
|
||||||
@item --list-checkers
|
@item --list-checkers
|
||||||
@itemx -l
|
@itemx -l
|
||||||
List and describe all the available checkers that will be run on packages
|
List and describe all the available checkers that will be run on packages
|
||||||
|
|
|
@ -34,44 +34,6 @@
|
||||||
check-patches
|
check-patches
|
||||||
check-synopsis-style))
|
check-synopsis-style))
|
||||||
|
|
||||||
|
|
||||||
;;;
|
|
||||||
;;; Command-line options.
|
|
||||||
;;;
|
|
||||||
|
|
||||||
(define %default-options
|
|
||||||
;; Alist of default option values.
|
|
||||||
'())
|
|
||||||
|
|
||||||
(define (show-help)
|
|
||||||
(display (_ "Usage: guix lint [OPTION]... [PACKAGE]...
|
|
||||||
Run a set of checkers on the specified package; if none is specified, run the checkers on all packages.\n"))
|
|
||||||
(display (_ "
|
|
||||||
-h, --help display this help and exit"))
|
|
||||||
(display (_ "
|
|
||||||
-l, --list-checkers display the list of available lint checkers"))
|
|
||||||
(display (_ "
|
|
||||||
-V, --version display version information and exit"))
|
|
||||||
(newline)
|
|
||||||
(show-bug-report-information))
|
|
||||||
|
|
||||||
(define %options
|
|
||||||
;; Specification of the command-line options.
|
|
||||||
;; TODO: add some options:
|
|
||||||
;; * --checkers=checker1,checker2...: only run the specified checkers
|
|
||||||
;; * --certainty=[low,medium,high]: only run checkers that have at least this
|
|
||||||
;; 'certainty'.
|
|
||||||
(list (option '(#\h "help") #f #f
|
|
||||||
(lambda args
|
|
||||||
(show-help)
|
|
||||||
(exit 0)))
|
|
||||||
(option '(#\l "list-checkers") #f #f
|
|
||||||
(lambda args
|
|
||||||
(list-checkers-and-exit)))
|
|
||||||
(option '(#\V "version") #f #f
|
|
||||||
(lambda args
|
|
||||||
(show-version-and-exit "guix lint")))))
|
|
||||||
|
|
||||||
|
|
||||||
;;;
|
;;;
|
||||||
;;; Helpers
|
;;; Helpers
|
||||||
|
@ -223,11 +185,67 @@ Run a set of checkers on the specified package; if none is specified, run the ch
|
||||||
(description "Validate package synopsis")
|
(description "Validate package synopsis")
|
||||||
(check check-synopsis-style))))
|
(check check-synopsis-style))))
|
||||||
|
|
||||||
(define (run-checkers package)
|
(define (run-checkers package checkers)
|
||||||
;; Run all the checkers on PACKAGE.
|
;; Run the given CHECKERS on PACKAGE.
|
||||||
(for-each (lambda (checker)
|
(for-each (lambda (checker)
|
||||||
((lint-checker-check checker) package))
|
((lint-checker-check checker) package))
|
||||||
%checkers))
|
checkers))
|
||||||
|
|
||||||
|
|
||||||
|
;;;
|
||||||
|
;;; Command-line options.
|
||||||
|
;;;
|
||||||
|
|
||||||
|
(define %default-options
|
||||||
|
;; Alist of default option values.
|
||||||
|
'())
|
||||||
|
|
||||||
|
(define (show-help)
|
||||||
|
(display (_ "Usage: guix lint [OPTION]... [PACKAGE]...
|
||||||
|
Run a set of checkers on the specified package; if none is specified, run the checkers on all packages.\n"))
|
||||||
|
(display (_ "
|
||||||
|
-c, --checkers=CHECKER1,CHECKER2...
|
||||||
|
only run the specificed checkers"))
|
||||||
|
(display (_ "
|
||||||
|
-h, --help display this help and exit"))
|
||||||
|
(display (_ "
|
||||||
|
-l, --list-checkers display the list of available lint checkers"))
|
||||||
|
(display (_ "
|
||||||
|
-V, --version display version information and exit"))
|
||||||
|
(newline)
|
||||||
|
(show-bug-report-information))
|
||||||
|
|
||||||
|
|
||||||
|
(define %options
|
||||||
|
;; Specification of the command-line options.
|
||||||
|
;; TODO: add some options:
|
||||||
|
;; * --certainty=[low,medium,high]: only run checkers that have at least this
|
||||||
|
;; 'certainty'.
|
||||||
|
(list (option '(#\c "checkers") #t #f
|
||||||
|
(lambda (opt name arg result arg-handler)
|
||||||
|
(let ((names (string-split arg #\,)))
|
||||||
|
(for-each (lambda (c)
|
||||||
|
(when (not (member c (map lint-checker-name
|
||||||
|
%checkers)))
|
||||||
|
(leave (_ "~a: invalid checker") c)))
|
||||||
|
names)
|
||||||
|
(values (alist-cons 'checkers
|
||||||
|
(filter (lambda (checker)
|
||||||
|
(member (lint-checker-name checker)
|
||||||
|
names))
|
||||||
|
%checkers)
|
||||||
|
result)
|
||||||
|
#f))))
|
||||||
|
(option '(#\h "help") #f #f
|
||||||
|
(lambda args
|
||||||
|
(show-help)
|
||||||
|
(exit 0)))
|
||||||
|
(option '(#\l "list-checkers") #f #f
|
||||||
|
(lambda args
|
||||||
|
(list-checkers-and-exit)))
|
||||||
|
(option '(#\V "version") #f #f
|
||||||
|
(lambda args
|
||||||
|
(show-version-and-exit "guix lint")))))
|
||||||
|
|
||||||
|
|
||||||
;;;
|
;;;
|
||||||
|
@ -238,23 +256,21 @@ Run a set of checkers on the specified package; if none is specified, run the ch
|
||||||
(define (parse-options)
|
(define (parse-options)
|
||||||
;; Return the alist of option values.
|
;; Return the alist of option values.
|
||||||
(args-fold* args %options
|
(args-fold* args %options
|
||||||
(lambda (opt name arg result)
|
(lambda (opt name arg result arg-handler)
|
||||||
(leave (_ "~A: unrecognized option~%") name))
|
(leave (_ "~A: unrecognized option~%") name))
|
||||||
(lambda (arg result)
|
(lambda (arg result arg-handler)
|
||||||
(alist-cons 'argument arg result))
|
(alist-cons 'argument arg result))
|
||||||
%default-options))
|
%default-options #f))
|
||||||
|
|
||||||
(let* ((opts (parse-options))
|
(let* ((opts (parse-options))
|
||||||
(args (filter-map (match-lambda
|
(args (filter-map (match-lambda
|
||||||
(('argument . value)
|
(('argument . value)
|
||||||
value)
|
value)
|
||||||
(_ #f))
|
(_ #f))
|
||||||
(reverse opts))))
|
(reverse opts)))
|
||||||
|
(checkers (or (assoc-ref opts 'checkers) %checkers)))
|
||||||
|
|
||||||
(if (null? args)
|
(if (null? args)
|
||||||
(fold-packages (lambda (p r) (run-checkers p)) '())
|
(fold-packages (lambda (p r) (run-checkers p checkers)) '())
|
||||||
(for-each
|
(for-each (lambda (spec)
|
||||||
(lambda (spec)
|
(run-checkers (specification->package spec) checkers))
|
||||||
(run-checkers spec))
|
args))))
|
||||||
(map specification->package args)))))
|
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
# GNU Guix --- Functional package management for GNU
|
||||||
|
# Copyright © 2014 Cyril Roelandt <tipecaml@gmail.com>
|
||||||
|
#
|
||||||
|
# This file is part of GNU Guix.
|
||||||
|
#
|
||||||
|
# GNU Guix is free software; you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
# your option) any later version.
|
||||||
|
#
|
||||||
|
# GNU Guix is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#
|
||||||
|
# Test the `guix lint' command-line utility.
|
||||||
|
#
|
||||||
|
|
||||||
|
guix lint --version
|
||||||
|
|
||||||
|
module_dir="t-guix-lint-$$"
|
||||||
|
mkdir "$module_dir"
|
||||||
|
trap "rm -rf $module_dir" EXIT
|
||||||
|
|
||||||
|
|
||||||
|
cat > "$module_dir/foo.scm"<<EOF
|
||||||
|
(define-module (foo)
|
||||||
|
#:use-module (guix packages)
|
||||||
|
#:use-module (gnu packages base))
|
||||||
|
|
||||||
|
(define-public dummy
|
||||||
|
(package (inherit hello)
|
||||||
|
(name "dummy")
|
||||||
|
(version "42")
|
||||||
|
(synopsis "dummy package")
|
||||||
|
(description "dummy package only used for testing purposes.")))
|
||||||
|
EOF
|
||||||
|
|
||||||
|
export GUIX_PACKAGE_PATH=$module_dir
|
||||||
|
export GUIX_PACKAGE_PATH
|
||||||
|
|
||||||
|
grep_warning ()
|
||||||
|
{
|
||||||
|
res=`echo "$1" | grep -E -c "(synopsis|description) should"`
|
||||||
|
echo $res
|
||||||
|
}
|
||||||
|
|
||||||
|
# Three issues with the dummy package:
|
||||||
|
# 1) the synopsis starts with the package name;
|
||||||
|
# 2) the synopsis starts with a lower-case letter;
|
||||||
|
# 3) the description starts with a lower-case letter.
|
||||||
|
|
||||||
|
out=`guix lint dummy 2>&1`
|
||||||
|
if [ `grep_warning "$out"` -ne 3 ]
|
||||||
|
then false; else true; fi
|
||||||
|
|
||||||
|
out=`guix lint -c synopsis dummy 2>&1`
|
||||||
|
if [ `grep_warning "$out"` -ne 2 ]
|
||||||
|
then false; else true; fi
|
||||||
|
|
||||||
|
out=`guix lint -c description dummy 2>&1`
|
||||||
|
if [ `grep_warning "$out"` -ne 1 ]
|
||||||
|
then false; else true; fi
|
||||||
|
|
||||||
|
out=`guix lint -c description,synopsis dummy 2>&1`
|
||||||
|
if [ `grep_warning "$out"` -ne 3 ]
|
||||||
|
then false; else true; fi
|
||||||
|
|
||||||
|
if guix lint -c synopsis,invalid-checker dummy 2>&1 | \
|
||||||
|
grep -q 'invalid-checker: invalid checker'
|
||||||
|
then true; else false; fi
|
Loading…
Reference in New Issue