From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id oawZGI0CK2A0PwAA0tVLHw (envelope-from ) for ; Mon, 15 Feb 2021 23:23:57 +0000 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id 0MJUE40CK2DWbwAAB5/wlQ (envelope-from ) for ; Mon, 15 Feb 2021 23:23:57 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id C90FF20CE8 for ; Tue, 16 Feb 2021 00:23:56 +0100 (CET) Received: from localhost ([::1]:38366 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lBnDe-0005FQ-3R for larch@yhetil.org; Mon, 15 Feb 2021 18:23:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45814) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lBnBt-0004PA-BG for emacs-orgmode@gnu.org; Mon, 15 Feb 2021 18:22:05 -0500 Received: from mout-p-103.mailbox.org ([2001:67c:2050::465:103]:52628) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1lBnBq-0007Zz-Sy for emacs-orgmode@gnu.org; Mon, 15 Feb 2021 18:22:04 -0500 Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-103.mailbox.org (Postfix) with ESMTPS id 4Dfg9M2bcrzQkQh for ; Tue, 16 Feb 2021 00:21:59 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter01.heinlein-hosting.de (spamfilter01.heinlein-hosting.de [80.241.56.115]) (amavisd-new, port 10030) with ESMTP id DshHQ3nOEc4Y for ; Tue, 16 Feb 2021 00:21:55 +0100 (CET) From: Kevin Foley To: emacs-orgmode@gnu.org Subject: Assistance Writing Test for Org Agenda Custom Bulk Function Date: Mon, 15 Feb 2021 18:21:50 -0500 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-MBO-SPAM-Probability: X-Rspamd-Score: -6.53 / 15.00 / 15.00 X-Rspamd-Queue-Id: 2AE2E17D3 X-Rspamd-UID: 65470c Received-SPF: pass client-ip=2001:67c:2050::465:103; envelope-from=kevin@kevinjfoley.me; helo=mout-p-103.mailbox.org X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, 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: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -2.36 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: C90FF20CE8 X-Spam-Score: -2.36 X-Migadu-Scanner: scn0.migadu.com X-TUID: +hmSiSuntuRi I'm trying write a test for a recently merged patch[1]. The patch adds the ability for users to specify a function to collect args to be passed to a custom bulk function. I'm trying to mock the argument collecting function and the custom bulk function and then test that the arguments returned from the former are passed to the latter. I'd also like to test the argument function is only called once while the bulk function is called multiple times. Here is an example of what I'm trying to do: (org-test-with-temp-text-in-file "* TODO a\n*TODO b" (let ((org-agenda-files `(,(buffer-file-name)))) (org-todo-list) (org-agenda-bulk-mark-all) ;; Fails without these ;; (defvar f-called-cnt) ;; (defvar arg-f-call-cnt) ;; (defvar f-called-args) (let ((f-called-cnt 0) (arg-f-call-cnt 0) (f-called-args nil)) (cl-letf (((symbol-function 'read-char-exclusive) (lambda () ?P)) (org-agenda-bulk-custom-functions '((?P (lambda (&rest args) (message "test" args) (setq f-called-cnt (1+ f-called-cnt) f-called-args args)) (lambda () (setq arg-f-call-cnt (1+ arg-f-call-cnt)) '(1 2 3)))))) (org-agenda-bulk-action) (org-test-agenda--kill-all-agendas) (should (= f-called-cnt 2)) (should (= arg-f-call-cnt 1)) (should (equal f-called-args '(1 2 3))))))) However, this fails with the error void-variable unless I first define the variables for storing the call counts/arguments. I understand that defvar makes the variables dynamically bound, however I'm struggling to understand why that's needed here. I've read the manual entries on variable binding but I seem to be missing something. Can someone help me understand what's going on here? Also, is there a better way to approach this? [1] https://code.orgmode.org/bzg/org-mode/commit/885ee086dde4ec2a9e303ff101e55d55c4b2363f