ox: Simplify fuzzy link matching
[org-mode/org-tableheadings.git] / testing / lisp / test-ob-lilypond.el
blob355f91f785170f81c7ed9962596a1d86d8d812fb
1 ;;; test-ob-lilypond.el --- tests for ob-lilypond.el
3 ;; Copyright (c) 2010-2014 Martyn Jago
4 ;; Authors: Martyn Jago
6 ;; This file is not part of GNU Emacs.
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ;;; Code:
22 (unless (featurep 'ob-lilypond)
23 (signal 'missing-test-dependency "Support for Lilypond code blocks"))
25 (save-excursion
26 (set-buffer (get-buffer-create "test-ob-lilypond.el"))
27 (setq org-babel-lilypond-here
28 (file-name-directory
29 (or load-file-name (buffer-file-name)))))
31 (ert-deftest ob-lilypond/assert ()
32 (should t))
34 (ert-deftest ob-lilypond/feature-provision ()
35 (should (featurep 'ob-lilypond)))
37 (ert-deftest ob-lilypond/check-lilypond-alias ()
38 (should (fboundp 'lilypond-mode)))
40 (ert-deftest ob-lilypond/org-babel-tangle-lang-exts ()
41 (let ((found nil)
42 (list org-babel-tangle-lang-exts))
43 (while list
44 (when (equal (car list) '("LilyPond" . "ly"))
45 (setq found t))
46 (setq list (cdr list)))
47 (should found)))
49 (ert-deftest ob-lilypond/org-babel-prep-session:lilypond ()
50 (should-error (org-babel-prep-session:lilypond nil nil))
51 :type 'error)
53 (ert-deftest ob-lilypond/ly-compile-lilyfile ()
54 (should (equal
55 `(,org-babel-lilypond-ly-command ;program
56 nil ;infile
57 "*lilypond*" ;buffer
58 t ;display
59 ,(if org-babel-lilypond-gen-png "--png" "") ;&rest...
60 ,(if org-babel-lilypond-gen-html "--html" "")
61 ,(if org-babel-lilypond-gen-pdf "--pdf" "")
62 ,(if org-babel-lilypond-use-eps "-dbackend=eps" "")
63 ,(if org-babel-lilypond-gen-svg "-dbackend=svg" "")
64 "--output=test-file"
65 "test-file.ly")
66 (org-babel-lilypond-compile-lilyfile "test-file.ly" t))))
68 (ert-deftest ob-lilypond/ly-compile-post-tangle ()
69 (should (boundp 'org-babel-lilypond-compile-post-tangle)))
71 (ert-deftest ob-lilypond/ly-display-pdf-post-tangle ()
72 (should (boundp 'org-babel-lilypond-display-pdf-post-tangle)))
74 (ert-deftest ob-lilypond/ly-play-midi-post-tangle ()
75 (should (boundp 'org-babel-lilypond-play-midi-post-tangle)))
77 (ert-deftest ob-lilypond/ly-command-ly/bound ()
78 (should (boundp 'org-babel-lilypond-ly-command)))
79 (ert-deftest ob-lilypond/ly-command-ly/stringp ()
80 (should (stringp org-babel-lilypond-ly-command)))
81 (ert-deftest ob-lilypond/ly-command-pdf/bound ()
82 (should (boundp 'org-babel-lilypond-pdf-command)))
83 (ert-deftest ob-lilypond/ly-command-pdf/stringp ()
84 (should (stringp org-babel-lilypond-pdf-command)))
85 (ert-deftest ob-lilypond/ly-command-midi/bound ()
86 (should (boundp 'org-babel-lilypond-midi-command)))
87 (ert-deftest ob-lilypond/ly-command-midi/stringp ()
88 (should (stringp org-babel-lilypond-midi-command)))
89 (ert-deftest ob-lilypond/ly-commands/darwin ()
90 (let ((system-type 'darwin)
91 org-babel-lilypond-ly-command
92 org-babel-lilypond-pdf-command
93 org-babel-lilypond-midi-command)
94 (custom-reevaluate-setting 'org-babel-lilypond-commands)
95 (should (equal
96 (list
97 org-babel-lilypond-ly-command
98 org-babel-lilypond-pdf-command
99 org-babel-lilypond-midi-command)
100 (list
101 "/Applications/lilypond.app/Contents/Resources/bin/lilypond"
102 "open"
103 "open"))))
104 (custom-reevaluate-setting 'org-babel-lilypond-commands))
105 (ert-deftest ob-lilypond/ly-commands/windows-nt ()
106 (let ((system-type 'windows-nt)
107 org-babel-lilypond-ly-command
108 org-babel-lilypond-pdf-command
109 org-babel-lilypond-midi-command)
110 (custom-reevaluate-setting 'org-babel-lilypond-commands)
111 (should (equal
112 (list
113 org-babel-lilypond-ly-command
114 org-babel-lilypond-pdf-command
115 org-babel-lilypond-midi-command)
116 (list
117 "lilypond"
119 ""))))
120 (custom-reevaluate-setting 'org-babel-lilypond-commands))
121 (ert-deftest ob-lilypond/ly-commands/other ()
122 (let ((system-type 'other)
123 org-babel-lilypond-ly-command
124 org-babel-lilypond-pdf-command
125 org-babel-lilypond-midi-command)
126 (custom-reevaluate-setting 'org-babel-lilypond-commands)
127 (should (equal
128 (list
129 org-babel-lilypond-ly-command
130 org-babel-lilypond-pdf-command
131 org-babel-lilypond-midi-command)
132 (list
133 "lilypond"
134 "xdg-open"
135 "xdg-open"))))
136 (custom-reevaluate-setting 'org-babel-lilypond-commands))
138 (ert-deftest ob-lilypond/ly-commands/customize ()
139 (let ((system-type 'other)
140 org-babel-lilypond-ly-command
141 org-babel-lilypond-pdf-command
142 org-babel-lilypond-midi-command)
143 (custom-initialize-reset 'org-babel-lilypond-commands
144 '(list "nonsense" "bla" "fasel"))
145 (should (equal
146 (list
147 org-babel-lilypond-ly-command
148 org-babel-lilypond-pdf-command
149 org-babel-lilypond-midi-command)
150 (list
151 "nonsense"
152 "bla"
153 "fasel"))))
154 (custom-reevaluate-setting 'org-babel-lilypond-commands))
156 (ert-deftest ob-lilypond/ly-gen-png ()
157 (should (boundp 'org-babel-lilypond-gen-png)))
159 (ert-deftest ob-lilypond/ly-gen-svg ()
160 (should (boundp 'org-babel-lilypond-gen-svg)))
162 (ert-deftest ob-lilypond/ly-gen-html ()
163 (should (boundp 'org-babel-lilypond-gen-html)))
165 (ert-deftest ob-lilypond/ly-gen-html ()
166 (should (boundp 'org-babel-lilypond-gen-pdf)))
168 (ert-deftest ob-lilypond/use-eps ()
169 (should (boundp 'org-babel-lilypond-use-eps)))
171 (ert-deftest ob-lilypond/ly-arrange-mode ()
172 (should (boundp 'org-babel-lilypond-arrange-mode)))
174 ;; (ert-deftest ob-lilypond/org-babel-default-header-args:lilypond ()
175 ;; (should (equal '((:tangle . "yes")
176 ;; (:noweb . "yes")
177 ;; (:results . "silent")
178 ;; (:comments . "yes"))
179 ;; org-babel-default-header-args:lilypond)))
181 ;;TODO finish...
182 (ert-deftest ob-lilypond/org-babel-expand-body:lilypond ()
183 (should (equal "This is a test"
184 (org-babel-expand-body:lilypond "This is a test" ()))))
186 ;;TODO (ert-deftest org-babel-lilypond-test-org-babel-execute:lilypond ())
187 (ert-deftest ob-lilypond/ly-check-for-compile-error ()
188 (set-buffer (get-buffer-create "*lilypond*"))
189 (erase-buffer)
190 (should (not (org-babel-lilypond-check-for-compile-error nil t)))
191 (insert-file-contents (concat org-babel-lilypond-here
192 "../examples/ob-lilypond-test.error")
193 nil nil nil t)
194 (goto-char (point-min))
195 (should (org-babel-lilypond-check-for-compile-error nil t))
196 (kill-buffer "*lilypond*"))
198 (ert-deftest ob-lilypond/ly-process-compile-error ()
199 (find-file-other-window (concat
200 org-babel-lilypond-here
201 "../examples/ob-lilypond-broken.org"))
202 (set-buffer (get-buffer-create "*lilypond*"))
203 (insert-file-contents (concat
204 org-babel-lilypond-here
205 "../examples/ob-lilypond-test.error")
206 nil nil nil t)
207 (goto-char (point-min))
208 (search-forward "error:" nil t)
209 (should-error
210 (org-babel-lilypond-process-compile-error (concat
211 org-babel-lilypond-here
212 "../examples/ob-lilypond-broken.ly"))
213 :type 'error)
214 (set-buffer "ob-lilypond-broken.org")
215 (should (equal 238 (point)))
216 (exchange-point-and-mark)
217 (should (equal (+ 238 (length "line 25")) (point)))
218 (kill-buffer "*lilypond*")
219 (kill-buffer "ob-lilypond-broken.org"))
221 (ert-deftest ob-lilypond/ly-mark-error-line ()
222 (let ((file-name (concat
223 org-babel-lilypond-here
224 "../examples/ob-lilypond-broken.org"))
225 (expected-point-min 198)
226 (expected-point-max 205)
227 (line "line 20"))
228 (find-file-other-window file-name)
229 (org-babel-lilypond-mark-error-line file-name line)
230 (should (equal expected-point-min (point)))
232 (exchange-point-and-mark)
233 (should (= expected-point-max (point)))
234 (kill-buffer (file-name-nondirectory file-name))))
236 (ert-deftest ob-lilypond/ly-parse-line-num ()
237 (with-temp-buffer
238 (insert-file-contents (concat
239 org-babel-lilypond-here
240 "../examples/ob-lilypond-test.error")
241 nil nil nil t)
242 (goto-char (point-min))
243 (search-forward "error:")
244 (should (equal 25 (org-babel-lilypond-parse-line-num (current-buffer))))))
246 (ert-deftest ob-lilypond/ly-parse-error-line ()
247 (let ((org-babel-lilypond-file (concat
248 org-babel-lilypond-here
249 "../examples/ob-lilypond-broken.ly")))
250 (should (equal "line 20"
251 (org-babel-lilypond-parse-error-line org-babel-lilypond-file 20)))
252 (should (not (org-babel-lilypond-parse-error-line org-babel-lilypond-file 0)))))
254 (ert-deftest ob-lilypond/ly-attempt-to-open-pdf ()
255 (let ((post-tangle org-babel-lilypond-display-pdf-post-tangle)
256 (org-babel-lilypond-file (concat
257 org-babel-lilypond-here
258 "../examples/ob-lilypond-test.ly"))
259 (pdf-file (concat
260 org-babel-lilypond-here
261 "../examples/ob-lilypond-test.pdf")))
262 (setq org-babel-lilypond-display-pdf-post-tangle t)
263 (when (not (file-exists-p pdf-file))
264 (set-buffer (get-buffer-create (file-name-nondirectory pdf-file)))
265 (write-file pdf-file))
266 (should (equal
267 (concat
268 org-babel-lilypond-pdf-command " " pdf-file)
269 (org-babel-lilypond-attempt-to-open-pdf org-babel-lilypond-file t)))
270 (delete-file pdf-file)
271 (kill-buffer (file-name-nondirectory pdf-file))
272 (should (equal
273 "No pdf file generated so can't display!"
274 (org-babel-lilypond-attempt-to-open-pdf pdf-file)))
275 (setq org-babel-lilypond-display-pdf-post-tangle post-tangle)))
277 (ert-deftest ob-lilypond/ly-attempt-to-play-midi ()
278 (let ((post-tangle org-babel-lilypond-play-midi-post-tangle)
279 (org-babel-lilypond-file (concat
280 org-babel-lilypond-here
281 "../examples/ob-lilypond-test.ly"))
282 (midi-file (concat
283 org-babel-lilypond-here
284 "../examples/ob-lilypond-test.midi")))
285 (setq org-babel-lilypond-play-midi-post-tangle t)
286 (when (not (file-exists-p midi-file))
287 (set-buffer (get-buffer-create (file-name-nondirectory midi-file)))
288 (write-file midi-file))
289 (should (equal
290 (concat
291 org-babel-lilypond-midi-command " " midi-file)
292 (org-babel-lilypond-attempt-to-play-midi org-babel-lilypond-file t)))
293 (delete-file midi-file)
294 (kill-buffer (file-name-nondirectory midi-file))
295 (should (equal
296 "No midi file generated so can't play!"
297 (org-babel-lilypond-attempt-to-play-midi midi-file)))
298 (setq org-babel-lilypond-play-midi-post-tangle post-tangle)))
300 (ert-deftest ob-lilypond/ly-toggle-midi-play-toggles-flag ()
301 (if org-babel-lilypond-play-midi-post-tangle
302 (progn
303 (org-babel-lilypond-toggle-midi-play)
304 (should (not org-babel-lilypond-play-midi-post-tangle))
305 (org-babel-lilypond-toggle-midi-play)
306 (should org-babel-lilypond-play-midi-post-tangle))
307 (org-babel-lilypond-toggle-midi-play)
308 (should org-babel-lilypond-play-midi-post-tangle)
309 (org-babel-lilypond-toggle-midi-play)
310 (should (not org-babel-lilypond-play-midi-post-tangle))))
312 (ert-deftest ob-lilypond/ly-toggle-pdf-display-toggles-flag ()
313 (if org-babel-lilypond-display-pdf-post-tangle
314 (progn
315 (org-babel-lilypond-toggle-pdf-display)
316 (should (not org-babel-lilypond-display-pdf-post-tangle))
317 (org-babel-lilypond-toggle-pdf-display)
318 (should org-babel-lilypond-display-pdf-post-tangle))
319 (org-babel-lilypond-toggle-pdf-display)
320 (should org-babel-lilypond-display-pdf-post-tangle)
321 (org-babel-lilypond-toggle-pdf-display)
322 (should (not org-babel-lilypond-display-pdf-post-tangle))))
324 (ert-deftest ob-lilypond/ly-toggle-pdf-generation-toggles-flag ()
325 (if org-babel-lilypond-gen-pdf
326 (progn
327 (org-babel-lilypond-toggle-pdf-generation)
328 (should (not org-babel-lilypond-gen-pdf))
329 (org-babel-lilypond-toggle-pdf-generation)
330 (should org-babel-lilypond-gen-pdf))
331 (org-babel-lilypond-toggle-pdf-generation)
332 (should org-babel-lilypond-gen-pdf)
333 (org-babel-lilypond-toggle-pdf-generation)
334 (should (not org-babel-lilypond-gen-pdf))))
336 (ert-deftest ob-lilypond/ly-toggle-arrange-mode ()
337 (if org-babel-lilypond-arrange-mode
338 (progn
339 (org-babel-lilypond-toggle-arrange-mode)
340 (should (not org-babel-lilypond-arrange-mode))
341 (org-babel-lilypond-toggle-arrange-mode)
342 (should org-babel-lilypond-arrange-mode))
343 (org-babel-lilypond-toggle-arrange-mode)
344 (should org-babel-lilypond-arrange-mode)
345 (org-babel-lilypond-toggle-arrange-mode)
346 (should (not org-babel-lilypond-arrange-mode))))
348 (ert-deftest ob-lilypond/ly-toggle-png-generation-toggles-flag ()
349 (if org-babel-lilypond-gen-png
350 (progn
351 (org-babel-lilypond-toggle-png-generation)
352 (should (not org-babel-lilypond-gen-png))
353 (org-babel-lilypond-toggle-png-generation)
354 (should org-babel-lilypond-gen-png))
355 (org-babel-lilypond-toggle-png-generation)
356 (should org-babel-lilypond-gen-png)
357 (org-babel-lilypond-toggle-png-generation)
358 (should (not org-babel-lilypond-gen-png))))
360 (ert-deftest ob-lilypond/ly-toggle-html-generation-toggles-flag ()
361 (if org-babel-lilypond-gen-html
362 (progn
363 (org-babel-lilypond-toggle-html-generation)
364 (should (not org-babel-lilypond-gen-html))
365 (org-babel-lilypond-toggle-html-generation)
366 (should org-babel-lilypond-gen-html))
367 (org-babel-lilypond-toggle-html-generation)
368 (should org-babel-lilypond-gen-html)
369 (org-babel-lilypond-toggle-html-generation)
370 (should (not org-babel-lilypond-gen-html))))
372 (ert-deftest ob-lilypond/ly-switch-extension-with-extensions ()
373 (should (equal "test-name.xyz"
374 (org-babel-lilypond-switch-extension "test-name" ".xyz")))
375 (should (equal "test-name.xyz"
376 (org-babel-lilypond-switch-extension "test-name.abc" ".xyz")))
377 (should (equal "test-name"
378 (org-babel-lilypond-switch-extension "test-name.abc" ""))))
380 (ert-deftest ob-lilypond/ly-switch-extension-with-paths ()
381 (should (equal "/some/path/to/test-name.xyz"
382 (org-babel-lilypond-switch-extension "/some/path/to/test-name" ".xyz"))))
384 (ert-deftest ob-lilypond/ly-get-header-args ()
385 (should (equal '((:tangle . "yes")
386 (:noweb . "yes")
387 (:results . "silent")
388 (:cache . "yes")
389 (:comments . "yes"))
390 (org-babel-lilypond-set-header-args t)))
391 (should (equal '((:results . "file")
392 (:exports . "results"))
393 (org-babel-lilypond-set-header-args nil))))
395 (ert-deftest ob-lilypond/ly-set-header-args ()
396 (org-babel-lilypond-set-header-args t)
397 (should (equal '((:tangle . "yes")
398 (:noweb . "yes")
399 (:results . "silent")
400 (:cache . "yes")
401 (:comments . "yes"))
402 org-babel-default-header-args:lilypond))
403 (org-babel-lilypond-set-header-args nil)
404 (should (equal '((:results . "file")
405 (:exports . "results"))
406 org-babel-default-header-args:lilypond)))
408 (provide 'test-ob-lilypond)
410 ;;; test-ob-lilypond.el ends here