From patchwork Fri May 26 22:30:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Cully X-Patchwork-Id: 50350 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 90E9B27BBE9; Fri, 26 May 2023 23:31:35 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 7F9DA27BBE2 for ; Fri, 26 May 2023 23:31:33 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q2fxk-0003uc-Pg; Fri, 26 May 2023 18:31:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q2fxe-0003sZ-9a for guix-patches@gnu.org; Fri, 26 May 2023 18:31:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q2fxd-0003A9-Tl for guix-patches@gnu.org; Fri, 26 May 2023 18:31:01 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q2fxd-00086C-QC for guix-patches@gnu.org; Fri, 26 May 2023 18:31:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#63538] [PATCH v2 1/3] tests: Add tests for MODIFY-SERVICES procedure References: <999ea3ff3ea32e4e1bb8b7b8abd4e0e29d1f2395.1684251578.git.bjc@spork.org> In-Reply-To: <999ea3ff3ea32e4e1bb8b7b8abd4e0e29d1f2395.1684251578.git.bjc@spork.org> Resent-From: Brian Cully Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 26 May 2023 22:31:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63538 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 63538@debbugs.gnu.org Cc: Brian Cully Received: via spool by 63538-submit@debbugs.gnu.org id=B63538.168514022531070 (code B ref 63538); Fri, 26 May 2023 22:31:01 +0000 Received: (at 63538) by debbugs.gnu.org; 26 May 2023 22:30:25 +0000 Received: from localhost ([127.0.0.1]:50967 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q2fx3-000853-DL for submit@debbugs.gnu.org; Fri, 26 May 2023 18:30:25 -0400 Received: from coleridge.kublai.com ([166.84.7.167]:61703 helo=mail.spork.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q2fx1-00084j-FC for 63538@debbugs.gnu.org; Fri, 26 May 2023 18:30:23 -0400 Received: from psyduck.jhoto.kublai.com (ool-18b8e9e7.dyn.optonline.net [24.184.233.231]) by mail.spork.org (Postfix) with ESMTPSA id 4C0D1BF69; Fri, 26 May 2023 18:30:23 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=spork.org; s=dkim; t=1685140223; bh=hplE5y/5zGGoOlYdJDfrP/08gwhoEKJlQ6NQFvoHzoo=; h=From:To:Cc:Subject:Date; b=oX/Ueu7vwReP/tXiZDqo4QgKB83vKVt0r7tkbXjLspms45lO9dG7HFyPZ2gGx5Gqg 9q35Vsc7HH78/zJhl0lx/lo21q3El11Msm+wNMH5Gzgg7rLQ2iUgKmH8yD5dO1mGjl T52ImPMmwtdiPpXkMfJdDDf+X/zwmd2RzTBbw/FU= Date: Fri, 26 May 2023 18:30:15 -0400 Message-Id: X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 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: , Reply-to: Brian Cully X-ACL-Warn: , Brian Cully via Guix-patches X-Patchwork-Original-From: Brian Cully via Guix-patches via From: Brian Cully Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * tests/services.scm ("modify-services: do nothing") ("modify-services: delete service") ("modify-services: change value"): New tests. --- tests/services.scm | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) base-commit: 1be6baed2b58a75868cdcc9f51b78624c2fefc4f diff --git a/tests/services.scm b/tests/services.scm index 8e35758209..435f39e59b 100644 --- a/tests/services.scm +++ b/tests/services.scm @@ -286,4 +286,54 @@ (define-module (test-services) ((one) one) (x x)))) +(test-equal "modify-services: do nothing" + '(1 2 3) + (let* ((t1 (service-type (name 't1) + (extensions '()) + (description ""))) + (t2 (service-type (name 't2) + (extensions '()) + (description ""))) + (t3 (service-type (name 't3) + (extensions '()) + (description ""))) + (services (list (service t1 1) (service t2 2) (service t3 3)))) + (sort (map service-value + (modify-services services)) + <))) + +(test-equal "modify-services: delete service" + '(1 3) + (let* ((t1 (service-type (name 't1) + (extensions '()) + (description ""))) + (t2 (service-type (name 't2) + (extensions '()) + (description ""))) + (t3 (service-type (name 't3) + (extensions '()) + (description ""))) + (services (list (service t1 1) (service t2 2) (service t3 3)))) + (sort (map service-value + (modify-services services + (delete t2))) + <))) + +(test-equal "modify-services: change value" + '(1 2 33) + (let* ((t1 (service-type (name 't1) + (extensions '()) + (description ""))) + (t2 (service-type (name 't2) + (extensions '()) + (description ""))) + (t3 (service-type (name 't3) + (extensions '()) + (description ""))) + (services (list (service t1 1) (service t2 2) (service t3 3)))) + (sort (map service-value + (modify-services services + (t3 value => 33))) + <))) + (test-end) From patchwork Fri May 26 22:30:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Cully X-Patchwork-Id: 50352 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 D93C127BBEA; Fri, 26 May 2023 23:31:42 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id E856127BBE2 for ; Fri, 26 May 2023 23:31:41 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q2fxm-0003ud-FF; Fri, 26 May 2023 18:31:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q2fxe-0003sa-Ly for guix-patches@gnu.org; Fri, 26 May 2023 18:31:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q2fxe-0003AG-AE for guix-patches@gnu.org; Fri, 26 May 2023 18:31:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q2fxe-00086K-62 for guix-patches@gnu.org; Fri, 26 May 2023 18:31:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#63538] [PATCH v2 2/3] tests: Check for service existence in MODIFY-SERVICES Resent-From: Brian Cully Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 26 May 2023 22:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63538 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 63538@debbugs.gnu.org Cc: Brian Cully Received: via spool by 63538-submit@debbugs.gnu.org id=B63538.168514022631076 (code B ref 63538); Fri, 26 May 2023 22:31:02 +0000 Received: (at 63538) by debbugs.gnu.org; 26 May 2023 22:30:26 +0000 Received: from localhost ([127.0.0.1]:50969 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q2fx3-000855-Ne for submit@debbugs.gnu.org; Fri, 26 May 2023 18:30:26 -0400 Received: from coleridge.kublai.com ([166.84.7.167]:59415 helo=mail.spork.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q2fx1-00084k-TJ for 63538@debbugs.gnu.org; Fri, 26 May 2023 18:30:24 -0400 Received: from psyduck.jhoto.kublai.com (ool-18b8e9e7.dyn.optonline.net [24.184.233.231]) by mail.spork.org (Postfix) with ESMTPSA id ADA54BEE2; Fri, 26 May 2023 18:30:23 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=spork.org; s=dkim; t=1685140223; bh=t9xUK4xqIkXvRG2F8P0RE1fk55OZAVeF22NNXcTTZpE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=X7kgb3PmQChuYjQWN+4M4jyia6IMGf17CaJN6ihRjQWanUoiHieTitDT0e1Ff+vfg A2O4YDv07c7L7AHASlkoJUDiAExIgRhevBCrXJIQ4N0o73xgAfZbOdb3E/iJRk5EY5 fSJxb2qNx55FxW6lb7SjZb4/BcloZOMaS+rj1nrM= Date: Fri, 26 May 2023 18:30:16 -0400 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 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: , Reply-to: Brian Cully X-ACL-Warn: , Brian Cully via Guix-patches X-Patchwork-Original-From: Brian Cully via Guix-patches via From: Brian Cully Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * tests/services.scm ("modify-services: delete non-existing service") ("modify-services: change value for non-existing service"): New tests. --- tests/services.scm | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/tests/services.scm b/tests/services.scm index 435f39e59b..8cdb1b2a31 100644 --- a/tests/services.scm +++ b/tests/services.scm @@ -303,7 +303,7 @@ (define-module (test-services) <))) (test-equal "modify-services: delete service" - '(1 3) + '(1) (let* ((t1 (service-type (name 't1) (extensions '()) (description ""))) @@ -316,11 +316,27 @@ (define-module (test-services) (services (list (service t1 1) (service t2 2) (service t3 3)))) (sort (map service-value (modify-services services + (delete t3) (delete t2))) <))) +(test-error "modify-services: delete non-existing service" + #t + (let* ((t1 (service-type (name 't1) + (extensions '()) + (description ""))) + (t2 (service-type (name 't2) + (extensions '()) + (description ""))) + (t3 (service-type (name 't2) + (extensions '()) + (description ""))) + (services (list (service t1 1) (service t2 2)))) + (modify-services services + (delete t3)))) + (test-equal "modify-services: change value" - '(1 2 33) + '(2 11 33) (let* ((t1 (service-type (name 't1) (extensions '()) (description ""))) @@ -333,7 +349,24 @@ (define-module (test-services) (services (list (service t1 1) (service t2 2) (service t3 3)))) (sort (map service-value (modify-services services + (t1 value => 11) (t3 value => 33))) <))) +(test-error "modify-services: change value for non-existing service" + #t + (let* ((t1 (service-type (name 't1) + (extensions '()) + (description ""))) + (t2 (service-type (name 't2) + (extensions '()) + (description ""))) + (t3 (service-type (name 't3) + (extensions '()) + (description ""))) + (services (list (service t1 1) (service t3 3)))) + (map service-value + (modify-services services + (t2 value => 22))))) + (test-end) From patchwork Fri May 26 22:30:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Cully X-Patchwork-Id: 50351 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 75E1E27BBE9; Fri, 26 May 2023 23:31:38 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 5CD7B27BBE2 for ; Fri, 26 May 2023 23:31:36 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q2fxo-0003ui-LJ; Fri, 26 May 2023 18:31:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q2fxf-0003sp-AR for guix-patches@gnu.org; Fri, 26 May 2023 18:31:07 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q2fxe-0003AL-Pr for guix-patches@gnu.org; Fri, 26 May 2023 18:31:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q2fxe-00086R-IS for guix-patches@gnu.org; Fri, 26 May 2023 18:31:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#63538] [PATCH v2 3/3] gnu: services: Error in MODIFY-SERVICES when services don't exist Resent-From: Brian Cully Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 26 May 2023 22:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63538 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 63538@debbugs.gnu.org Cc: Brian Cully Received: via spool by 63538-submit@debbugs.gnu.org id=B63538.168514023131092 (code B ref 63538); Fri, 26 May 2023 22:31:02 +0000 Received: (at 63538) by debbugs.gnu.org; 26 May 2023 22:30:31 +0000 Received: from localhost ([127.0.0.1]:50971 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q2fx9-00085Q-42 for submit@debbugs.gnu.org; Fri, 26 May 2023 18:30:31 -0400 Received: from coleridge.kublai.com ([166.84.7.167]:63834 helo=mail.spork.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q2fx2-00084s-AW for 63538@debbugs.gnu.org; Fri, 26 May 2023 18:30:24 -0400 Received: from psyduck.jhoto.kublai.com (ool-18b8e9e7.dyn.optonline.net [24.184.233.231]) by mail.spork.org (Postfix) with ESMTPSA id 22EA7BEE3; Fri, 26 May 2023 18:30:24 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=spork.org; s=dkim; t=1685140224; bh=jkzBQVpzQldllzZ/W1qwHhXun/BknWAYdplHnxXnZDw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=rRmlHYCuos321eCeis8XJQSa197QbyFM/mB0hwABZOIS1Ssu3zknxv7aCOCFo2mTK PMNP+iqry1bX5Pev3YI5bUi5Koh0OfmKmOFhu9vpcOflIca3NwQTcZaoriv16xq6CQ K8chy/motQNdesjfn7h0iVFau0s6A0O+UcQjW8PU= Date: Fri, 26 May 2023 18:30:17 -0400 Message-Id: <13ab94bbed475a933d8376ad8fc166c6ad124b67.1685140217.git.bjc@spork.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 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: , Reply-to: Brian Cully X-ACL-Warn: , Brian Cully via Guix-patches X-Patchwork-Original-From: Brian Cully via Guix-patches via From: Brian Cully Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches This patch causes MODIFY-SERVICES to raise an error if a reference is made to a service which isn't in its service list. This it to help users notice if they have an invalid rule, which is currently silently ignored. * gnu/services.scm (%delete-service): new procedure (%apply-clauses): new syntax rule (%modify-service): remove syntax rule --- gnu/services.scm | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/gnu/services.scm b/gnu/services.scm index 31eba9f035..a58cffe536 100644 --- a/gnu/services.scm +++ b/gnu/services.scm @@ -296,20 +296,35 @@ (define (simple-service name target value) (description "This is a simple service.")))) (service type value))) -(define-syntax %modify-service +(define (%delete-service kind services) + (let loop ((found #f) + (return '()) + (services services)) + (match services + ('() + (if found + (values return found) + (raise (formatted-message + (G_ "modify-services: service '~a' not found in service list") + (service-type-name kind))))) + ((svc . rest) + (if (eq? (service-kind svc) kind) + (loop svc return rest) + (loop found (cons svc return) rest)))))) + +(define-syntax %apply-clauses (syntax-rules (=> delete) - ((_ svc (delete kind) clauses ...) - (if (eq? (service-kind svc) kind) - #f - (%modify-service svc clauses ...))) - ((_ service) - service) - ((_ svc (kind param => exp ...) clauses ...) - (if (eq? (service-kind svc) kind) - (let ((param (service-value svc))) - (service (service-kind svc) - (begin exp ...))) - (%modify-service svc clauses ...))))) + ((_ ((delete kind) . rest) services) + (%apply-clauses rest (%delete-service kind services))) + ((_ ((kind param => exp ...) . rest) services) + (call-with-values (lambda () (%delete-service kind services)) + (lambda (svcs found) + (let ((param (service-value found))) + (cons (service (service-kind found) + (begin exp ...)) + (%apply-clauses rest svcs)))))) + ((_ () services) + services))) (define-syntax modify-services (syntax-rules () @@ -345,10 +360,8 @@ (define-syntax modify-services UDEV-SERVICE-TYPE. This is a shorthand for (filter-map (lambda (svc) ...) %base-services)." - ((_ services clauses ...) - (filter-map (lambda (service) - (%modify-service service clauses ...)) - services)))) + ((_ services . clauses) + (%apply-clauses clauses services)))) ;;;