;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2012, 2013 Cyril Roelandt ;;; Copyright © 2014, 2015, 2016 Eric Bavier ;;; Copyright © 2014, 2015, 2016, 2017 Ludovic Courtès ;;; Copyright © 2015, 2016 Mathieu Lirzin ;;; Copyright © 2016 Hartmut Goebel ;;; Copyright © 2017 Alex Kost ;;; Copyright © 2017 Efraim Flashner ;;; ;;; 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 . ;; Avoid interference. (unsetenv "http_proxy") (define-module (test-lint) #:use-module (guix tests) #:use-module (guix tests http) #:use-module (guix download) #:use-module (guix git-download) #:use-module (guix build-system gnu) #:use-module (guix packages) #:use-module (guix scripts lint) #:use-module (guix ui) #:use-module (gnu packages) #:use-module (gnu packages glib) #:use-module (gnu packages pkg-config) #:use-module (gnu packages python) #:use-module (web uri) #:use-module (web server) #:use-module (web server http) #:use-module (web response) #:use-module (ice-9 match) #:use-module (srfi srfi-9 gnu) #:use-module (srfi srfi-64)) ;; Test the linter. ;; Avoid collisions with other tests. (%http-server-port 9999) (define %null-sha256 ;; SHA256 of the empty string. (base32 "0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73")) (define %long-string (make-string 2000 #\a)) (test-begin "lint") (define (call-with-warnings thunk) (let ((port (open-output-string))) (parameterize ((guix-warning-port port)) (thunk)) (get-output-string port))) (define-syntax-rule (with-warnings body ...) (call-with-warnings (lambda () body ...))) (test-assert "description: not a string" (->bool (string-contains (with-warnings (let ((pkg (dummy-package "x" (description 'foobar)))) (check-description-style pkg))) "invalid description"))) (test-assert "description: not empty" (->bool (string-contains (with-warnings (let ((pkg (dummy-package "x" (description "")))) (check-description-style pkg))) "description should not be empty"))) (test-assert "description: valid Texinfo markup" (->bool (string-contains (with-warnings (check-description-style (dummy-package "x" (description "f{oo}b@r")))) "Texinfo markup in description is invalid"))) (test-assert "description: does not start with an upper-case letter" (->bool (string-contains (with-warnings (let ((pkg (dummy-package "x" (description "bad description.")))) (check-description-style pkg))) "description should start with an upper-case letter"))) (test-assert "description: may start with a digit" (string-null? (with-warnings (let ((pkg (dummy-package "x" (description "2-component library.")))) (check-description-style pkg))))) (test-assert "description: may start with lower-case package name" (string-null? (with-warnings (let ((pkg (dummy-package "x" (description "x is a dummy package.")))) (check-description-style pkg))))) (test-assert "description: two spaces after end of sentence" (->bool (string-contains (with-warnings (let ((pkg (dummy-package "x" (description "Bad. Quite bad.")))) (check-description-style pkg))) "sentences in description should be followed by two spaces"))) (test-assert "description: end-of-sentence detection with abbreviations" (string-null? (with-warnings (let ((pkg (dummy-package "x" (description "E.g. Foo, i.e. Bar resp. Baz (a.k.a. DVD).")))) (check-description-style pkg))))) (test-assert "description: may not contain trademark signs" (and (->bool (string-contains (with-warnings (let ((pkg (dummy-package "x" (description "Does The Right Thing™")))) (check-description-style pkg))) "should not contain trademark sign")) (->bool (string-contains (with-warnings (let ((pkg (dummy-package "x" (description "Works with Format®")))) (check-description-style pkg))) "should not contain trademark sign")))) (test-assert "description: suggest ornament instead of quotes" (->bool (string-contains (with-warnings (let ((pkg (dummy-package "x" (description "This is a 'quoted' thing.")))) (check-description-style pkg))) "use @code"))) (test-assert "synopsis: not a string" (->bool (string-contains (with-warnings (let ((pkg (dummy-package "x" (synopsis #f)))) (check-synopsis-style pkg))) "invalid synopsis"))) (test-assert "synopsis: not empty" (->bool (string-contains (with-warnings (let ((pkg (dummy-package "x"