From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id YHj0GRrmLWC8MQAA0tVLHw (envelope-from ) for ; Thu, 18 Feb 2021 03:59:22 +0000 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id 4HmuFRrmLWDIPAAAbx9fmQ (envelope-from ) for ; Thu, 18 Feb 2021 03:59:22 +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 C46342F6D1 for ; Thu, 18 Feb 2021 04:59:21 +0100 (CET) Received: from localhost ([::1]:42846 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lCaTI-00020w-Up for larch@yhetil.org; Wed, 17 Feb 2021 22:59:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57832) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lCaSn-00020X-Fk for emacs-orgmode@gnu.org; Wed, 17 Feb 2021 22:58:49 -0500 Received: from out2.migadu.com ([188.165.223.204]:43209) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lCaSk-0002Tt-0K for emacs-orgmode@gnu.org; Wed, 17 Feb 2021 22:58:49 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kyleam.com; s=key1; t=1613620723; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gbvs88i+y5tBkW30hrA1RTclU1au4IxYQNhRFodCkQQ=; b=os2E/Vx1jNLInXfLF5Xr9jqtyHJM+nvttC1ffxSgdVWltAjXegV2ZO0HN7RShnX24c8dE1 ++EhNDuiWswOkYBGBBEsbAztzzTM1pxG3YbR6E9t08kDKatRYEtIZF019lJ4uJx9GGqtKb 0nTzif/hmFH+lPDr4S0V2ZchAvPm6THE1KO9SSFbWkWS2ksuchLNqrSJ60sN1lezQw/7Xc iufV7NmujUmjUPpmm80VyVDPdXMBV4b1ctML8q7B38SXmHqNA7M404kSYSEiyB9HzVIxfF TC/mUPBZ+yW1uHhS4il+mQ6ZgsEZW4nly+3CGVArU3TBDZav8wwVSZ4IeGYdpQ== From: Kyle Meyer To: Kevin Foley Subject: Re: Assistance Writing Test for Org Agenda Custom Bulk Function In-Reply-To: References: Date: Wed, 17 Feb 2021 22:58:41 -0500 Message-ID: <87wnv62fim.fsf@kyleam.com> MIME-Version: 1.0 Content-Type: text/plain X-Migadu-Auth-User: kyle@kyleam.com Received-SPF: pass client-ip=188.165.223.204; envelope-from=kyle@kyleam.com; helo=out2.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , Cc: emacs-orgmode@gnu.org Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -2.56 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=kyleam.com header.s=key1 header.b="os2E/Vx1"; 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: C46342F6D1 X-Spam-Score: -2.56 X-Migadu-Scanner: scn1.migadu.com X-TUID: zFWiM6ozrkRF Kevin Foley writes: > 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" Unrelated note: there's a missing a space between the second "*" and "TODO". [...] > (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? Perhaps you're not capturing the environment due to your quoting: ;; -*- lexical-binding: t; -*- (let ((x 0)) '(t (lambda () x))) ;; => (y (lambda nil x)) (let ((x 0)) (list t (lambda () x))) ;; => (t (closure ((x . 0) t) nil x)) So try something like (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))))) or (org-agenda-bulk-custom-functions (list (list ?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)))))