diff --git a/core/core-file-templates.el b/core/core-file-templates.el index fbaaf29c5..d9c955d29 100644 --- a/core/core-file-templates.el +++ b/core/core-file-templates.el @@ -34,6 +34,7 @@ ("\\.c$" "__.c" c-mode) ;; Elisp + ("-test\\.el$" "__" emacs-ert-mode) ("\\.emacs\\.d/.+\\.el$" "__initfile" emacs-lisp-mode) ("\\.emacs\\.d/private/\\(snippets\\|templates\\)/.+$" "__" snippet-mode) diff --git a/modules/defuns/defuns-lisp.el b/modules/defuns/defuns-lisp.el index c0e23ee9a..c61f52761 100644 --- a/modules/defuns/defuns-lisp.el +++ b/modules/defuns/defuns-lisp.el @@ -12,5 +12,37 @@ (let ((func (function-called-at-point))) (if func (find-function-other-window func)))) +(defun narf--ert-pre () + (save-buffer) + (eval-buffer)) + +;;;###autoload +(defun narf/ert-run-test () + (interactive) + (let (case-fold-search) + (narf--ert-pre) + (aif (thing-at-point 'defun t) + (if (string-match "(ert-deftest \\([^ ]+\\)" it) + (ert-run-tests-interactively (substring it (match-beginning 1) (match-end 1))) + (user-error "Invalid test at point")) + (user-error "No test found at point")))) + +;;;###autoload +(defun narf/ert-rerun-test () + (interactive) + (let (case-fold-search) + (narf--ert-pre) + (aif (car-safe ert--selector-history) + (ert-run-tests-interactively it) + (message "No test found in history, looking for test at point") + (narf/ert-run-test)))) + +;;;###autoload +(defun narf/ert-run-all-tests () + (interactive) + (ert-delete-all-tests) + (narf--ert-pre) + (ert-run-tests-interactively t)) + (provide 'defuns-lisp) ;;; defuns-lisp.el ends here diff --git a/modules/module-lisp.el b/modules/module-lisp.el index 0cbd5ab8a..e942f2410 100644 --- a/modules/module-lisp.el +++ b/modules/module-lisp.el @@ -72,13 +72,32 @@ "define-text-object" "add-yas-minor-mode" "define-docset" "define-org-link!" "define-company-backend" "define-org-section")) "!\\)") - (1 font-lock-keyword-face append)))) + (1 font-lock-keyword-face append)) + ;; Ert + (,(concat + "(" + (regexp-opt '("ert-deftest") t) + " \\([^ ]+\\)") + (1 font-lock-keyword-face) + (2 font-lock-function-name-face)))) ;; Real go-to-definition for elisp (map! :map emacs-lisp-mode-map :m "gd" 'narf/elisp-find-function-at-pt :m "gD" 'narf/elisp-find-function-at-pt-other-window) +(define-minor-mode emacs-ert-mode + "Ert test file minor mode" + :lighter " Ert" :keymap (make-sparse-keymap) + (add-yas-minor-mode! 'emacs-ert-mode)) +(associate! emacs-ert-mode :match "/test/.+-test\\.el$") + +(map! :map emacs-lisp-mode-map + (:localleader + :n "tr" 'narf/ert-rerun-test + :n "ta" 'narf/ert-run-all-tests + :n "ts" 'narf/ert-run-test)) + (use-package slime :defer t :config (setq inferior-lisp-program "clisp")) diff --git a/private/templates/emacs-ert-mode/__ b/private/templates/emacs-ert-mode/__ new file mode 100644 index 000000000..595cfef66 --- /dev/null +++ b/private/templates/emacs-ert-mode/__ @@ -0,0 +1,3 @@ +;;; `(f-filename buffer-file-name)` + +$0 \ No newline at end of file