branch: main
commit 76ef5a9908a8b3a1fc648d3f19ceade1cb041b42
Author: Al Haji-Ali <[email protected]>
Commit: Ikumi Keita <[email protected]>
Add test related to `preview-watch-preamble'
* preview.el (preview-get-dpi): Handle nil dimensions for batch mode.
* tests/latex/preview-latex-test.el (preview-cache-preamble): Add test
for `preview-cache-preamble' with non-nil `TeX-output-dir'.
---
preview.el | 4 +--
tests/latex/preview-latex-test.el | 67 +++++++++++++++++++++++++++++++++++++++
2 files changed, 69 insertions(+), 2 deletions(-)
diff --git a/preview.el b/preview.el
index 840cf138..b23bf41b 100644
--- a/preview.el
+++ b/preview.el
@@ -3778,8 +3778,8 @@ name(\\([^)]+\\))\\)\\|\
(defun preview-get-dpi ()
(let* ((monitor-attrs (frame-monitor-attributes))
(mm-dims (cdr (assoc 'mm-size monitor-attrs)))
- (mm-width (nth 0 mm-dims))
- (mm-height (nth 1 mm-dims))
+ (mm-width (or (nth 0 mm-dims) 1))
+ (mm-height (or (nth 1 mm-dims) 1))
(pixel-dims (cl-cdddr (assoc 'geometry monitor-attrs)))
(pixel-width (nth 0 pixel-dims))
(pixel-height (nth 1 pixel-dims)))
diff --git a/tests/latex/preview-latex-test.el
b/tests/latex/preview-latex-test.el
index 8c7d8314..155615a0 100644
--- a/tests/latex/preview-latex-test.el
+++ b/tests/latex/preview-latex-test.el
@@ -23,6 +23,11 @@
(require 'ert)
(require 'preview)
+(require 'font-latex)
+
+(AUCTeX-set-ert-path
+ 'preview-test-file
+ "../../circ.tex")
(ert-deftest preview-error-quote-utf-8 ()
"`preview-error-quote' is robust against partial ^^-quoting or not.
@@ -41,6 +46,68 @@ emacs' coding system later."
"Test mixture of raw 8-bit byte and byte with ^^-quoting."
(dolist (str '("prim\xC3\xA1rias" "prim^^c3\xA1rias" "prim^^c3^^a1rias"))
(should (string= (preview--decode-^^ab str 'utf-8) "primárias"))))
+(ert-deftest preview-cache-preamble ()
+ "Test caching of preamble with non-nil `TeX-output-dir'."
+ (let ((TeX-clean-confirm nil)
+ (preview-auto-cache-preamble nil)
+ (process-environment (copy-sequence process-environment))
+ (TeX-output-dir "auctex-output")
+ buffer1 buffer2
+ (pt-msg (with-current-buffer (messages-buffer) (point))))
+ (unwind-protect
+ (save-window-excursion
+ (setq buffer1 (find-file preview-test-file))
+ (delete-other-windows)
+ (preview-cache-preamble)
+ (setq buffer2 (TeX-active-buffer))
+ (message "Please wait for asynchronous process to finish...")
+ (while (get-buffer-process buffer2)
+ (sleep-for 1))
+ (should-error
+ (with-current-buffer (messages-buffer)
+ (goto-char pt-msg)
+ (search-forward "error in process sentinel:")))
+ (message "Please wait for asynchronous process to finish...done")
+
+ (with-current-buffer buffer1
+ ;; ini file should be deleted
+ (should-not
+ (or
+ (file-exists-p
+ (expand-file-name
+ (TeX-master-output-file "ini")))
+ (file-exists-p
+ (expand-file-name
+ (TeX-master-file "ini")))))
+ ;; fmt file should be in output-directory
+ (should
+ (file-exists-p
+ (expand-file-name
+ (preview-dump-file-name
+ (TeX-master-output-file "fmt")))))
+ ;; and not be in master directory
+ (should-not
+ (file-exists-p
+ (expand-file-name
+ (preview-dump-file-name
+ (TeX-master-file "fmt")))))))
+ ;; Cleanup.
+ (if (buffer-live-p buffer2)
+ (kill-buffer buffer2))
+ (when (buffer-live-p buffer1)
+ (set-buffer buffer1)
+ (TeX-clean t) ;; delete the log files
+ (preview-cache-preamble-off)
+
+ ;; Check clean-up
+ (should-not
+ (file-exists-p
+ (expand-file-name
+ (preview-dump-file-name
+ (TeX-master-output-file "fmt")))))
+
+ (delete-directory (expand-file-name TeX-output-dir))
+ (kill-buffer buffer1)))))
;;; preview-latex-test.el ends here