org.texi: Delete misplaced colon
[org-mode.git] / testing / lisp / test-ob-lilypond.el
blob400d4c88c49e040cd26af1fe8e39de4c01b401c8
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-pdf ()
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 (string-prefix-p "No pdf file generated"
273 (org-babel-lilypond-attempt-to-open-pdf pdf-file)))
274 (setq org-babel-lilypond-display-pdf-post-tangle post-tangle)))
276 (ert-deftest ob-lilypond/ly-attempt-to-play-midi ()
277 (let ((post-tangle org-babel-lilypond-play-midi-post-tangle)
278 (org-babel-lilypond-file (concat
279 org-babel-lilypond-here
280 "../examples/ob-lilypond-test.ly"))
281 (midi-file (concat
282 org-babel-lilypond-here
283 "../examples/ob-lilypond-test.midi")))
284 (setq org-babel-lilypond-play-midi-post-tangle t)
285 (when (not (file-exists-p midi-file))
286 (set-buffer (get-buffer-create (file-name-nondirectory midi-file)))
287 (write-file midi-file))
288 (should (equal
289 (concat
290 org-babel-lilypond-midi-command " " midi-file)
291 (org-babel-lilypond-attempt-to-play-midi org-babel-lilypond-file t)))
292 (delete-file midi-file)
293 (kill-buffer (file-name-nondirectory midi-file))
294 (should (string-prefix-p
295 "No midi file generated"
296 (org-babel-lilypond-attempt-to-play-midi midi-file)))
297 (setq org-babel-lilypond-play-midi-post-tangle post-tangle)))
299 (ert-deftest ob-lilypond/ly-toggle-midi-play-toggles-flag ()
300 (if org-babel-lilypond-play-midi-post-tangle
301 (progn
302 (org-babel-lilypond-toggle-midi-play)
303 (should (not org-babel-lilypond-play-midi-post-tangle))
304 (org-babel-lilypond-toggle-midi-play)
305 (should org-babel-lilypond-play-midi-post-tangle))
306 (org-babel-lilypond-toggle-midi-play)
307 (should org-babel-lilypond-play-midi-post-tangle)
308 (org-babel-lilypond-toggle-midi-play)
309 (should (not org-babel-lilypond-play-midi-post-tangle))))
311 (ert-deftest ob-lilypond/ly-toggle-pdf-display-toggles-flag ()
312 (if org-babel-lilypond-display-pdf-post-tangle
313 (progn
314 (org-babel-lilypond-toggle-pdf-display)
315 (should (not org-babel-lilypond-display-pdf-post-tangle))
316 (org-babel-lilypond-toggle-pdf-display)
317 (should org-babel-lilypond-display-pdf-post-tangle))
318 (org-babel-lilypond-toggle-pdf-display)
319 (should org-babel-lilypond-display-pdf-post-tangle)
320 (org-babel-lilypond-toggle-pdf-display)
321 (should (not org-babel-lilypond-display-pdf-post-tangle))))
323 (ert-deftest ob-lilypond/ly-toggle-pdf-generation-toggles-flag ()
324 (if org-babel-lilypond-gen-pdf
325 (progn
326 (org-babel-lilypond-toggle-pdf-generation)
327 (should (not org-babel-lilypond-gen-pdf))
328 (org-babel-lilypond-toggle-pdf-generation)
329 (should org-babel-lilypond-gen-pdf))
330 (org-babel-lilypond-toggle-pdf-generation)
331 (should org-babel-lilypond-gen-pdf)
332 (org-babel-lilypond-toggle-pdf-generation)
333 (should (not org-babel-lilypond-gen-pdf))))
335 (ert-deftest ob-lilypond/ly-toggle-arrange-mode ()
336 (if org-babel-lilypond-arrange-mode
337 (progn
338 (org-babel-lilypond-toggle-arrange-mode)
339 (should (not org-babel-lilypond-arrange-mode))
340 (org-babel-lilypond-toggle-arrange-mode)
341 (should org-babel-lilypond-arrange-mode))
342 (org-babel-lilypond-toggle-arrange-mode)
343 (should org-babel-lilypond-arrange-mode)
344 (org-babel-lilypond-toggle-arrange-mode)
345 (should (not org-babel-lilypond-arrange-mode))))
347 (ert-deftest ob-lilypond/ly-toggle-png-generation-toggles-flag ()
348 (if org-babel-lilypond-gen-png
349 (progn
350 (org-babel-lilypond-toggle-png-generation)
351 (should (not org-babel-lilypond-gen-png))
352 (org-babel-lilypond-toggle-png-generation)
353 (should org-babel-lilypond-gen-png))
354 (org-babel-lilypond-toggle-png-generation)
355 (should org-babel-lilypond-gen-png)
356 (org-babel-lilypond-toggle-png-generation)
357 (should (not org-babel-lilypond-gen-png))))
359 (ert-deftest ob-lilypond/ly-toggle-html-generation-toggles-flag ()
360 (if org-babel-lilypond-gen-html
361 (progn
362 (org-babel-lilypond-toggle-html-generation)
363 (should (not org-babel-lilypond-gen-html))
364 (org-babel-lilypond-toggle-html-generation)
365 (should org-babel-lilypond-gen-html))
366 (org-babel-lilypond-toggle-html-generation)
367 (should org-babel-lilypond-gen-html)
368 (org-babel-lilypond-toggle-html-generation)
369 (should (not org-babel-lilypond-gen-html))))
371 (ert-deftest ob-lilypond/ly-switch-extension-with-extensions ()
372 (should (equal "test-name.xyz"
373 (org-babel-lilypond-switch-extension "test-name" ".xyz")))
374 (should (equal "test-name.xyz"
375 (org-babel-lilypond-switch-extension "test-name.abc" ".xyz")))
376 (should (equal "test-name"
377 (org-babel-lilypond-switch-extension "test-name.abc" ""))))
379 (ert-deftest ob-lilypond/ly-switch-extension-with-paths ()
380 (should (equal "/some/path/to/test-name.xyz"
381 (org-babel-lilypond-switch-extension "/some/path/to/test-name" ".xyz"))))
383 (ert-deftest ob-lilypond/ly-get-header-args ()
384 (should (equal '((:tangle . "yes")
385 (:noweb . "yes")
386 (:results . "silent")
387 (:cache . "yes")
388 (:comments . "yes"))
389 (org-babel-lilypond-set-header-args t)))
390 (should (equal '((:results . "file")
391 (:exports . "results"))
392 (org-babel-lilypond-set-header-args nil))))
394 (ert-deftest ob-lilypond/ly-set-header-args ()
395 (org-babel-lilypond-set-header-args t)
396 (should (equal '((:tangle . "yes")
397 (:noweb . "yes")
398 (:results . "silent")
399 (:cache . "yes")
400 (:comments . "yes"))
401 org-babel-default-header-args:lilypond))
402 (org-babel-lilypond-set-header-args nil)
403 (should (equal '((:results . "file")
404 (:exports . "results"))
405 org-babel-default-header-args:lilypond)))
407 (provide 'test-ob-lilypond)
409 ;;; test-ob-lilypond.el ends here