emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
blob a7a41040bf4d02a0f77058aa8f920e891fb0e9f1 4946 bytes (raw)
name: testing/lisp/test-ox-man.el 	 # note: path name is non-authoritative(*)

  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

debug log:

solving a7a41040b ...
found a7a41040b in https://list.orgmode.org/orgmode/322940b6-deb8-4f44-98b6-7bbdab452063@malloc.fr/
found 12f839ea8 in https://git.savannah.gnu.org/cgit/emacs/org-mode.git
preparing index
index prepared:
100644 12f839ea84e1f68d6b53046d08aa50c74d1dcd34	testing/lisp/test-ox-man.el

applying [1/1] https://list.orgmode.org/orgmode/322940b6-deb8-4f44-98b6-7bbdab452063@malloc.fr/
diff --git a/testing/lisp/test-ox-man.el b/testing/lisp/test-ox-man.el
index 12f839ea8..a7a41040b 100644

Checking patch testing/lisp/test-ox-man.el...
Applied patch testing/lisp/test-ox-man.el cleanly.

index at:
100644 a7a41040bf4d02a0f77058aa8f920e891fb0e9f1	testing/lisp/test-ox-man.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).