From 633061080e62feb02c75cce27e39c93b24f6e390 Mon Sep 17 00:00:00 2001 From: Ola Nilsson Date: Fri, 13 Oct 2017 00:00:04 +0200 Subject: Add more markdown running functions Add function buttercup-run-markdown-buffer that runs all tests found in the current buffer and buttercup-run-markdown-file that runs all tests in a specified file. These new functions are convenient to run markdown tests interactively. --- buttercup.el | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/buttercup.el b/buttercup.el index c199f16..10c09e0 100644 --- a/buttercup.el +++ b/buttercup.el @@ -1254,18 +1254,26 @@ current directory." (buttercup-run))) ;;;###autoload -(defun buttercup-run-markdown () - "Run all test suites defined in Markdown files passed as arguments. -A suite must be defined within a Markdown \"lisp\" code block." - (let ((lisp-buffer (generate-new-buffer "elisp"))) - (dolist (file command-line-args-left) - (with-current-buffer (find-file-noselect file) - (goto-char (point-min)) - (let ((case-fold-search t)) - (while (re-search-forward - "```\\(?:emacs-\\|e\\)?lisp\n\\(\\(?:.\\|\n\\)*?\\)```" - nil t) - (let ((code (match-string 1))) +(defun buttercup-run-markdown-buffer (&rest markdown-buffers) + "Run all test suites defined in MARKDOWN-BUFFERS. +A suite must be defined within a Markdown \"lisp\" code block. +If MARKDOWN-BUFFERS is empty (nil), use the current buffer." + (interactive) + (unless markdown-buffers + (setq markdown-buffers (list (current-buffer)))) + (let ((lisp-buffer (generate-new-buffer "elisp")) + (case-fold-search t) + code + buttercup-suites) + (dolist (markdown-buffer markdown-buffers) + (with-current-buffer markdown-buffer + (save-excursion + (save-match-data + (goto-char (point-min)) + (while (re-search-forward + "```\\(?:emacs-\\|e\\)?lisp\n\\(\\(?:.\\|\n\\)*?\\)```" + nil t) + (setq code (match-string 1)) (with-current-buffer lisp-buffer (insert code))))))) (with-current-buffer lisp-buffer @@ -1274,6 +1282,20 @@ A suite must be defined within a Markdown \"lisp\" code block." (point-max))) (buttercup-run))) +;;;###autoload +(defun buttercup-run-markdown () + "Run all test suites defined in Markdown files passed as arguments. +A suite must be defined within a Markdown \"lisp\" code block." + (apply #'buttercup-run-markdown-buffer (mapcar #'find-file-noselect + command-line-args-left))) + +;;;###autoload +(defun buttercup-run-markdown-file (file) + "Run all test suites defined in Markdown FILE. +A suite must be defined within a Markdown \"lisp\" code block." + (interactive "fMarkdown file: ") + (buttercup-run-markdown-buffer (find-file-noselect file))) + (eval-when-compile ;; Defined below in a dedicated section (defvar buttercup-reporter)) -- cgit v1.2.3