diff options
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | Makefile | 25 | ||||
-rw-r--r-- | test/ebuild-mode-tests.el | 49 | ||||
-rw-r--r-- | test/glep-mode-tests.el | 6 | ||||
-rw-r--r-- | test/xemacs-test-wrapper.el | 33 |
5 files changed, 101 insertions, 24 deletions
@@ -1,5 +1,17 @@ 2024-08-22 Ulrich Müller <ulm@gentoo.org> + * test/ebuild-mode-tests.el (cl-letf, cl-letf*) + (ebuild-mode-test-run-with-fixed-time) + (ebuild-mode-test-run-silently, ebuild-mode-test-font-lock) + (ebuild-mode-test-unescape-string): Portability fixes for XEmacs. + * test/glep-mode-tests.el (glep-mode-test-run-with-fixed-time): + Sync from ebuild-mode-test-run-with-fixed-time. + * test/xemacs-test-wrapper.el: New file. + * Makefile (DISTFILES): Add xemacs-test-wrapper.el. + (ELCS, TESTS): Include only files that are actually supported by + the Emacs version. + (check): Make it work with XEmacs. + * ebuild-mode.el (ebuild-repo-mode): Activate the menu in XEmacs. Use positive condition for feature. @@ -6,18 +6,23 @@ PV = $(shell sed '/^;.*[Vv]ersion/!d;s/[^0-9.]*\([^ \t]*\).*/\1/;q' \ ebuild-mode.el) P = $(PN)-$(PV) -TESTS = test/ebuild-mode-tests.el test/glep-mode-tests.el +EMACS = emacs +EMACSFLAGS = -batch -q --no-site-file +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 \ - $(TESTS) + test/ebuild-mode-tests.el test/glep-mode-tests.el \ + test/xemacs-test-wrapper.el -ELCS = ebuild-mode.elc devbook-mode.elc gentoo-newsitem-mode.elc glep-mode.elc +ELCS = ebuild-mode.elc gentoo-newsitem-mode.elc +TESTS = test/ebuild-mode-tests.el INFOFILES = ebuild-mode.info - -EMACS = emacs -EMACSFLAGS = -batch -q --no-site-file -BYTECOMPFLAGS = -eval "(add-to-list 'load-path nil)" +ifeq ($(findstring xemacs,$(EMACS)),) + ELCS += devbook-mode.elc glep-mode.elc + TESTS += test/glep-mode-tests.el +endif .PHONY: all keywords check dist clean @@ -34,8 +39,14 @@ keywords: ./keyword-generation.sh check: +ifeq ($(findstring xemacs,$(EMACS)),) $(EMACS) $(EMACSFLAGS) $(BYTECOMPFLAGS) $(patsubst %,-l %,$(TESTS)) \ -f ert-run-tests-batch-and-exit +else + $(EMACS) $(EMACSFLAGS) $(BYTECOMPFLAGS) \ + -eval "(add-to-list 'load-path \"test\")" \ + -l xemacs-test-wrapper -f batch-test-emacs $(TESTS) +endif dist: $(DISTFILES) tar -cJf $(P).tar.xz --transform='s%^%$(P)/%' $^ diff --git a/test/ebuild-mode-tests.el b/test/ebuild-mode-tests.el index 21987db..5497499 100644 --- a/test/ebuild-mode-tests.el +++ b/test/ebuild-mode-tests.el @@ -23,13 +23,28 @@ (require 'ert) (require 'ebuild-mode) +(when (and (featurep 'xemacs) + (not (fboundp 'cl-letf))) + (defalias 'cl-letf #'letf) + (defalias 'cl-letf* #'letf*)) + (defmacro ebuild-mode-test-run-with-fixed-time (&rest body) - `(cl-letf* ((fixed-time (date-to-time "2024-08-10T00:00:00Z")) - (orig-fun (symbol-function 'format-time-string)) - ((symbol-function 'format-time-string) - (lambda (fmt-string &optional time &rest args) - (apply orig-fun fmt-string (or time fixed-time) args)))) - ,@body)) + (let ((zone (if (or (not (featurep 'xemacs)) + (function-allows-args #'format-time-string 3)) + (list 'zone)))) + `(cl-letf* ((fixed-time (date-to-time "2024-08-10 00:00:00 +0000")) + (orig-fun (symbol-function 'format-time-string)) + ((symbol-function 'format-time-string) + (lambda (fmt-string &optional time ,@zone) + (funcall orig-fun fmt-string (or time fixed-time) ,@zone)))) + ,@body))) + +(defmacro ebuild-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))) (ert-deftest ebuild-mode-test-arch-lessp () (should (ebuild-mode-arch-lessp "amd64" "x86")) @@ -46,12 +61,18 @@ (ert-deftest ebuild-mode-test-font-lock () (with-temp-buffer - (let ((inhibit-message t)) - (ebuild-mode)) (insert "src_install() {\n" "\temake install\n" "}\n") - (font-lock-ensure) + (ebuild-mode-test-run-silently + (ebuild-mode) + (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)) + (font-lock-fontify-buffer)))) (goto-char (point-min)) (search-forward "src_install") (should (equal (get-text-property (match-beginning 0) 'face) @@ -128,11 +149,11 @@ (should (string-equal (ebuild-mode-unescape-string "äöü" 'ansi-c) "äöü")) - (should (string-equal - (decode-coding-string - (ebuild-mode-unescape-string "\\360\\237\\221\\215" 'ansi-c) - 'utf-8-unix) - "👍"))) + (let ((s (ebuild-mode-unescape-string "\\360\\237\\221\\215" 'ansi-c))) + (if (or (not (featurep 'xemacs)) + (emacs-version>= 21 5)) + (setq s (decode-coding-string s 'utf-8-unix))) + (should (string-equal s "👍")))) (ert-deftest ebuild-mode-test-get-keywords () (with-temp-buffer diff --git a/test/glep-mode-tests.el b/test/glep-mode-tests.el index 228ff50..9400752 100644 --- a/test/glep-mode-tests.el +++ b/test/glep-mode-tests.el @@ -24,11 +24,11 @@ (require 'glep-mode) (defmacro glep-mode-test-run-with-fixed-time (&rest body) - `(cl-letf* ((fixed-time (date-to-time "2024-08-10T00:00:00Z")) + `(cl-letf* ((fixed-time (date-to-time "2024-08-10 00:00:00 +0000")) (orig-fun (symbol-function 'format-time-string)) ((symbol-function 'format-time-string) - (lambda (fmt-string &optional time &rest args) - (apply orig-fun fmt-string (or time fixed-time) args)))) + (lambda (fmt-string &optional time zone) + (funcall orig-fun fmt-string (or time fixed-time) zone)))) ,@body)) (ert-deftest glep-mode-test-font-lock () diff --git a/test/xemacs-test-wrapper.el b/test/xemacs-test-wrapper.el new file mode 100644 index 0000000..dd83a07 --- /dev/null +++ b/test/xemacs-test-wrapper.el @@ -0,0 +1,33 @@ +;; Copyright 2024 Gentoo Authors +;; Distributed under the terms of the GNU General Public License v2 or later + +;; Quick and dirty hack to make the tests work with XEmacs, where ERT +;; is not available. It defines some macros (just the few that we need; +;; this is far from being complete) in terms of the XEmacs test suite +;; harness. + +;; Run the tests: +;; xemacs -batch -q --no-site-file -eval "(add-to-list 'load-path nil)" \ +;; -l test/xemacs-test-wrapper -f batch-test-emacs test/mytest.el + +(require 'test-harness) +(provide 'ert) ; pretend that ERT is present + +(defmacro ert-deftest (_name _args &rest body) + `(progn ,@body)) + +(defmacro should (assertion) + (let ((args (ignore-errors + (destructuring-bind (s1 (s2 form) (s3 (err msg))) + assertion + (list (list s1 s2 s3) err msg form))))) + ;; handle (should (equal (should-error ...) '(error ...))) + (if (equal (car args) '(equal should-error quote)) + `(Check-Error-Message ,@(cdr args)) + `(Assert ,assertion)))) + +(defmacro should-not (assertion) + `(Assert (not ,assertion))) + +(defmacro should-error (form) + `(Check-Error 'error ,form)) |