From patchwork Sun May 9 18:02:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: M X-Patchwork-Id: 29187 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 834EB27BC82; Sun, 9 May 2021 19:03:12 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id D020227BC81 for ; Sun, 9 May 2021 19:03:11 +0100 (BST) Received: from localhost ([::1]:47614 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lfnlm-0000hT-Un for patchwork@mira.cbaines.net; Sun, 09 May 2021 14:03:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40910) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lfnle-0000eH-BE for guix-patches@gnu.org; Sun, 09 May 2021 14:03:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:45009) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lfnle-00072Z-33 for guix-patches@gnu.org; Sun, 09 May 2021 14:03:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lfnld-00076C-Vb for guix-patches@gnu.org; Sun, 09 May 2021 14:03:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#48320] [PATCH] lint: Verify if #:tests? is respected in the 'check' phase. Resent-From: Maxime Devos Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 09 May 2021 18:03:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 48320 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 48320@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.162058335227250 (code B ref -1); Sun, 09 May 2021 18:03:01 +0000 Received: (at submit) by debbugs.gnu.org; 9 May 2021 18:02:32 +0000 Received: from localhost ([127.0.0.1]:56555 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lfnl9-00075R-N8 for submit@debbugs.gnu.org; Sun, 09 May 2021 14:02:32 -0400 Received: from lists.gnu.org ([209.51.188.17]:48680) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lfnl6-00075I-JT for submit@debbugs.gnu.org; Sun, 09 May 2021 14:02:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40842) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lfnl5-0000HF-9a for guix-patches@gnu.org; Sun, 09 May 2021 14:02:28 -0400 Received: from laurent.telenet-ops.be ([2a02:1800:110:4::f00:19]:34846) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lfnl2-0006cC-B2 for guix-patches@gnu.org; Sun, 09 May 2021 14:02:27 -0400 Received: from ptr-bvsjgyjmffd7q9timvx.18120a2.ip6.access.telenet.be ([IPv6:2a02:1811:8c09:9d00:aaf1:9810:a0b8:a55d]) by laurent.telenet-ops.be with bizsmtp id 2i2K250020mfAB401i2KQX; Sun, 09 May 2021 20:02:19 +0200 Message-ID: <2b0fee1845a66e1fb126b4bbf1c9892b7c648a3a.camel@telenet.be> From: Maxime Devos Date: Sun, 09 May 2021 20:02:12 +0200 User-Agent: Evolution 3.34.2 MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telenet.be; s=r21; t=1620583339; bh=DvpLwUPDDyHeUnlOZ//u2OOFTKBEWan69D2MYwxGWhg=; h=Subject:From:To:Date; b=RumX3z0KAieEc9JR/gzsqAfwvrIu89obDIk5d8gfA2F+oMYa8j0jvLtobgOdahiY1 rBM1chBcgXJbQtY0MCv6AHUwQjfZop/W7HmFqGJIgrJSslmxuQMKPbPlWUVGHoPjZ6 AxF4p+2WDA47qelUPKhhHrepgJYJVvyi+ReTOAqTA0be34WarTxUDDPgUKEOgYtAKz cpi1NlM2ZYO9D4wI90qSoEAxMPndDRTSg4BbtTV1wmu9Je67mffzdVlNi0xcJgMLAu +fWpEMk/7o6ufvjrYB1V9jQ00yKdFeYWRBXStGhkIGba7TuUHeZ4BQ/JM3D6Z91nTb +Bb0Csead+ZbQ== Received-SPF: pass client-ip=2a02:1800:110:4::f00:19; envelope-from=maximedevos@telenet.be; helo=laurent.telenet-ops.be X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches Hi guix, There have been a few patches to the mailing list lately not respecting this, and this linter detects 325 package definitions that could be modified to support the --without-tests package transformation. Copyright lines were added in the previous patch I sent to guix-patches today. Greetings, Maxime From 77f6fdb0158d76af9a6789bd0da45ac852ee2868 Mon Sep 17 00:00:00 2001 From: Maxime Devos Date: Sun, 9 May 2021 19:53:31 +0200 Subject: [PATCH] lint: Verify if #:tests? is respected in the 'check' phase. There have been a few patches to the mailing list lately not respecting this, and this linter detects 325 package definitions that could be modified to support the --without-tests package transformation. * guix/lint.scm (check-optional-tests): New linter. (%local-checkers)[optional-tests]: Add it. * tests/lint.scm (package-with-phase-changes): New procedure. ("optional-tests: no check phase") ("optional-tests: check phase respects #:tests?") ("optional-tests: check phase ignores #:tests?") ("optional-tests: do not crash when #:phases is invalid"): New tests. --- guix/lint.scm | 40 ++++++++++++++++++++++++++++++++++++++++ tests/lint.scm | 31 +++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/guix/lint.scm b/guix/lint.scm index d1cbc9d300..f5db4664dc 100644 --- a/guix/lint.scm +++ b/guix/lint.scm @@ -87,6 +87,7 @@ check-source check-source-file-name check-source-unstable-tarball + check-optional-tests check-mirror-url check-github-url check-license @@ -963,6 +964,41 @@ descriptions maintained upstream." (origin-uris origin)) '()))) +(define (check-optional-tests package) + "Emit a warning if the test suite is run unconditionally." + (define (check-check-procedure expression) + (match expression + (`(,(or 'lambda 'lambda*) ,_ (invoke . ,_) . ,_) + (list (make-warning package + ;; TRANSLATORS: check and #:tests? are a Scheme + ;; symbol and keyword respectively and should not + ;; be translated. + (G_ "the 'check' phase should respect #:tests?") + #:field 'arguments))) + ;; The 'check' phase seems ok, stop searching for a bug in this package + ;; definition. + (_ '()))) + (define (check-phases-delta delta) + (match delta + (`(replace 'check ,expression) + (check-check-procedure expression)) + (_ #f))) + (define (check-phases-deltas deltas) + (match deltas + (() '()) + ((head . tail) + (or (check-phases-delta head) + (check-phases-deltas tail))) + (_ (list (make-warning package + (G_ "incorrect call to modify-phases") + #:field 'arguments))))) + (apply (lambda* (#:key phases #:allow-other-keys) + (match phases + (`(modify-phases ,_ . ,changes) + (check-phases-deltas changes)) + (_ '()))) + (package-arguments package))) + (define (check-mirror-url package) "Check whether PACKAGE uses source URLs that should be 'mirror://'." (define (check-mirror-uri uri) ;XXX: could be optimized @@ -1529,6 +1565,10 @@ them for PACKAGE." (description "Make sure the 'license' field is a \ or a list thereof") (check check-license)) + (lint-checker + (name 'optional-tests) + (description "Make sure tests are only run when requested") + (check check-optional-tests)) (lint-checker (name 'mirror-url) (description "Suggest 'mirror://' URLs") diff --git a/tests/lint.scm b/tests/lint.scm index d6e877d0d7..c9cd6366ec 100644 --- a/tests/lint.scm +++ b/tests/lint.scm @@ -731,6 +731,37 @@ (sha256 %null-sha256)))))) (check-source-unstable-tarball pkg))) +(define (package-with-phase-changes changes) + (dummy-package "x" + (arguments `(#:phases + (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 "source: 200" '() (with-http-server `((200 ,%long-string)) -- 2.31.1