From bb33ce840f4ebbdcac14da74dba5acce052fbba1 Mon Sep 17 00:00:00 2001 From: Carlo Sciolla Date: Sun, 27 Aug 2017 12:23:37 +0200 Subject: [PATCH] Better test docs and cleanup --- plantuml-mode.el | 4 +++- test/plantuml-preview-test.el | 18 +++++++++++++----- test/test-helper.el | 23 ++++++++++++++++++++++- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/plantuml-mode.el b/plantuml-mode.el index eca66cf..c8f4fe1 100644 --- a/plantuml-mode.el +++ b/plantuml-mode.el @@ -246,7 +246,9 @@ to choose where to display it: - else -> new window" (let ((b (get-buffer plantuml-preview-buffer))) (when b - (kill-buffer b))) + (with-current-buffer b + (setq buffer-read-only nil) + (erase-buffer)))) (let* ((imagep (and (display-images-p) (plantuml-is-image-output-p))) diff --git a/test/plantuml-preview-test.el b/test/plantuml-preview-test.el index 0654284..d07b6ff 100644 --- a/test/plantuml-preview-test.el +++ b/test/plantuml-preview-test.el @@ -9,6 +9,8 @@ ;;; Code: (defun assert-preview (puml output &optional format) + "Run PlantUML on the source PUML and asserts the result to be +equal to OUTPUT. Can choose the output FORMAT (default: utxt)." (if format (setq plantuml-output-type format) (setq plantuml-output-type "utxt")) @@ -18,13 +20,19 @@ (replace-regexp-in-string " " "~" (read-preview-buffer))))) (ert-deftest preview-utxt-test () - (setq-local plantuml-jar-path plantuml-test-jar-path) - (assert-preview "a-b.puml" "a-b.txt")) + (unwind-protect + (progn + (setq-local plantuml-jar-path plantuml-test-jar-path) + (assert-preview "a-b.puml" "a-b.txt")) + (cleanup-preview))) (ert-deftest preview-unicode-test () - (setq-local plantuml-jar-path plantuml-test-jar-path) - (setq-local plantuml-output-type "utxt") - (assert-preview "unicode.puml" "unicode.txt")) + (unwind-protect + (progn + (setq-local plantuml-jar-path plantuml-test-jar-path) + (setq-local plantuml-output-type "utxt") + (assert-preview "unicode.puml" "unicode.txt"))) + (cleanup-preview)) (provide 'plantuml-mode-preview-test) diff --git a/test/test-helper.el b/test/test-helper.el index 9fba3f7..03fabec 100644 --- a/test/test-helper.el +++ b/test/test-helper.el @@ -22,17 +22,38 @@ (defvar plantuml-test-jar-path (f-join package-code-path "bin/plantuml.jar")) +(defun test-file-path (path) + "Translate the relative test path PATH in an absolute path." + (f-join plantuml-test-resources-path path)) + +(defun cleanup-preview () + "Kill the preview buffer" + (let ((proc (get-buffer-process plantuml-preview-buffer))) + (when proc + (set-process-query-on-exit-flag proc nil)) + (kill-buffer plantuml-preview-buffer))) + (defun read-buffer (bufname) + "Read the contents of buffer BUFNAME." (with-current-buffer (get-buffer bufname) (buffer-string))) (defun read-preview-buffer () + "Read the contents of the PlantUML preview buffer." (read-buffer plantuml-preview-buffer)) (defun read-test-file (path) - (f-read (f-join plantuml-test-resources-path path) 'utf-8)) + "Fetch the string content of the test file at relative path PATH." + (f-read (test-file-path path) 'utf-8)) + +(defun open-test-file-in-buf (test-file) + "Visit TEST-FILE in a new buffer." + (message "buffer list before: %s" (buffer-list)) + (find-file (test-file-path test-file)) + (message "buffer list after: %s" (buffer-list))) (defun load-plantuml-mode () + "Load the plantuml-mode package." (require 'plantuml-mode (f-expand "plantuml-mode.el" package-code-path))) (load-plantuml-mode)