From unknown Sun Jun 22 00:20:41 2025 X-Loop: help-debbugs@gnu.org Subject: bug#31336: 27.0.50; [RFC] Gnus mock testing sessions Resent-From: Eric Abrahamsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 01 May 2018 22:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 31336 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: 31336@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.15252119617252 (code B ref -1); Tue, 01 May 2018 22:00:02 +0000 Received: (at submit) by debbugs.gnu.org; 1 May 2018 21:59:21 +0000 Received: from localhost ([127.0.0.1]:46163 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fDdIr-0001sq-MV for submit@debbugs.gnu.org; Tue, 01 May 2018 17:59:21 -0400 Received: from eggs.gnu.org ([208.118.235.92]:35834) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fDdIn-0001sb-2Z for submit@debbugs.gnu.org; Tue, 01 May 2018 17:59:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fDdIe-0007Xt-1A for submit@debbugs.gnu.org; Tue, 01 May 2018 17:59:07 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:36043) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fDdId-0007Xp-Sc for submit@debbugs.gnu.org; Tue, 01 May 2018 17:59:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55011) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDdIZ-0002FR-Rc for bug-gnu-emacs@gnu.org; Tue, 01 May 2018 17:59:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fDdIV-0007UZ-9e for bug-gnu-emacs@gnu.org; Tue, 01 May 2018 17:58:59 -0400 Received: from mail.ericabrahamsen.net ([50.56.99.223]:49554) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fDdIU-0007Ty-SC for bug-gnu-emacs@gnu.org; Tue, 01 May 2018 17:58:55 -0400 Received: from localhost (174-21-181-71.tukw.qwest.net [174.21.181.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: eric@ericabrahamsen.net) by mail.ericabrahamsen.net (Postfix) with ESMTPSA id AAB9EC14DD for ; Tue, 1 May 2018 21:58:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mail.ericabrahamsen.net; s=mail; t=1525211932; bh=gN5Cuk7ROdm9iITTEv/66Lu9qgAu5QsB320Tkp1mvWo=; h=From:To:Subject:Date:From; b=xY7L5lgg1aoDeAFZK9QIrmdEu9YPhy5mMA4NiWgPhneFdFtBGQt+wambRQ/4ss6QA IuNLp1IVjYqkIXD9XUEGtHr9Cjki46l4pkgyNTI8PTCEgqa2tTjQMnwlFt3dTE14hW AoxI4+3xYI4BZhPsxe7SYrD2rZVs5Yx+NDK4p+E8= From: Eric Abrahamsen Date: Tue, 01 May 2018 14:56:11 -0700 Message-ID: <87d0yff3b8.fsf@ericabrahamsen.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.1 (----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.1 (-----) --=-=-= Content-Type: text/plain Something I've wanted for a while is a fake Gnus session that I can use for testing, since it's very hard to get Gnus up and running meaningfully without substantial customization. So I made the attached "gnus-mock.el" library. You start "emacs -Q", run `gnus-mock', and get a repeatable trashable Gnus session you can use for testing. What I did was put a basic Gnus installation under ./test/data/gnus/mock, and every time you start a mock session that installation gets copied to a temporary directory, and Gnus operates out of that directory for the duration of the session. You can abuse it however you like, and then when you quit it gets cleaned up. It has some hard-coded config (at present, just one nnmaildir server), and you have the option of laying your own config over that. It seems to work just fine. I can imagine all kinds of things we could do with this, but I wanted to float this here before I went any further, to get some feedback. Some things: 1. Ideally we'd have a bunch of messages in there, which can serve as sort of regression tests, and may also be useful for unit tests as well. Is there any concern about the size of data? My understanding is that this data will be discarded in an actual install, so maybe it doesn't matter so much? 2. I'm currently using `source-directory' to find the data dir. I guess, if we're expecting this only to be used for development in the source tree, then that's okay. 3. Locally, I wrote a python one-liner as a dummy `sendmail-program', that just returns a 0 exit code. A python script isn't really practical, and also I haven't done anything for the other mail sending protocols. What I'd really like is a little executable that accepts the message, and then sticks it in yet another directory within the temp installation. Then we can point `mail-sources' to that, and have a little boomerang where all sent messages come back to you. 4. It's not possible to pre-configure directory-based servers in `gnus-server-alist', as the directory paths need to be absolute, and at present they change every time `gnus-mock' is started. Not a tragedy, though. I've attached the gnus-mock code, and the dummy .gnus.el config file -- later, once there's some feedback on this, I can push a branch that contains the whole data dir. Hope this is welcome, Eric --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=gnus-mock.el ;;; gnus-mock.el --- Mock Gnus installation for testing -*- lexical-binding: t; -*- ;; Copyright (C) 2018 Free Software Foundation ;; Author: Eric Abrahamsen ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;; This module provides a reproducible mock Gnus installation, ;; including dummy data, that can be used for Gnus development and ;; testing. Start the mock Gnus session with either `gnus-mock' or ;; `gnus-mock-unplugged'. Nothing in the mock sessions will make a ;; network connection, and mail sending is stubbed out using ;; `gnus-mock-sendmail-program'. ;; The mock session starts with a predefined nnmaildir server, as well ;; as some dummy mail data. Other predefined servers may be added in ;; the future. At startup, all dummy data is copied into a temporary ;; directory. At shutdown, the temporary directory is deleted. ;; A special config file is used for the mock session; users may add ;; to this config, or shadow its options, by setting ;; `gnus-mock-settings-file' to the name of an additional config file. ;;; Code: (require 'gnus) (require 'message) (defgroup gnus-mock nil "Options for the mock Gnus installation." :group 'gnus :version "27.1") (defcustom gnus-mock-settings-file nil "Path to an additional config file for mock Gnus. The contents of this file will be appended to gnus-mock's own config file before Gnus startup, in effect shadowing config values in the default file." :group 'gnus-mock :type 'file) (defcustom gnus-mock-data-dir (expand-file-name "test/data/gnus/mock" source-directory) "Source directory for Gnus mock data." :group 'gnus-mock :type 'string) (defcustom gnus-mock-cleanup-p t "When non-nil, delete temporary files after shutdown. Each Gnus mock session will create a new temporary directory, so multiple sessions will not conflict if this option is nil." :group 'gnus-mock :type 'boolean) (defcustom gnus-mock-sendmail-program (nnheader-concat gnus-mock-data-dir "fakesendmail.py") "Program used as the value of `sendmail-program'." :group 'gnus-mock :type 'string) ;; Regular Gnus can also check this, in case of a "dirty" mock ;; session. (defvar gnus-mock-p nil "Non-nil during a mocked Gnus session.") (defun gnus-mock-setup () "Set up mock data and config." (let ((mock-tmp-dir (make-temp-file "emacs-gnus-mock-" t))) (setq gnus-home-directory mock-tmp-dir gnus-directory (nnheader-concat gnus-home-directory "News") gnus-agent-directory (nnheader-concat gnus-directory "agent/") nndraft-directory (nnheader-concat gnus-directory "drafts/") gnus-init-file (nnheader-concat gnus-home-directory ".gnus") gnus-startup-file (nnheader-concat gnus-home-directory ".newsrc") message-directory gnus-home-directory sendmail-program gnus-mock-sendmail-program ;; If Emacs was started with -Q, as it should have been, ;; `init-file-user' will be nil which will prevent reading of ;; `gnus-init-file'. init-file-user "gnus-mock") ;; Put our data and config in place. (copy-directory gnus-mock-data-dir (file-name-as-directory gnus-home-directory) nil nil t) ;; Possibly insert additional config. (when gnus-mock-settings-file (with-temp-buffer (insert-file-contents gnus-mock-settings-file) (append-to-file (point-min) (point-max) gnus-init-file))))) ;;;###autoload (defun gnus-mock-unplugged () "Start an unplugged mock Gnus session." (interactive) (gnus-mock t)) ;;;###autoload (defun gnus-mock (&optional unplugged) "Start a mock Gnus session." (interactive) (when (gnus-alive-p) (error "First save and quit your running Gnus session")) (gnus-mock-setup) (when unplugged (setq gnus-plugged nil)) (setq gnus-mock-p t) (gnus) (add-hook 'gnus-after-exiting-gnus-hook #'gnus-mock-restore)) (defun gnus-mock-restore () "Restore after quitting a mock Gnus session." (when gnus-mock-p (when gnus-mock-cleanup-p (delete-directory gnus-home-directory t)) (setq gnus-mock-p nil) (remove-hook 'gnus-after-exiting-gnus-hook #'gnus-mock-restore))) (provide 'gnus-mock) ;;; gnus-mock.el ends here --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=.gnus.el ;;; Settings for Gnus mock sessions. Do not edit this file, instead ;;; add further customizations to the file indicated by ;;; `gnus-mock-settings-file'. (setq gnus-select-method '(nnmaildir "Test" (directory (expand-file-name "test" gnus-home-directory)))) (setq user-mail-address "mockturtle@gnus.org") (setq user-full-name "Mock Turtle") (setq message-send-mail-function #'message-send-mail-with-sendmail) --=-=-=-- From unknown Sun Jun 22 00:20:41 2025 X-Loop: help-debbugs@gnu.org Subject: bug#31336: [RFC] Gnus mock testing sessions References: <87d0yff3b8.fsf@ericabrahamsen.net> In-Reply-To: <87d0yff3b8.fsf@ericabrahamsen.net> Resent-From: Eric Abrahamsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 09 May 2018 18:30:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 31336 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: 31336@debbugs.gnu.org Received: via spool by 31336-submit@debbugs.gnu.org id=B31336.152589060016834 (code B ref 31336); Wed, 09 May 2018 18:30:02 +0000 Received: (at 31336) by debbugs.gnu.org; 9 May 2018 18:30:00 +0000 Received: from localhost ([127.0.0.1]:55551 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fGTqh-0004NR-Ko for submit@debbugs.gnu.org; Wed, 09 May 2018 14:29:59 -0400 Received: from mail.ericabrahamsen.net ([50.56.99.223]:55416) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fGTqg-0004NJ-0P for 31336@debbugs.gnu.org; Wed, 09 May 2018 14:29:58 -0400 Received: from localhost (174-21-181-71.tukw.qwest.net [174.21.181.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: eric@ericabrahamsen.net) by mail.ericabrahamsen.net (Postfix) with ESMTPSA id D42F0C1637 for <31336@debbugs.gnu.org>; Wed, 9 May 2018 18:29:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mail.ericabrahamsen.net; s=mail; t=1525890597; bh=Ihf8TgQ8x1EKjI9zfweJY/PoszKjpbo/tbKRZu6wMhY=; h=From:To:Subject:Date:From; b=taLasD8RdQ2xNde6eGtdnx8w/xKKLMV9mSpy58ctcjYnpACtpwTJqBPfb1UKpxcD5 M8gINyZHL21kU+FWSBQoKMnUIHYz6KmD8rori9PD9YOSmKBK905dR8TUcL27gay0vl gAUzzd6dLc6gixqdsgsRvOZCFZBhU5+qzVBw/pQE= From: Eric Abrahamsen Date: Wed, 09 May 2018 11:29:56 -0700 Message-ID: <87603wfzrv.fsf@ericabrahamsen.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hmm, given the crickets here, maybe this would be better off as an ELPA package? From unknown Sun Jun 22 00:20:41 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Eric Abrahamsen Subject: bug#31336: closed ([RFC] Gnus mock testing sessions) Message-ID: References: <87efcz6miy.fsf@ericabrahamsen.net> <87d0yff3b8.fsf@ericabrahamsen.net> X-Gnu-PR-Message: they-closed 31336 X-Gnu-PR-Package: emacs Reply-To: 31336@debbugs.gnu.org Date: Tue, 09 Oct 2018 17:47:05 +0000 Content-Type: multipart/mixed; boundary="----------=_1539107225-26183-1" This is a multi-part message in MIME format... ------------=_1539107225-26183-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #31336: 27.0.50; [RFC] Gnus mock testing sessions which was filed against the emacs package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 31336@debbugs.gnu.org. --=20 31336: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D31336 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1539107225-26183-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 31336-done) by debbugs.gnu.org; 9 Oct 2018 17:46:33 +0000 Received: from localhost ([127.0.0.1]:42518 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g9w5Z-0006nc-H1 for submit@debbugs.gnu.org; Tue, 09 Oct 2018 13:46:33 -0400 Received: from mail.ericabrahamsen.net ([50.56.99.223]:38491) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g9w5Y-0006nV-7k for 31336-done@debbugs.gnu.org; Tue, 09 Oct 2018 13:46:32 -0400 Received: from localhost (97-113-224-119.tukw.qwest.net [97.113.224.119]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: eric@ericabrahamsen.net) by mail.ericabrahamsen.net (Postfix) with ESMTPSA id 6C9B9403D8 for <31336-done@debbugs.gnu.org>; Tue, 9 Oct 2018 17:46:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mail.ericabrahamsen.net; s=mail; t=1539107191; bh=wMvayFWnA801Yyu4Iy2Wuf8AqxGJRSMV4yjEAzssS60=; h=From:To:Subject:Date:From; b=JfTIcBacVXsWyBPV1a8Qra14cJvnfVwUX6xBZGnicT8X/vRKMFK2BAKB31uAnLXkJ ZLtjjyT1K26lZYONuc0bB9G1ixEi1IPsXpHKZQtqaaYSGpPq8Jp6CH21PaHY1dsWWB jNBPokgC090ia6JJlrKyccJM2/I/ZkfhPY1CvCSI= From: Eric Abrahamsen To: 31336-done@debbugs.gnu.org Subject: [RFC] Gnus mock testing sessions Date: Tue, 09 Oct 2018 10:46:29 -0700 Message-ID: <87efcz6miy.fsf@ericabrahamsen.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 31336-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) I'm just going to propose this as an Elpa package. ------------=_1539107225-26183-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 1 May 2018 21:59:21 +0000 Received: from localhost ([127.0.0.1]:46163 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fDdIr-0001sq-MV for submit@debbugs.gnu.org; Tue, 01 May 2018 17:59:21 -0400 Received: from eggs.gnu.org ([208.118.235.92]:35834) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fDdIn-0001sb-2Z for submit@debbugs.gnu.org; Tue, 01 May 2018 17:59:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fDdIe-0007Xt-1A for submit@debbugs.gnu.org; Tue, 01 May 2018 17:59:07 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:36043) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fDdId-0007Xp-Sc for submit@debbugs.gnu.org; Tue, 01 May 2018 17:59:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55011) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDdIZ-0002FR-Rc for bug-gnu-emacs@gnu.org; Tue, 01 May 2018 17:59:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fDdIV-0007UZ-9e for bug-gnu-emacs@gnu.org; Tue, 01 May 2018 17:58:59 -0400 Received: from mail.ericabrahamsen.net ([50.56.99.223]:49554) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fDdIU-0007Ty-SC for bug-gnu-emacs@gnu.org; Tue, 01 May 2018 17:58:55 -0400 Received: from localhost (174-21-181-71.tukw.qwest.net [174.21.181.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: eric@ericabrahamsen.net) by mail.ericabrahamsen.net (Postfix) with ESMTPSA id AAB9EC14DD for ; Tue, 1 May 2018 21:58:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mail.ericabrahamsen.net; s=mail; t=1525211932; bh=gN5Cuk7ROdm9iITTEv/66Lu9qgAu5QsB320Tkp1mvWo=; h=From:To:Subject:Date:From; b=xY7L5lgg1aoDeAFZK9QIrmdEu9YPhy5mMA4NiWgPhneFdFtBGQt+wambRQ/4ss6QA IuNLp1IVjYqkIXD9XUEGtHr9Cjki46l4pkgyNTI8PTCEgqa2tTjQMnwlFt3dTE14hW AoxI4+3xYI4BZhPsxe7SYrD2rZVs5Yx+NDK4p+E8= From: Eric Abrahamsen To: bug-gnu-emacs@gnu.org Subject: 27.0.50; [RFC] Gnus mock testing sessions Date: Tue, 01 May 2018 14:56:11 -0700 Message-ID: <87d0yff3b8.fsf@ericabrahamsen.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.1 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.1 (-----) --=-=-= Content-Type: text/plain Something I've wanted for a while is a fake Gnus session that I can use for testing, since it's very hard to get Gnus up and running meaningfully without substantial customization. So I made the attached "gnus-mock.el" library. You start "emacs -Q", run `gnus-mock', and get a repeatable trashable Gnus session you can use for testing. What I did was put a basic Gnus installation under ./test/data/gnus/mock, and every time you start a mock session that installation gets copied to a temporary directory, and Gnus operates out of that directory for the duration of the session. You can abuse it however you like, and then when you quit it gets cleaned up. It has some hard-coded config (at present, just one nnmaildir server), and you have the option of laying your own config over that. It seems to work just fine. I can imagine all kinds of things we could do with this, but I wanted to float this here before I went any further, to get some feedback. Some things: 1. Ideally we'd have a bunch of messages in there, which can serve as sort of regression tests, and may also be useful for unit tests as well. Is there any concern about the size of data? My understanding is that this data will be discarded in an actual install, so maybe it doesn't matter so much? 2. I'm currently using `source-directory' to find the data dir. I guess, if we're expecting this only to be used for development in the source tree, then that's okay. 3. Locally, I wrote a python one-liner as a dummy `sendmail-program', that just returns a 0 exit code. A python script isn't really practical, and also I haven't done anything for the other mail sending protocols. What I'd really like is a little executable that accepts the message, and then sticks it in yet another directory within the temp installation. Then we can point `mail-sources' to that, and have a little boomerang where all sent messages come back to you. 4. It's not possible to pre-configure directory-based servers in `gnus-server-alist', as the directory paths need to be absolute, and at present they change every time `gnus-mock' is started. Not a tragedy, though. I've attached the gnus-mock code, and the dummy .gnus.el config file -- later, once there's some feedback on this, I can push a branch that contains the whole data dir. Hope this is welcome, Eric --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=gnus-mock.el ;;; gnus-mock.el --- Mock Gnus installation for testing -*- lexical-binding: t; -*- ;; Copyright (C) 2018 Free Software Foundation ;; Author: Eric Abrahamsen ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;; This module provides a reproducible mock Gnus installation, ;; including dummy data, that can be used for Gnus development and ;; testing. Start the mock Gnus session with either `gnus-mock' or ;; `gnus-mock-unplugged'. Nothing in the mock sessions will make a ;; network connection, and mail sending is stubbed out using ;; `gnus-mock-sendmail-program'. ;; The mock session starts with a predefined nnmaildir server, as well ;; as some dummy mail data. Other predefined servers may be added in ;; the future. At startup, all dummy data is copied into a temporary ;; directory. At shutdown, the temporary directory is deleted. ;; A special config file is used for the mock session; users may add ;; to this config, or shadow its options, by setting ;; `gnus-mock-settings-file' to the name of an additional config file. ;;; Code: (require 'gnus) (require 'message) (defgroup gnus-mock nil "Options for the mock Gnus installation." :group 'gnus :version "27.1") (defcustom gnus-mock-settings-file nil "Path to an additional config file for mock Gnus. The contents of this file will be appended to gnus-mock's own config file before Gnus startup, in effect shadowing config values in the default file." :group 'gnus-mock :type 'file) (defcustom gnus-mock-data-dir (expand-file-name "test/data/gnus/mock" source-directory) "Source directory for Gnus mock data." :group 'gnus-mock :type 'string) (defcustom gnus-mock-cleanup-p t "When non-nil, delete temporary files after shutdown. Each Gnus mock session will create a new temporary directory, so multiple sessions will not conflict if this option is nil." :group 'gnus-mock :type 'boolean) (defcustom gnus-mock-sendmail-program (nnheader-concat gnus-mock-data-dir "fakesendmail.py") "Program used as the value of `sendmail-program'." :group 'gnus-mock :type 'string) ;; Regular Gnus can also check this, in case of a "dirty" mock ;; session. (defvar gnus-mock-p nil "Non-nil during a mocked Gnus session.") (defun gnus-mock-setup () "Set up mock data and config." (let ((mock-tmp-dir (make-temp-file "emacs-gnus-mock-" t))) (setq gnus-home-directory mock-tmp-dir gnus-directory (nnheader-concat gnus-home-directory "News") gnus-agent-directory (nnheader-concat gnus-directory "agent/") nndraft-directory (nnheader-concat gnus-directory "drafts/") gnus-init-file (nnheader-concat gnus-home-directory ".gnus") gnus-startup-file (nnheader-concat gnus-home-directory ".newsrc") message-directory gnus-home-directory sendmail-program gnus-mock-sendmail-program ;; If Emacs was started with -Q, as it should have been, ;; `init-file-user' will be nil which will prevent reading of ;; `gnus-init-file'. init-file-user "gnus-mock") ;; Put our data and config in place. (copy-directory gnus-mock-data-dir (file-name-as-directory gnus-home-directory) nil nil t) ;; Possibly insert additional config. (when gnus-mock-settings-file (with-temp-buffer (insert-file-contents gnus-mock-settings-file) (append-to-file (point-min) (point-max) gnus-init-file))))) ;;;###autoload (defun gnus-mock-unplugged () "Start an unplugged mock Gnus session." (interactive) (gnus-mock t)) ;;;###autoload (defun gnus-mock (&optional unplugged) "Start a mock Gnus session." (interactive) (when (gnus-alive-p) (error "First save and quit your running Gnus session")) (gnus-mock-setup) (when unplugged (setq gnus-plugged nil)) (setq gnus-mock-p t) (gnus) (add-hook 'gnus-after-exiting-gnus-hook #'gnus-mock-restore)) (defun gnus-mock-restore () "Restore after quitting a mock Gnus session." (when gnus-mock-p (when gnus-mock-cleanup-p (delete-directory gnus-home-directory t)) (setq gnus-mock-p nil) (remove-hook 'gnus-after-exiting-gnus-hook #'gnus-mock-restore))) (provide 'gnus-mock) ;;; gnus-mock.el ends here --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=.gnus.el ;;; Settings for Gnus mock sessions. Do not edit this file, instead ;;; add further customizations to the file indicated by ;;; `gnus-mock-settings-file'. (setq gnus-select-method '(nnmaildir "Test" (directory (expand-file-name "test" gnus-home-directory)))) (setq user-mail-address "mockturtle@gnus.org") (setq user-full-name "Mock Turtle") (setq message-send-mail-function #'message-send-mail-with-sendmail) --=-=-=-- ------------=_1539107225-26183-1--