blob: 247c75d7ca9820812e268875489845b09c03a0d1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
;;; test-markdown-config-preview-autostart.el --- preview server autostart -*- lexical-binding: t; -*-
;;; Commentary:
;; Tests for `cj/--markdown-preview-ensure-server': F2 preview starts the
;; simple-httpd listener itself when it isn't running (per the 2026-07-01
;; cj comment), and leaves a running server alone. simple-httpd isn't
;; installed in batch, so the tests provide a stub feature with the two
;; functions the helper touches.
;;; Code:
(require 'ert)
(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
(require 'markdown-config)
;; Stand in for the elpa package: `require' in the helper becomes a
;; no-op. Tests mock httpd-running-p explicitly (works whether the
;; real simple-httpd or this stub is loaded), so the stub bodies never
;; matter.
(require 'cl-lib)
(unless (featurep 'simple-httpd)
(defun httpd-running-p () nil)
(defun httpd-start () nil)
(provide 'simple-httpd))
(ert-deftest test-markdown-config-ensure-server-starts-when-down ()
"Normal: a stopped server gets started."
(let ((started nil))
(cl-letf (((symbol-function 'httpd-running-p) (lambda () nil))
((symbol-function 'cj/markdown-preview-server-start)
(lambda () (setq started t))))
(cj/--markdown-preview-ensure-server)
(should started))))
(ert-deftest test-markdown-config-ensure-server-noop-when-running ()
"Boundary: a running server is left alone."
(let ((started nil))
(cl-letf (((symbol-function 'httpd-running-p) (lambda () t))
((symbol-function 'cj/markdown-preview-server-start)
(lambda () (setq started t))))
(cj/--markdown-preview-ensure-server)
(should-not started))))
(ert-deftest test-markdown-config-preview-no-longer-signals-user-error ()
"Error-path regression: the old user-error on a stopped server is gone."
(should-not (string-match-p "user-error"
(format "%S" (symbol-function 'cj/markdown-preview)))))
(provide 'test-markdown-config-preview-autostart)
;;; test-markdown-config-preview-autostart.el ends here
|