forked from fniessen/emacs-leuven
-
Notifications
You must be signed in to change notification settings - Fork 0
/
org-test-fni.txt
167 lines (131 loc) · 5.31 KB
/
org-test-fni.txt
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#+TITLE: Extra tests for Org mode
#+AUTHOR: Fabrice Niessen
#+EMAIL: (concat "fniessen" at-sign "pirilampo.org")
#+DESCRIPTION:
#+KEYWORDS:
#+LANGUAGE: en
#+OPTIONS: H:4 num:nil
#+PROPERTY: header-args :tangle yes :padline yes :eval no
#+SETUPFILE: https://fniessen.github.io/org-html-themes/setup/theme-readtheorg.setup
* Extra
See http://www.randomsample.de:4457/waterfall.
* Header
#+begin_src emacs-lisp
;;;; org-test-fni.el --- Extra tests for Org mode
;; Copyright (C) 2014-2017 Fabrice Niessen
;; Author: Fabrice Niessen
;; This file is not part of GNU Emacs.
;; 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 <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Command:
;; emacs -Q --batch -L lisp/ -L testing/ -l ~/src/emacs-leuven/org-test-fni.el --eval '(setq org-confirm-babel-evaluate nil)' -f ert-run-tests-batch-and-exit
;;; Code:
;; Org mode (reverse order, so that the Org lisp directory will be found
;; before the Org contrib lisp directory).
(add-to-list 'load-path "~/Public/Repositories/org-mode/testing")
(add-to-list 'load-path "~/Public/Repositories/org-mode/contrib/lisp") ; htmlize
(add-to-list 'load-path "~/Public/Repositories/org-mode/lisp")
;; XXX This shoud be on the command-line!
(require 'ert)
(require 'ox)
#+end_src
* Helper functions
#+begin_src emacs-lisp
;;; Functions for writing tests.
(defun compare-org-html-export-files (org-file)
"Compare current export of ORG-FILE with HTML file already present on disk."
(require 'ox-html)
(let* ((html-file (concat (file-name-directory org-file)
(file-name-base org-file) ".html"))
html-contents)
;; Should have a `.html' file.
(should
(file-exists-p html-file))
;; Should have the same `.html' exported file.
(should
(equal
;; New export.
(with-temp-buffer
(insert-file-contents org-file)
(setq html-contents
(let ((org-export-allow-bind-keywords t))
(org-export-as 'html)))
(delete-region (point-min) (point-max))
(insert html-contents)
(buffer-string))
;; Old export.
(with-temp-buffer
(insert-file-contents html-file)
(buffer-string))))))
#+end_src
For inspiration:
#+begin_src emacs-lisp :tangle no
(ert-deftest test-ob-exp/org-babel-exp-src-blocks/w-no-headers ()
"Testing export without any headlines in the Org mode file."
(require 'ox-html)
(let ((html-file (concat (file-name-sans-extension org-test-no-heading-file)
".html")))
(when (file-exists-p html-file) (delete-file html-file))
(org-test-in-example-file org-test-no-heading-file
;; Export the file to HTML.
(org-export-to-file 'html html-file))
;; Should create a .html file.
(should (file-exists-p html-file))
;; Should not create a file with "::" appended to it's name.
(should-not (file-exists-p (concat org-test-no-heading-file "::")))
(when (file-exists-p html-file) (delete-file html-file))))
(ert-deftest test-ob-exp/org-babel-exp-src-blocks/w-no-file ()
"Testing export from buffers which are not visiting any file."
(require 'ox-html)
(let ((name (generate-new-buffer-name "*Org HTML Export*")))
(org-test-in-example-file nil
(org-export-to-buffer 'html name nil nil nil t))
;; Should create a HTML buffer.
(should (buffer-live-p (get-buffer name)))
;; Should contain the content of the buffer.
(with-current-buffer (get-buffer name)
(should (string-match (regexp-quote org-test-file-ob-anchor)
(buffer-string))))
(when (get-buffer name) (kill-buffer name))))
#+end_src
* Tests
Files to test:
- sample Org file
- example.txt
- ERT Refcard
- Babel Refcard
- Beamer Refcard
- Emacs-Leuven
#+begin_src emacs-lisp
;;; Internal tests.
(ert-deftest test-org-export/export-html-backend-test-file ()
"Compare current export of ORG-FILE with HTML file already present on disk."
(compare-org-html-export-files "~/src/emacs-leuven/org-test-sample.org"))
;; (ert 'test-org-export/export-html-backend-test-file)
#+end_src
#+begin_src emacs-lisp :tangle no
(ert-deftest test-org-export/export-html-backend-example-file ()
"Compare current export of ORG-FILE with HTML file already present on disk."
(compare-org-html-export-files "~/src/org-style/example.txt"))
;; (ert 'test-org-export/export-html-backend-example-file)
#+end_src
#+begin_src emacs-lisp :tangle no
(ert-deftest test-org-export/export-html-backend-ERT-refcard-file ()
"Compare current export of ORG-FILE with HTML file already present on disk."
(compare-org-html-export-files "~/src/reference-cards/ERT-refcard.txt"))
;; (ert 'test-org-export/export-html-backend-ERT-refcard-file)
#+end_src
* Footer
#+begin_src emacs-lisp
(provide 'org-test-fni)
;;; org-test-fni.el ends here
#+end_src