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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
| | ;;; 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"))))
(ert-deftest ox-man/default ()
"Test default values."
(ox-man/test-with-exported-test
""
(should (string= (buffer-string) ".TH \"\" \"1\" \"\" \n"))))
(ert-deftest ox-man/title-only ()
"Test title only."
(ox-man/test-with-exported-test
"#+TITLE: Emacs"
(should (string= (buffer-string) ".TH \"Emacs\" \"1\" \"\" \n"))))
(ert-deftest ox-man/section-only ()
"Test version (1 is the default value, use 2 instead)."
(ox-man/test-with-exported-test
"#+MAN_CLASS_OPTIONS: :section-id \"2\""
(should (string= (buffer-string) ".TH \"\" \"2\" \"\" \n"))))
(ert-deftest ox-man/title-date-section ()
"Test main options."
(ox-man/test-with-exported-test
"#+TITLE: Emacs
#+DATE: 1985-03-20
#+MAN_CLASS_OPTIONS: :section-id \"2\""
(should (string= (buffer-string) ".TH \"Emacs\" \"2\" \"1985-03-20\" \n"))))
(ert-deftest ox-man/title-date-section-release ()
"Test release."
(ox-man/test-with-exported-test
"#+TITLE: Emacs
#+DATE: 1985-03-20
#+MAN_CLASS_OPTIONS: :section-id \"2\" :release \"Emacs 13\""
(should (string= (buffer-string) ".TH \"Emacs\" \"2\" \"1985-03-20\" \"Emacs 13\" \n"))))
(ert-deftest ox-man/title-date-section-release-header ()
"Test header."
(ox-man/test-with-exported-test
"#+TITLE: Emacs
#+DATE: 1985-03-20
#+MAN_CLASS_OPTIONS: :section-id \"2\" :release \"Emacs 13\" :header \"GNU\""
(should (string= (buffer-string) ".TH \"Emacs\" \"2\" \"1985-03-20\" \"Emacs 13\" \"GNU\" \n"))))
(provide 'test-ox-man)
;;; test-ox-man.el ends here
|