scripts: add guix lint
[jackhill/guix/guix.git] / tests / lint.scm
CommitLineData
b4f5e0e8
CR
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2012, 2013 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(define-module (test-packages)
21 #:use-module (guix build download)
22 #:use-module (guix build-system gnu)
23 #:use-module (guix packages)
24 #:use-module (guix scripts lint)
25 #:use-module (guix ui)
26 #:use-module (gnu packages)
27 #:use-module (gnu packages pkg-config)
28 #:use-module (srfi srfi-64))
29
30;; Test the linter.
31
32\f
33(test-begin "lint")
34
35(define-syntax-rule (dummy-package name* extra-fields ...)
36 (package extra-fields ... (name name*) (version "0") (source #f)
37 (build-system gnu-build-system)
38 (synopsis #f) (description #f)
39 (home-page #f) (license #f) ))
40
41(define (call-with-warnings thunk)
42 (let ((port (open-output-string)))
43 (parameterize ((guix-warning-port port))
44 (thunk))
45 (get-output-string port)))
46
47(test-assert "synopsis: ends with a period"
48 (->bool
49 (string-contains (call-with-warnings
50 (lambda ()
51 (let ((pkg (dummy-package "x"
52 (synopsis "Bad synopsis."))))
53 (check-synopsis-style pkg))))
54 "no period allowed at the end of the synopsis")))
55
56(test-assert "synopsis: ends with 'etc.'"
57 (->bool
58 (string-null? (call-with-warnings
59 (lambda ()
60 (let ((pkg (dummy-package "x"
61 (synopsis "Foo, bar, etc."))))
62 (check-synopsis-style pkg)))))))
63
64(test-assert "synopsis: starts with 'A'"
65 (->bool
66 (string-contains (call-with-warnings
67 (lambda ()
68 (let ((pkg (dummy-package "x"
69 (synopsis "A bad synopŝis"))))
70 (check-synopsis-style pkg))))
71 "no article allowed at the beginning of the synopsis")))
72
73(test-assert "synopsis: starts with 'An'"
74 (->bool
75 (string-contains (call-with-warnings
76 (lambda ()
77 (let ((pkg (dummy-package "x"
78 (synopsis "An awful synopsis"))))
79 (check-synopsis-style pkg))))
80 "no article allowed at the beginning of the synopsis")))
81
82(test-assert "inputs: pkg-config is probably a native input"
83 (->bool
84 (string-contains
85 (call-with-warnings
86 (lambda ()
87 (let ((pkg (dummy-package "x"
88 (inputs `(("pkg-config" ,pkg-config))))))
89 (check-inputs-should-be-native pkg))))
90 "pkg-config should probably be a native input")))
91
92(test-assert "patches: file names"
93 (->bool
94 (string-contains
95 (call-with-warnings
96 (lambda ()
97 (let ((pkg (dummy-package "x"
98 (source
99 (origin
100 (method url-fetch)
101 (uri "someurl")
102 (sha256 "somesha")
103 (patches (list "/path/to/y.patch")))))))
104 (check-patches pkg))))
105 "file names of patches should start with the package name")))
106
107(test-end "lint")
108
109\f
110(exit (= (test-runner-fail-count (test-runner-current)) 0))