From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:267::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms12 with LMTPS id 77IOHV6pC2DKNAAAsNZ9tg (envelope-from ); Sat, 23 Jan 2021 04:43:10 +0000 Received: from out0.migadu.com ([2001:41d0:2:267::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id QCyBOlypC2B4TwAAbx9fmQ (envelope-from ); Sat, 23 Jan 2021 04:43:08 +0000 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=1611376988; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=pOPRtWkooi5TX0fdZOkPU210rlH35CHORUTC8YqecLM=; b=argbv7W/oMtM8kdc3al+sSssRLfn/1Oo9SyvUfbJCQadzOT9alVY1n1OoYA+v00kwPu+HL kpyOdtk7AuHcqybKVX8tt7YFPju+x2yaCkIjgajafcanxlHwlxek/fQmbSDsOkefLUfHe+ xSDzM8/p+yeNPiHqk+4wExYz+WCZyaFP1Z6nV/K03N/DSLS4TJpEpVJ0eZWFKC+nvelt+p pljL7uZ5q3Zrv6WNPD97iDh5UTPOwlkPiP9XPyOf5pqbIr1FJU/qN/+u/es4hgn3e2v/4l Zqx3HjCBIwCdfMVEBmUi8I43v2+y87oVhspyQjXBTC8Hyxxyij/+PLuup+lJvw== From: Kyle Meyer To: piem@inbox.kyleam.com Subject: [PATCH] Add a few basic tests Date: Fri, 22 Jan 2021 23:43:00 -0500 Message-Id: <20210123044300.31326-1-kyle@kyleam.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: kyle@kyleam.com X-TUID: imGtT6EVKQ5a The more interesting things will involve more work and setup to test, but at least start testing some simple things. This project's Makefile was originally based off of Elfeed's, and the changes from this commit are adapted from there as well. --- Makefile | 10 ++++- tests/piem-tests.el | 104 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 tests/piem-tests.el diff --git a/Makefile b/Makefile index 6ea8472..a139d1a 100644 --- a/Makefile +++ b/Makefile @@ -2,16 +2,21 @@ EMACS = emacs # Rely on EMACSLOADPATH for everything but the current directory. -BATCH = $(EMACS) --batch -Q -L . +BATCH = $(EMACS) --batch -Q -L . -L tests EL = piem.el piem-b4.el piem-elfeed.el piem-eww.el piem-gnus.el \ - piem-maildir.el piem-notmuch.el + piem-maildir.el piem-notmuch.el \ + tests/piem-tests.el ELC = $(EL:.el=.elc) all: compile piem.info piem-autoloads.el compile: $(ELC) +check: test +test: $(ELC) + $(BATCH) -l tests/piem-tests.elc -f ert-run-tests-batch + piem-autoloads.el: $(EL) $(BATCH) -l package --eval \ '(package-generate-autoloads "piem" default-directory)' @@ -31,6 +36,7 @@ piem-gnus.elc: piem-gnus.el piem.elc piem-maildir.elc: piem-maildir.el piem-notmuch.elc: piem-notmuch.el piem.elc piem.elc: piem.el piem-maildir.elc +tests/piem-tests.elc: tests/piem-tests.el piem.elc .SUFFIXES: .el .elc .texi .info .html diff --git a/tests/piem-tests.el b/tests/piem-tests.el new file mode 100644 index 0000000..346f9e1 --- /dev/null +++ b/tests/piem-tests.el @@ -0,0 +1,104 @@ +;;; piem-tests.el --- tests for piem -*- lexical-binding: t; -*- + +;; Copyright (C) 2021 Kyle Meyer + +;; Author: Kyle Meyer + +;; 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 . + +;;; Code: + +(require 'ert) +(require 'piem) + +(ert-deftest piem-message-link-re () + (should-not (string-match-p + (piem-message-link-re "https://example.com/inbox") + "https://example.com/inbox")) + (should (string-match-p + (piem-message-link-re "https://example.com/inbox") + "https://example.com/inbox/msg@id/")) + (should-not (string-match-p + (piem-message-link-re "https://example.com/inbox" "msg@id1") + "https://example.com/inbox/msg@id/")) + (should (string-match-p + (piem-message-link-re "https://example.com/inbox/") + "https://example.com/inbox/msg@id/T/#t")) + (should (string-match-p + (piem-message-link-re "https://example.com/inbox/") + "https://example.com/inbox/msg@id/T/#r53974723fd9")) + (should (string-match-p + (piem-message-link-re "https://example.com/inbox/") + "https://example.com/inbox/msg@id/T/#r53974723fd9")) + (should (string-match-p + (piem-message-link-re "https://example.com/inbox/") + "https://example.com/inbox/msg@id/t/#ma0d6f35c094"))) + +(ert-deftest piem-escape-mid () + (should (equal (piem-escape-mid "msg@id") "msg@id")) + (should (equal (piem-escape-mid "m/g@id") "m%2Fg@id"))) + +(ert-deftest piem-name-branch-who-what-v () + (should (equal (piem-name-branch-who-what-v + (list :from "Foo Bar " + :subject "[PATCH] Do a thing")) + "fb/do-thing")) + (should (equal (piem-name-branch-who-what-v + (list :from "Foo " + :subject "[PATCH] Do a thing")) + "f/do-thing")) + (should (equal (piem-name-branch-who-what-v + (list :from "Foo Bar " + :subject "[PATCH v3] Do a thing")) + "fb/do-thing__v3")) + (should-not (piem-name-branch-who-what-v + (list :from "Foo Bar ")))) + +(ert-deftest piem--insert-message-id-header () + (should-not + (with-temp-buffer + (piem--insert-message-id-header "msg@id"))) + (should + (string-match-p + (concat + (rx "Subject: [PATCH 1/2] a\nMessage-Id: \n" + (one-or-more anychar) + "Subject: [PATCH 2/2] b\nMessage-Id: \n")) + (with-temp-buffer + (insert "\ +From 0d732713af1f3fb48b37430e2cd0a3033cea14f3 Mon Sep 17 00:00:00 2001 +From: Foo Bar +Date: Fri, 22 Jan 2021 22:35:58 -0500 +Subject: [PATCH 1/2] a + +--- + a | 1 + + 1 file changed, 1 insertion(+) + create mode 100644 a + +From 7b2433ead6d8d10bff3325cb3719a316ddb52392 Mon Sep 17 00:00:00 2001 +From: Foo Bar +Date: Fri, 22 Jan 2021 22:36:09 -0500 +Subject: [PATCH 2/2] b + +--- + b | 1 + + 1 file changed, 1 insertion(+) + create mode 100644 b") + (goto-char (point-min)) + (piem--insert-message-id-header "msg@id") + (buffer-string))))) + +(provide 'piem-tests) +;;; piem-tests.el ends here base-commit: c9228b90ceed55502cfcbf70d5c9332028860100 -- 2.29.2