diff options
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | Makefile | 7 | ||||
-rw-r--r-- | test/devbook-mode-tests.el | 72 | ||||
-rw-r--r-- | test/ebuild-mode-tests.el | 57 | ||||
-rw-r--r-- | test/gentoo-newsitem-mode-tests.el | 106 | ||||
-rw-r--r-- | test/glep-mode-tests.el | 49 |
6 files changed, 299 insertions, 3 deletions
@@ -1,5 +1,16 @@ 2024-08-26 Ulrich Müller <ulm@gentoo.org> + * test/ebuild-mode-tests.el (ebuild-mode-test-input): New variable + and function. + (ebuild-mode-test-skeleton, ebuild-mode-test-keybindings): + New tests. + * test/glep-mode-tests.el (glep-mode-test-input): New variable and + function. + (glep-mode-test-skeleton, glep-mode-test-keybindings): New tests. + * test/gentoo-newsitem-mode-tests.el: + * test/devbook-mode-tests.el: New files. + * Makefile (DISTFILES, TESTS): Add them. + * test/xemacs-test-wrapper.el (kill-emacs): Return a useful exit status. @@ -13,15 +13,16 @@ BYTECOMPFLAGS = -eval "(add-to-list 'load-path nil)" DISTFILES = ebuild-mode.el ebuild-mode-keywords.el devbook-mode.el \ gentoo-newsitem-mode.el glep-mode.el ebuild-mode.texi \ ChangeLog Makefile keyword-generation.sh \ - test/ebuild-mode-tests.el test/glep-mode-tests.el \ + test/ebuild-mode-tests.el test/devbook-mode-tests.el \ + test/gentoo-newsitem-mode-tests.el test/glep-mode-tests.el \ test/xemacs-test-wrapper.el ELCS = ebuild-mode.elc gentoo-newsitem-mode.elc -TESTS = test/ebuild-mode-tests.el +TESTS = test/ebuild-mode-tests.el test/gentoo-newsitem-mode-tests.el INFOFILES = ebuild-mode.info ifeq ($(findstring xemacs,$(EMACS)),) ELCS += devbook-mode.elc glep-mode.elc - TESTS += test/glep-mode-tests.el + TESTS += test/devbook-mode-tests.el test/glep-mode-tests.el endif .PHONY: all keywords check dist clean diff --git a/test/devbook-mode-tests.el b/test/devbook-mode-tests.el new file mode 100644 index 0000000..321e1e6 --- /dev/null +++ b/test/devbook-mode-tests.el @@ -0,0 +1,72 @@ +;;; devbook-mode-tests.el --- tests for devbook-mode.el -*-lexical-binding:t-*- + +;; Copyright 2024 Gentoo Authors + +;; Author: Ulrich Müller <ulm@gentoo.org> +;; Maintainer: <emacs@gentoo.org> + +;; This file 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 2 of the License, or +;; (at your option) any later version. + +;; This file 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>. + +;;; Code: + +(require 'ert) +(require 'devbook-mode) + +(defmacro devbook-mode-test-run-silently (&rest body) + `(let ((inhibit-message t)) ,@body)) + +(defvar devbook-mode-test-input nil) + +(defun devbook-mode-test-input (&rest _args) + (concat (pop devbook-mode-test-input))) + +(ert-deftest devbook-mode-test-skeleton () + (with-temp-buffer + (cl-letf (((symbol-function 'read-from-minibuffer) + #'devbook-mode-test-input) + ((symbol-function 'read-string) + #'devbook-mode-test-input) + (buffer-file-name + "/home/larry/devmanual/quickstart/text.xml")) + (setq devbook-mode-test-input + '("Quickstart guide")) + (devbook-insert-skeleton)) + (let ((buf1 (concat "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<guide self=\"quickstart/\">\n" + "<chapter>\n" + "<title>Quickstart guide</title>\n")) + (buf2 (concat "\n" + "</chapter>\n" + "</guide>\n"))) + (should (equal (point) + (+ (point-min) (length buf1)))) + (should (string-equal (buffer-string) + (concat buf1 buf2)))))) + +(ert-deftest devbook-mode-test-keybindings () + (should (equal (lookup-key devbook-mode-map "\C-c\C-n") + 'devbook-insert-skeleton)) + (with-temp-buffer + (devbook-mode-test-run-silently + (devbook-mode)) + (should (equal (local-key-binding "\C-c\C-n") + 'devbook-insert-skeleton)))) + +(provide 'devbook-mode-tests) + +;; Local Variables: +;; coding: utf-8 +;; End: + +;;; devbook-mode-tests.el ends here diff --git a/test/ebuild-mode-tests.el b/test/ebuild-mode-tests.el index 5497499..5c9d944 100644 --- a/test/ebuild-mode-tests.el +++ b/test/ebuild-mode-tests.el @@ -46,6 +46,11 @@ ((symbol-function 'clear-message) #'ignore)) ,@body))) +(defvar ebuild-mode-test-input nil) + +(defun ebuild-mode-test-input (&rest _args) + (concat (pop ebuild-mode-test-input))) + (ert-deftest ebuild-mode-test-arch-lessp () (should (ebuild-mode-arch-lessp "amd64" "x86")) (should-not (ebuild-mode-arch-lessp "amd64-linux" "x86")) @@ -199,6 +204,47 @@ (buffer-string) "KEYWORDS=\"~amd64 ~arm -m68k ~ppc64 ~x86\"\n")))) +(ert-deftest ebuild-mode-test-skeleton () + (with-temp-buffer + (cl-letf (((symbol-function 'read-from-minibuffer) + #'ebuild-mode-test-input) + ((symbol-function 'read-string) + #'ebuild-mode-test-input)) + (setq ebuild-mode-test-input + '("8" ; EAPI + "" ; inherit + "Skeleton test" ; DESCRIPTION + "https://www.gentoo.org/" ; HOMEPAGE + "" ; SRC_URI + "" ; S + "GPL-2+" "MIT" "" ; LICENSE + "~amd64" "" ; KEYWORDS + "" ; IUSE + "")) ; RESTRICT + (ebuild-mode-test-run-with-fixed-time + (ebuild-mode-test-run-silently + (if (featurep 'xemacs) + ;; prevent a segfault (seen with XEmacs 21.4.24 and 21.5.35) + (cl-letf (((symbol-function 'pos-visible-in-window-p) + (lambda (&rest _args) t))) + (ebuild-mode-insert-skeleton)) + (ebuild-mode-insert-skeleton)))) + (should (string-equal + (buffer-string) + (concat "# Copyright 2024 Gentoo Authors\n" + "# Distributed under the terms of the " + "GNU General Public License v2\n\n" + "EAPI=8\n\n" + "DESCRIPTION=\"Skeleton test\"\n" + "HOMEPAGE=\"https://www.gentoo.org/\"\n" + "SRC_URI=\"\"\n\n" + "LICENSE=\"GPL-2+ MIT\"\n" + "SLOT=\"0\"\n" + "KEYWORDS=\"~amd64\"\n\n" + "RDEPEND=\"\"\n" + "DEPEND=\"${RDEPEND}\"\n" + "BDEPEND=\"\"\n")))))) + (ert-deftest ebuild-mode-test-insert-tag-line () (let ((ebuild-mode-full-name "Larry the Cow") (ebuild-mode-mail-address "larry@example.org")) @@ -216,6 +262,17 @@ (buffer-string) "# Larry the Cow <larry@example.org> (2024-08-10)\n")))))) +(ert-deftest ebuild-mode-test-keybindings () + (should (equal (lookup-key ebuild-mode-map "\C-c\C-e\C-k") + 'ebuild-mode-keyword)) + (should (equal (lookup-key ebuild-repo-mode-map "\C-c-") + 'ebuild-mode-insert-tag-line)) + (with-temp-buffer + (ebuild-mode-test-run-silently + (ebuild-mode)) + (should (equal (local-key-binding "\C-c\C-eu") + 'ebuild-run-command-unpack)))) + (provide 'ebuild-mode-tests) ;; Local Variables: diff --git a/test/gentoo-newsitem-mode-tests.el b/test/gentoo-newsitem-mode-tests.el new file mode 100644 index 0000000..e447fd1 --- /dev/null +++ b/test/gentoo-newsitem-mode-tests.el @@ -0,0 +1,106 @@ +;;; gentoo-newsitem-mode-tests.el -*-lexical-binding:t-*- + +;; Copyright 2024 Gentoo Authors + +;; Author: Ulrich Müller <ulm@gentoo.org> +;; Maintainer: <emacs@gentoo.org> + +;; This file 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 2 of the License, or +;; (at your option) any later version. + +;; This file 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>. + +;;; Code: + +(require 'ert) +(require 'gentoo-newsitem-mode) + +(when (and (featurep 'xemacs) + (not (fboundp 'cl-letf))) + (defalias 'cl-letf #'letf) + (defalias 'cl-letf* #'letf*)) + +(defmacro gentoo-newsitem-mode-test-run-silently (&rest body) + (if (boundp 'inhibit-message) + `(let ((inhibit-message t)) ,@body) + `(cl-letf (((symbol-function 'append-message) #'ignore) + ((symbol-function 'clear-message) #'ignore)) + ,@body))) + +(defvar gentoo-newsitem-mode-test-input nil) + +(defun gentoo-newsitem-mode-test-input (&rest _args) + (concat (pop gentoo-newsitem-mode-test-input))) + +(ert-deftest gentoo-newsitem-mode-test-font-lock () + (with-temp-buffer + (gentoo-newsitem-mode) + (insert "Author: Larry the Cow\n") + (if (fboundp 'font-lock-ensure) + (font-lock-ensure)) + (if (featurep 'xemacs) + ;; XEmacs refuses to fontify in batch mode, + ;; therefore pretend that we are interactive + (cl-letf (((symbol-function 'noninteractive) #'ignore)) + (gentoo-newsitem-mode-test-run-silently + (font-lock-fontify-buffer)))) + (goto-char (point-min)) + (search-forward "Author") + (should (equal (get-text-property (match-beginning 0) 'face) + 'font-lock-keyword-face)) + (search-forward "Larry") + (should-not (get-text-property (match-beginning 0) 'face)))) + +(ert-deftest gentoo-newsitem-mode-test-skeleton () + (with-temp-buffer + (cl-letf (((symbol-function 'read-from-minibuffer) + #'gentoo-newsitem-mode-test-input) + ((symbol-function 'read-string) + #'gentoo-newsitem-mode-test-input)) + (setq gentoo-newsitem-mode-test-input + '("Skeleton test" ; Title + "Larry the Cow <larry@example.org>" "" ; Author + "" ; Translator + "2024-08-10" ; Posted + "" ; News-Item-Format + "" ; Display-If-Installed + "" ; Display-If-Keyword + "")) ; Display-If-Profile + (gentoo-newsitem-mode-test-run-silently + (if (featurep 'xemacs) + ;; prevent a segfault (seen with XEmacs 21.4.24 and 21.5.35) + (cl-letf (((symbol-function 'pos-visible-in-window-p) + (lambda (&rest _args) t))) + (gentoo-newsitem-insert-skeleton)) + (gentoo-newsitem-insert-skeleton))) + (should (string-equal + (buffer-string) + (concat "Title: Skeleton test\n" + "Author: Larry the Cow <larry@example.org>\n" + "Posted: 2024-08-10\n" + "Revision: 1\n" + "News-Item-Format: 2.0\n\n")))))) + +(ert-deftest gentoo-newsitem-mode-test-keybindings () + (should (equal (lookup-key gentoo-newsitem-mode-map "\C-c\C-n") + 'gentoo-newsitem-insert-skeleton)) + (with-temp-buffer + (gentoo-newsitem-mode) + (should (equal (local-key-binding "\C-c\C-n") + 'gentoo-newsitem-insert-skeleton)))) + +(provide 'gentoo-newsitem-mode-tests) + +;; Local Variables: +;; coding: utf-8 +;; End: + +;;; gentoo-newsitem-mode-tests.el ends here diff --git a/test/glep-mode-tests.el b/test/glep-mode-tests.el index 9400752..7318293 100644 --- a/test/glep-mode-tests.el +++ b/test/glep-mode-tests.el @@ -31,6 +31,11 @@ (funcall orig-fun fmt-string (or time fixed-time) zone)))) ,@body)) +(defvar glep-mode-test-input nil) + +(defun glep-mode-test-input (&rest _args) + (concat (pop glep-mode-test-input))) + (ert-deftest glep-mode-test-font-lock () (with-temp-buffer (glep-mode) @@ -79,6 +84,42 @@ "---\n" "Last-Modified: 2023-02-22\n")))))) +(ert-deftest glep-mode-test-skeleton () + (with-temp-buffer + (cl-letf (((symbol-function 'read-from-minibuffer) + #'glep-mode-test-input) + ((symbol-function 'read-string) + #'glep-mode-test-input) + (buffer-file-name + "/home/larry/devmanual/quickstart/text.xml")) + (setq glep-mode-test-input + '("9999" ; GLEP + "Skeleton test" ; Title + "Larry the Cow" ; Author + "Informational" ; Type + "Draft" ; Status + "1" ; Version + "" ; Requires + "")) ; Replaces + (glep-mode-test-run-with-fixed-time + (glep-mode-insert-skeleton))) + (goto-char (point-min)) + (search-forward "---\n" nil nil 2) + (should (string-equal + (buffer-substring (point-min) (point)) + (concat "---\n" + "GLEP: 9999\n" + "Title: Skeleton test\n" + "Author: Larry the Cow\n" + "Type: Informational\n" + "Status: Draft\n" + "Version: 1\n" + "Created: 2024-08-10\n" + "Last-Modified: 2024-08-10\n" + "Post-History: \n" + "Content-Type: text/x-rst\n" + "---\n"))))) + (ert-deftest glep-mode-test-in-preamble-p () (with-temp-buffer (let ((preamble "---\nGLEP: 2\n---\n")) @@ -91,6 +132,14 @@ (forward-line 3) (should-not (glep-mode-in-preamble-p (point))))) +(ert-deftest glep-mode-test-keybindings () + (should (equal (lookup-key glep-mode-map "\C-c\C-n") + 'glep-mode-insert-skeleton)) + (with-temp-buffer + (glep-mode) + (should (equal (local-key-binding "\C-c\C-n") + 'glep-mode-insert-skeleton)))) + (provide 'glep-mode-tests) ;; Local Variables: |