
dc4e6b1329
; Update copyright years in more files64b3777631
; Run set-copyright from admin.el8e1c56ae46
; Add 2024 to copyright years # Conflicts: # doc/misc/modus-themes.org # doc/misc/texinfo.tex # etc/NEWS # etc/refcards/ru-refcard.tex # etc/themes/modus-operandi-theme.el # etc/themes/modus-themes.el # etc/themes/modus-vivendi-theme.el # lib/alloca.in.h # lib/binary-io.h # lib/c-ctype.h # lib/c-strcasecmp.c # lib/c-strncasecmp.c # lib/careadlinkat.c # lib/cloexec.c # lib/close-stream.c # lib/diffseq.h # lib/dup2.c # lib/filemode.h # lib/fpending.c # lib/fpending.h # lib/fsusage.c # lib/getgroups.c # lib/getloadavg.c # lib/gettext.h # lib/gettime.c # lib/gettimeofday.c # lib/group-member.c # lib/malloc.c # lib/md5-stream.c # lib/md5.c # lib/md5.h # lib/memmem.c # lib/memrchr.c # lib/nanosleep.c # lib/save-cwd.h # lib/sha1.c # lib/sig2str.c # lib/stdlib.in.h # lib/strtoimax.c # lib/strtol.c # lib/strtoll.c # lib/time_r.c # lib/xalloc-oversized.h # lisp/auth-source-pass.el # lisp/emacs-lisp/lisp-mnt.el # lisp/emacs-lisp/timer.el # lisp/info-look.el # lisp/jit-lock.el # lisp/loadhist.el # lisp/mail/rmail.el # lisp/net/ntlm.el # lisp/net/webjump.el # lisp/progmodes/asm-mode.el # lisp/progmodes/project.el # lisp/progmodes/sh-script.el # lisp/textmodes/flyspell.el # lisp/textmodes/reftex-toc.el # lisp/textmodes/reftex.el # lisp/textmodes/tex-mode.el # lisp/url/url-gw.el # m4/alloca.m4 # m4/clock_time.m4 # m4/d-type.m4 # m4/dirent_h.m4 # m4/dup2.m4 # m4/euidaccess.m4 # m4/fchmodat.m4 # m4/filemode.m4 # m4/fsusage.m4 # m4/getgroups.m4 # m4/getloadavg.m4 # m4/getrandom.m4 # m4/gettime.m4 # m4/gettimeofday.m4 # m4/gnulib-common.m4 # m4/group-member.m4 # m4/inttypes.m4 # m4/malloc.m4 # m4/manywarnings.m4 # m4/mempcpy.m4 # m4/memrchr.m4 # m4/mkostemp.m4 # m4/mktime.m4 # m4/nproc.m4 # m4/nstrftime.m4 # m4/pathmax.m4 # m4/pipe2.m4 # m4/pselect.m4 # m4/pthread_sigmask.m4 # m4/readlink.m4 # m4/realloc.m4 # m4/sig2str.m4 # m4/ssize_t.m4 # m4/stat-time.m4 # m4/stddef_h.m4 # m4/stdint.m4 # m4/stdio_h.m4 # m4/stdlib_h.m4 # m4/stpcpy.m4 # m4/strnlen.m4 # m4/strtoimax.m4 # m4/strtoll.m4 # m4/time_h.m4 # m4/timegm.m4 # m4/timer_time.m4 # m4/timespec.m4 # m4/unistd_h.m4 # m4/warnings.m4 # nt/configure.bat # nt/preprep.c # test/lisp/register-tests.el
224 lines
7.4 KiB
EmacsLisp
224 lines
7.4 KiB
EmacsLisp
;;; erts-mode.el --- major mode to edit erts files -*- lexical-binding: t; -*-
|
|
|
|
;; Copyright (C) 2021-2024 Free Software Foundation, Inc.
|
|
|
|
;; Keywords: tools
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
;; GNU Emacs 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.
|
|
|
|
;; GNU Emacs 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 <https://www.gnu.org/licenses/>.
|
|
|
|
;;; Commentary:
|
|
|
|
;;; Code:
|
|
|
|
(eval-when-compile (require 'cl-lib))
|
|
(require 'ert)
|
|
|
|
(defgroup erts-mode nil
|
|
"Major mode for editing Emacs test files."
|
|
:group 'lisp)
|
|
|
|
(defface erts-mode-specification-name
|
|
'((((class color)
|
|
(background dark))
|
|
:foreground "green")
|
|
(((class color)
|
|
(background light))
|
|
:foreground "cornflower blue")
|
|
(t
|
|
:bold t))
|
|
"Face used for displaying specification names."
|
|
:group 'erts-mode)
|
|
|
|
(defface erts-mode-specification-value
|
|
'((((class color)
|
|
(background dark))
|
|
:foreground "DeepSkyBlue1")
|
|
(((class color)
|
|
(background light))
|
|
:foreground "blue")
|
|
(t
|
|
:bold t))
|
|
"Face used for displaying specification values."
|
|
:group 'erts-mode)
|
|
|
|
(defface erts-mode-start-test
|
|
'((t :inherit font-lock-keyword-face))
|
|
"Face used for displaying specification test start markers."
|
|
:group 'erts-mode)
|
|
|
|
(defface erts-mode-end-test
|
|
'((t :inherit font-lock-comment-face))
|
|
"Face used for displaying specification test start markers."
|
|
:group 'erts-mode)
|
|
|
|
(defvar-keymap erts-mode-map
|
|
:parent prog-mode-map
|
|
"C-c C-r" #'erts-tag-region
|
|
"C-c C-c" #'erts-run-test)
|
|
|
|
(defvar erts-mode-font-lock-keywords
|
|
;; Specifications.
|
|
`((erts-mode--match-not-in-test
|
|
("^\\([^ \t\n:]+:\\)[ \t]*\\(.*\\(\n[ \t].*\\)*\\)\n?"
|
|
(progn (goto-char (match-beginning 0)) (match-end 0)) nil
|
|
(1 'erts-mode-specification-name)
|
|
(2 'erts-mode-specification-value)))
|
|
("^=-=$" 0 'erts-mode-start-test)
|
|
("^=-=-=$" 0 'erts-mode-end-test)))
|
|
|
|
(defun erts-mode--match-not-in-test (_limit)
|
|
(when (erts-mode--in-test-p (point))
|
|
(erts-mode--end-of-test))
|
|
(let ((start (point)))
|
|
(goto-char
|
|
(if (re-search-forward "^=-=$" nil t)
|
|
(match-beginning 0)
|
|
(point-max)))
|
|
(if (< (point) start)
|
|
nil
|
|
;; Here we disregard LIMIT so that we may extend the area again.
|
|
(set-match-data (list start (point)))
|
|
(point))))
|
|
|
|
(defun erts-mode--end-of-test ()
|
|
(search-forward "^=-=-=\n" nil t))
|
|
|
|
(defun erts-mode--in-test-p (point)
|
|
"Say whether POINT is in a test."
|
|
(save-excursion
|
|
(goto-char point)
|
|
(beginning-of-line)
|
|
(if (looking-at "=-=\\(-=\\)?$")
|
|
t
|
|
(let ((test-start (save-excursion
|
|
(re-search-backward "^=-=\n" nil t))))
|
|
;; Before the first test.
|
|
(and test-start
|
|
(let ((test-end (re-search-backward "^=-=-=\n" nil t)))
|
|
(or (null test-end)
|
|
;; Between tests.
|
|
(> test-start test-end))))))))
|
|
|
|
;;;###autoload
|
|
(define-derived-mode erts-mode prog-mode "erts"
|
|
"Major mode for editing erts (Emacs testing) files.
|
|
This mode mainly provides some font locking.
|
|
|
|
\\{erts-mode-map}"
|
|
(setq-local font-lock-defaults '(erts-mode-font-lock-keywords t)))
|
|
|
|
(defun erts-tag-region (start end name)
|
|
"Tag the region between START and END as a test.
|
|
Interactively, this is the region.
|
|
|
|
NAME should be a string appropriate for output by ert if the test fails.
|
|
If NAME is nil or the empty string, a name will be auto-generated."
|
|
(interactive "r\nsTest name: " erts-mode)
|
|
;; Automatically make a name.
|
|
(when (zerop (length name))
|
|
(save-excursion
|
|
(goto-char (point-min))
|
|
(let ((names nil))
|
|
(while (re-search-forward "^Name:[ \t]*\\(.*\\)" nil t)
|
|
(let ((name (match-string 1)))
|
|
(unless (erts-mode--in-test-p (point))
|
|
(push name names))))
|
|
(setq name
|
|
(cl-loop with base = (file-name-sans-extension (buffer-name))
|
|
for i from 1
|
|
for name = (format "%s%d" base i)
|
|
unless (member name names)
|
|
return name)))))
|
|
(save-excursion
|
|
(goto-char end)
|
|
(unless (bolp)
|
|
(insert "\n"))
|
|
(insert "=-=-=\n")
|
|
(goto-char start)
|
|
(insert "Name: " name "\n\n")
|
|
(insert "=-=\n")))
|
|
|
|
(defun erts-mode--preceding-spec (name)
|
|
(save-excursion
|
|
;; Find the name, but skip if it's in a test.
|
|
(while (and (re-search-backward (format "^%s:" name) nil t)
|
|
(erts-mode--in-test-p (point))))
|
|
(and (not (erts-mode--in-test-p (point)))
|
|
(re-search-forward "^=-=$" nil t)
|
|
(progn
|
|
(goto-char (match-beginning 0))
|
|
(cdr (assq (intern (downcase name))
|
|
(ert--erts-specifications (point))))))))
|
|
|
|
(defun erts-run-test (test-function &optional verbose)
|
|
"Run the current test.
|
|
If the current erts file doesn't define a test function, the user
|
|
will be prompted for one.
|
|
|
|
If VERBOSE (interactively, the prefix), display a diff of the
|
|
expected results and the actual results in a separate buffer."
|
|
(interactive
|
|
(list (or (erts-mode--preceding-spec "Code")
|
|
(read-string "Transformation function: "))
|
|
current-prefix-arg)
|
|
erts-mode)
|
|
(save-excursion
|
|
(erts-mode--goto-start-of-test)
|
|
(condition-case arg
|
|
(ert-test--erts-test
|
|
(list (cons 'dummy t)
|
|
(cons 'code (car (read-from-string test-function)))
|
|
(cons 'point-char (save-match-data
|
|
(erts-mode--preceding-spec "Point-Char"))))
|
|
(buffer-file-name))
|
|
(:success (message "Test successful"))
|
|
(ert-test-failed
|
|
(if (not verbose)
|
|
(message "Test failure; result: \n%s"
|
|
(substring-no-properties (cadr (cadr arg))))
|
|
(message "Test failure")
|
|
(let (expected got)
|
|
(unwind-protect
|
|
(progn
|
|
(with-current-buffer
|
|
(setq expected (generate-new-buffer "erts expected"))
|
|
(insert (nth 1 (cadr arg))))
|
|
(with-current-buffer
|
|
(setq got (generate-new-buffer "erts results"))
|
|
(insert (nth 2 (cadr arg))))
|
|
(diff-buffers expected got))
|
|
(kill-buffer expected)
|
|
(kill-buffer got))))))))
|
|
|
|
(defun erts-mode--goto-start-of-test ()
|
|
(if (not (erts-mode--in-test-p (point)))
|
|
(re-search-forward "^=-=\n" nil t)
|
|
(re-search-backward "^=-=\n" nil t)
|
|
(let ((potential-start (match-end 0)))
|
|
;; See if we're in a two-clause ("before" and "after") test or not.
|
|
(if-let ((start (and (save-excursion (re-search-backward "^=-=\n" nil t))
|
|
(match-end 0))))
|
|
(let ((end (save-excursion (re-search-backward "^=-=-=\n" nil t))))
|
|
(if (or (not end)
|
|
(> start end))
|
|
;; We are, so go to the real start.
|
|
(goto-char start)
|
|
(goto-char potential-start)))
|
|
(goto-char potential-start)))))
|
|
|
|
(provide 'erts-mode)
|
|
|
|
;;; erts-mode.el ends here
|