diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2021-07-18 16:05:21 +0200 | 
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2021-07-18 19:50:01 +0200 | 
| commit | 0e47fcced442d8e7c1b05184fdc1c14f10ed04ec (patch) | |
| tree | 4ae844bc0ec3c670f8697bdc24362c122fa718ad /tests/lint.scm | |
| parent | e4b70bc55a538569465bcedee19d1f2607308e65 (diff) | |
| parent | 8b1bde7bb3936a64244824500ffe60f123704437 (diff) | |
Merge branch 'master' into core-updates
Diffstat (limited to 'tests/lint.scm')
| -rw-r--r-- | tests/lint.scm | 172 | 
1 files changed, 171 insertions, 1 deletions
| diff --git a/tests/lint.scm b/tests/lint.scm index 0a8f1c6f54..dfb45ef60d 100644 --- a/tests/lint.scm +++ b/tests/lint.scm @@ -8,7 +8,9 @@  ;;; Copyright © 2017 Efraim Flashner <efraim@flashner.co.il>  ;;; Copyright © 2018, 2019 Arun Isaac <arunisaac@systemreboot.net>  ;;; Copyright © 2020 Timothy Sample <samplet@ngyro.com> +;;; Copyright © 2020 Tobias Geerinckx-Rice <me@tobias.gr>  ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz> +;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>  ;;;  ;;; This file is part of GNU Guix.  ;;; @@ -38,7 +40,7 @@    #:use-module (guix lint)    #:use-module (guix ui)    #:use-module (guix swh) -  #:use-module ((guix gexp) #:select (local-file)) +  #:use-module ((guix gexp) #:select (gexp local-file gexp?))    #:use-module ((guix utils) #:select (call-with-temporary-directory))    #:use-module ((guix import hackage) #:select (%hackage-url))    #:use-module ((guix import stackage) #:select (%stackage-url)) @@ -46,6 +48,7 @@    #:use-module (gnu packages glib)    #:use-module (gnu packages pkg-config)    #:use-module (gnu packages python-xyz) +  #:use-module ((gnu packages bash) #:select (bash bash-minimal))    #:use-module (web uri)    #:use-module (web server)    #:use-module (web server http) @@ -160,6 +163,13 @@                               (description "This is a 'quoted' thing."))))       (check-description-style pkg)))) +(test-equal "description: leading whitespace" +  "description contains leading whitespace" +  (single-lint-warning-message +   (let ((pkg (dummy-package "x" +                              (description " Whitespace.")))) +     (check-description-style pkg)))) +  (test-equal "description: trailing whitespace"    "description contains trailing whitespace"    (single-lint-warning-message @@ -370,6 +380,92 @@                            ("pkgkonfig" ,pkg-config))))))       (check-input-labels pkg)))) +(test-equal "explicit #:sh argument to 'wrap-program' is acceptable" +  '() +  (let* ((phases +          ;; Loosely based on the "catfish" package +          `(modify-phases %standard-phases +             (add-after 'install 'wrap +               (lambda* (#:key inputs outputs #:allow-other-keys) +                 (define catfish (string-append (assoc-ref outputs "out") +                                                "/bin/catfish")) +                 (define hsab (string-append (assoc-ref inputs "hsab") +                                             "/bin/hsab")) +                 (wrap-program catfish #:sh hsab +                               `("PYTHONPATH" = (,"blabla"))))))) +         (pkg (dummy-package "x" (arguments `(#:phases ,phases))))) +    (check-wrapper-inputs pkg))) + +(test-equal +    "'check-wrapper-inputs' detects 'wrap-program' without \"bash\" in inputs" +  "\"bash-minimal\" should be in 'inputs' when 'wrap-program' is used" +  (let* ((phases +          `(modify-phases %standard-phases +             (add-after 'install 'wrap +               (lambda _ +                 (wrap-program the-binary bla-bla))))) +         (pkg (dummy-package "x" (arguments `(#:phases ,phases))))) +    (single-lint-warning-message (check-wrapper-inputs pkg)))) + +(test-equal +    "'check-wrapper-inputs' detects 'wrap-qt-program' without \"bash\" in inputs" +  "\"bash-minimal\" should be in 'inputs' when 'wrap-qt-program' is used" +  (let* ((phases +          `(modify-phases %standard-phases +             (add-after 'install 'qtwrap +               (lambda _ +                 (wrap-qt-program the-binary bla-bla))))) +         (pkg (dummy-package "x" (arguments `(#:phases ,phases))))) +    (single-lint-warning-message (check-wrapper-inputs pkg)))) + +(test-equal "\"bash\" in 'inputs' satisfies 'check-wrapper-inputs'" +  '() +  (let* ((phases +          `(modify-phases %standard-phases +             (add-after 'install 'wrap +               (lambda _ +                 (wrap-program the-binary bla-bla))))) +         (pkg (dummy-package "x" (arguments `(#:phases ,phases)) +                             (inputs `(("bash" ,bash)))))) +    (check-wrapper-inputs pkg))) + +(test-equal "\"bash-minimal\" in 'inputs' satisfies 'check-wrapper-inputs'" +  '() +  (let* ((phases +          `(modify-phases %standard-phases +             (add-after 'install 'wrap +               (lambda _ +                 (wrap-program THE-BINARY bla-bla))))) +         (pkg (dummy-package "x" (arguments `(#:phases ,phases)) +                             (inputs `(("bash-minimal" ,bash-minimal)))))) +    (check-wrapper-inputs pkg))) + +(test-equal "'cut' doesn't hide bad usages of 'wrap-program'" +  "\"bash-minimal\" should be in 'inputs' when 'wrap-program' is used" +  (let* ((phases +          ;; Taken from the "straw-viewer" package +          `(modify-phases %standard-phases +             (add-after 'install 'wrap-program +               (lambda* (#:key outputs #:allow-other-keys) +                 (let* ((out (assoc-ref outputs "out")) +                        (bin-dir (string-append out "/bin/")) +                        (site-dir (string-append out "/lib/perl5/site_perl/")) +                        (lib-path (getenv "PERL5LIB"))) +                   (for-each (cut wrap-program <> +                                  `("PERL5LIB" ":" prefix +                                    (,lib-path ,site-dir))) +                             (find-files bin-dir))))))) +         (pkg (dummy-package "x" (arguments `(#:phases ,phases))))) +    (single-lint-warning-message (check-wrapper-inputs pkg)))) + +(test-equal "bogus phase specifications don't crash the linter" +  "invalid phase clause" +  (let* ((phases +          `(modify-phases %standard-phases +             (add-invalid))) +         (pkg (dummy-package "x" (arguments `(#:phases ,phases))))) +    (single-lint-warning-message (check-wrapper-inputs pkg)))) +  (test-equal "file patches: different file name -> warning"    "file names of patches should start with the package name"    (single-lint-warning-message @@ -758,6 +854,80 @@                                 (sha256 %null-sha256))))))      (check-source-unstable-tarball pkg))) +(define (package-with-phase-changes changes) +  (dummy-package "x" +                 (arguments `(#:phases +                              ,(if (gexp? changes) +                                   #~(modify-phases %standard-phases +                                       #$@changes) +                                   `(modify-phases %standard-phases +                                      ,@changes)))))) + +(test-equal "optional-tests: no check phase" +  '() +  (let ((pkg (package-with-phase-changes '()))) +    (check-optional-tests pkg))) + +(test-equal "optional-tests: check phase respects #:tests?" +  '() +  (let ((pkg (package-with-phase-changes +              '((replace 'check +                  (lambda* (#:key tests? #:allow-other-keys?) +                    (when tests? +                      (invoke "./the-test-suite")))))))) +    (check-optional-tests pkg))) + +(test-equal "optional-tests: check phase ignores #:tests?" +  "the 'check' phase should respect #:tests?" +  (let ((pkg (package-with-phase-changes +              '((replace 'check +                  (lambda _ +                    (invoke "./the-test-suite"))))))) +    (single-lint-warning-message +     (check-optional-tests pkg)))) + +(test-equal "optional-tests: do not crash when #:phases is invalid" +  "incorrect call to ‘modify-phases’" +  (let ((pkg (package-with-phase-changes 'this-is-not-a-list))) +    (single-lint-warning-message +     (check-optional-tests pkg)))) + +(test-equal "optional-tests: allow G-exps (no warning)" +  '() +  (let ((pkg (package-with-phase-changes #~()))) +    (check-optional-tests pkg))) + +(test-equal "optional-tests: allow G-exps (warning)" +  "the 'check' phase should respect #:tests?" +  (let ((pkg (package-with-phase-changes +              #~((replace 'check +                   (lambda _ +                     (invoke "/the-test-suite"))))))) +    (single-lint-warning-message +     (check-optional-tests pkg)))) + +(test-equal "optional-tests: complicated 'check' phase" +  "the 'check' phase should respect #:tests?" +  (let ((pkg (package-with-phase-changes +              '((replace 'check +                  (lambda* (#:key inputs tests? #:allow-other-keys) +                    (let ((something (stuff from inputs or native-inputs))) +                      (delete-file "dateutil/test/test_utils.py") +                      (invoke "pytest" "-vv")))))))) +    (single-lint-warning-message +     (check-optional-tests pkg)))) + +(test-equal "optional-tests: 'check' phase is not first phase" +  "the 'check' phase should respect #:tests?" +  (let ((pkg (package-with-phase-changes +              '((add-after 'unpack +                    (lambda _ +                      (chdir "libtestcase-0.0.0"))) +                (replace 'check +                  (lambda _ (invoke "./test-suite"))))))) +    (single-lint-warning-message +     (check-optional-tests pkg)))) +  (test-equal "source: 200"    '()    (with-http-server `((200 ,%long-string)) | 
