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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
| | ;;; test-ox-man.el --- Tests from ox-man.el -*- lexical-binding: t; -*-
;; Copyright (C) 2025 Ilya Chernyshov
;; Author: Ilya Chernyshov <ichernyshovvv@gmail.com>
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Code:
(require 'ox-man)
(defvar ox-man/groff-executable (executable-find "groff")
"Contain path to groff executable of nil when there is no such path.")
(defmacro ox-man/test-with-exported-test (source &rest body)
"Run BODY in export buffer for SOURCE string exported to man.
Throw an error when exported text does not pass groff linter (if groff
executable is available)."
(declare (indent 1))
`(org-test-with-exported-text 'man ,source
(when ox-man/groff-executable
(let ((output (generate-new-buffer " *groff-linter-output*")))
(unwind-protect
(progn
(call-process-region
(point-min) (point-max) ox-man/groff-executable
nil (list output t) nil
"-zww" "-rCHECKSTYLE=3" "-man" "-")
(with-current-buffer output
(should
(string-empty-p
(thread-last
(buffer-string)
;; FIXME: ox-man does not yet support passing a
;; project name.
(replace-regexp-in-string
(rx bol (0+ any)
"style: .TH missing fourth argument; "
"suggest package/project name and version"
(0+ any) eol)
"")
;; We do support date via #+DATE keyword, but it
;; is not enabled by default for historical
;; reasons.
(replace-regexp-in-string
(rx bol (0+ any)
"style: .TH missing third argument;"
" suggest document modification"
" date in ISO 8601 format (YYYY-MM-DD)"
(0+ any) eol)
"")
(replace-regexp-in-string "\n+" ""))))))
(kill-buffer output))))
,@body))
(ert-deftest ox-man/bold ()
"Test bold text."
(ox-man/test-with-exported-test "*bold* text"
(should (search-forward "\\fBbold\\fP text"))))
(ert-deftest ox-man/code ()
"Test text formatted as code."
(ox-man/test-with-exported-test "~code~"
(should (search-forward "\\fCcode\\fP"))))
(ert-deftest ox-man/italic-underlined-verbatim ()
"Test italic, underlined and verbatim text."
(ox-man/test-with-exported-test "/italic/, _underlined_, =verbatim="
(should (search-forward "\\fIitalic\\fP"))
(should (search-forward "\\fIunderlined\\fP"))
(should (search-forward "\\fIverbatim\\fP"))))
(provide 'test-ox-man)
;;; test-ox-man.el ends here
|