From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id qAVPJ39bMWD0YgAA0tVLHw (envelope-from ) for ; Sat, 20 Feb 2021 18:57:03 +0000 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id WOEHI39bMWAmMAAA1q6Kng (envelope-from ) for ; Sat, 20 Feb 2021 18:57:03 +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 BF7802925C for ; Sat, 20 Feb 2021 19:57:02 +0100 (CET) Received: from localhost ([::1]:47424 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lDXR7-0001Gb-Er for larch@yhetil.org; Sat, 20 Feb 2021 13:57:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45494) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lDXQj-0001G0-1R for emacs-orgmode@gnu.org; Sat, 20 Feb 2021 13:56:37 -0500 Received: from mout-p-101.mailbox.org ([80.241.56.151]:34372) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1lDXQg-0004GU-T6 for emacs-orgmode@gnu.org; Sat, 20 Feb 2021 13:56:36 -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-101.mailbox.org (Postfix) with ESMTPS id 4Djd2k0rp0zQlXR for ; Sat, 20 Feb 2021 19:56:30 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter04.heinlein-hosting.de (spamfilter04.heinlein-hosting.de [80.241.56.122]) (amavisd-new, port 10030) with ESMTP id zZOqXIZfh4Gt for ; Sat, 20 Feb 2021 19:56:26 +0100 (CET) From: Kevin Foley To: emacs-orgmode@gnu.org Subject: [PATCH] Add tests for org agenda bulk functions Date: Sat, 20 Feb 2021 13:56:18 -0500 Message-ID: MIME-Version: 1.0 Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-test-org-agenda.el-Test-bulk-functions.patch X-MBO-SPAM-Probability: X-Rspamd-Score: -5.80 / 15.00 / 15.00 X-Rspamd-Queue-Id: 2329117D3 X-Rspamd-UID: 076e34 Received-SPF: pass client-ip=80.241.56.151; envelope-from=kevin@kevinjfoley.me; helo=mout-p-101.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, 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: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -0.67 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: BF7802925C X-Spam-Score: -0.67 X-Migadu-Scanner: scn1.migadu.com X-TUID: xDIrX7XoOc8N >From 1f7bdcaa40ccb562c4a04bc1bd27517ca1e69bea Mon Sep 17 00:00:00 2001 From: "Kevin J. Foley" Date: Sat, 20 Feb 2021 13:42:44 -0500 Subject: [PATCH] test-org-agenda.el: Test bulk functions * testing/lisp/test-org-agenda.el (org-test-agenda-with-agenda): Create macro to setup agenda for tests. (test-org-agenda/bulk): Test that bulk actions are applied to marked items. (test-org-agenda/bulk-custom): Test that custom bulk actions are applied to marked items. (test-org-agenda/bulk-custom-arg-func): Test that argument collection function is properly called for custom bulk functions. --- testing/lisp/test-org-agenda.el | 68 +++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/testing/lisp/test-org-agenda.el b/testing/lisp/test-org-agenda.el index 7c1bfb2be..22449a73b 100644 --- a/testing/lisp/test-org-agenda.el +++ b/testing/lisp/test-org-agenda.el @@ -42,6 +42,13 @@ (defun org-test-agenda--kill-all-agendas () (mapc #'kill-buffer (org-test-agenda--agenda-buffers))) +(defmacro org-test-agenda-with-agenda (text &rest body) + (declare (indent 1)) + `(org-test-with-temp-text-in-file ,text + (let ((org-agenda-files `(,buffer-file-name))) + ,@body + (org-test-agenda--kill-all-agendas)))) + ;; Test the Agenda @@ -180,6 +187,67 @@ (ert-deftest test-org-agenda/diary-inclusion () (should (search-forward "f0bcf0cd8bad93c1451bb6e1b2aaedef5cce7cbb" nil t)) (org-test-agenda--kill-all-agendas))) +;; agenda bulk actions + +(ert-deftest test-org-agenda/bulk () + "Bulk actions are applied to marked items." + (org-test-agenda-with-agenda "* TODO a\n* TODO b" + (org-todo-list) + (org-agenda-bulk-mark-all) + (cl-letf (((symbol-function 'read-char-exclusive) + (lambda () ?t)) + ((symbol-function 'completing-read) + (lambda (&rest rest) "DONE"))) + (org-agenda-bulk-action)) + (org-agenda-previous-item 99) + (should (looking-at ".*DONE a")) + (org-agenda-next-item 1) + (should (looking-at ".*DONE b")))) + +(ert-deftest test-org-agenda/bulk-custom () + "Custom bulk actions are applied to all marked items." + (org-test-agenda-with-agenda "* TODO a\n* TODO b" + (org-todo-list) + (org-agenda-bulk-mark-all) + + ;; Mock read functions + (let* ((f-call-cnt 0) + (org-agenda-bulk-custom-functions + `((?P ,(lambda () (setq f-call-cnt (1+ f-call-cnt))))))) + (cl-letf* (((symbol-function 'read-char-exclusive) + (lambda () ?P))) + (org-agenda-bulk-action) + (should (= f-call-cnt 2)))))) + +(ert-deftest test-org-agenda/bulk-custom-arg-func () + "Argument collection functions can be specified for custom bulk +functions." + (org-test-agenda-with-agenda "* TODO a\n* TODO b" + (org-todo-list) + (org-agenda-bulk-mark-all) + (let* ((f-called-cnt 0) + (arg-f-call-cnt 0) + (f-called-args nil) + (org-agenda-bulk-custom-functions + `((?P + ;; Custom bulk function + ,(lambda (&rest args) + (message "test" args) + (setq f-called-cnt (1+ f-called-cnt) + + f-called-args args)) + ;; Argument collection function + ,(lambda () + (setq arg-f-call-cnt (1+ arg-f-call-cnt)) + '(1 2 3)))))) + (cl-letf (((symbol-function 'read-char-exclusive) + (lambda () ?P))) + (org-agenda-bulk-action)) + (should (= f-called-cnt 2)) + (should (= arg-f-call-cnt 1)) + (should (equal f-called-args '(1 2 3)))))) + + (provide 'test-org-agenda) -- 2.28.0