From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.bugs Subject: bug#31336: 27.0.50; [RFC] Gnus mock testing sessions Date: Tue, 01 May 2018 14:56:11 -0700 Message-ID: <87d0yff3b8.fsf@ericabrahamsen.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1525211892 20536 195.159.176.226 (1 May 2018 21:58:12 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 1 May 2018 21:58:12 +0000 (UTC) To: 31336@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue May 01 23:58:08 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fDdHj-000593-4Z for geb-bug-gnu-emacs@m.gmane.org; Tue, 01 May 2018 23:58:07 +0200 Original-Received: from localhost ([::1]:46350 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDdJo-0002TQ-Bq for geb-bug-gnu-emacs@m.gmane.org; Tue, 01 May 2018 18:00:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55234) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDdJh-0002Qt-4S for bug-gnu-emacs@gnu.org; Tue, 01 May 2018 18:00:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fDdJa-0007pn-Qr for bug-gnu-emacs@gnu.org; Tue, 01 May 2018 18:00:09 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:38266) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fDdJa-0007pj-Lw for bug-gnu-emacs@gnu.org; Tue, 01 May 2018 18:00:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fDdJa-0001uN-FW for bug-gnu-emacs@gnu.org; Tue, 01 May 2018 18:00:02 -0400 X-Loop: help-debbugs@gnu.org 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: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.15252119617252 (code B ref -1); Tue, 01 May 2018 22:00:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 1 May 2018 21:59:21 +0000 Original-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 Original-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 Original-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 Original-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 Original-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 Original-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 Original-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 Original-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= 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-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:145909 Archived-At: --=-=-= 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) --=-=-=--