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/>.
22 (unless (featurep 'ob-lilypond
)
23 (signal 'missing-test-dependency
"Support for Lilypond code blocks"))
26 (set-buffer (get-buffer-create "test-ob-lilypond.el"))
27 (setq org-babel-lilypond-here
29 (or load-file-name
(buffer-file-name)))))
31 (ert-deftest ob-lilypond
/assert
()
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
()
42 (list org-babel-tangle-lang-exts
))
44 (when (equal (car list
) '("LilyPond" .
"ly"))
46 (setq list
(cdr list
)))
49 (ert-deftest ob-lilypond
/org-babel-prep-session
:lilypond
()
50 (should-error (org-babel-prep-session:lilypond nil nil
))
53 (ert-deftest ob-lilypond
/ly-compile-lilyfile
()
55 `(,org-babel-lilypond-ly-command
;program
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" "")
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
)
97 org-babel-lilypond-ly-command
98 org-babel-lilypond-pdf-command
99 org-babel-lilypond-midi-command
)
101 "/Applications/lilypond.app/Contents/Resources/bin/lilypond"
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
)
113 org-babel-lilypond-ly-command
114 org-babel-lilypond-pdf-command
115 org-babel-lilypond-midi-command
)
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
)
129 org-babel-lilypond-ly-command
130 org-babel-lilypond-pdf-command
131 org-babel-lilypond-midi-command
)
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"))
147 org-babel-lilypond-ly-command
148 org-babel-lilypond-pdf-command
149 org-babel-lilypond-midi-command
)
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")
177 ;; (:results . "silent")
178 ;; (:comments . "yes"))
179 ;; org-babel-default-header-args:lilypond)))
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*"))
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")
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")
207 (goto-char (point-min))
208 (search-forward "error:" nil t
)
210 (org-babel-lilypond-process-compile-error (concat
211 org-babel-lilypond-here
212 "../examples/ob-lilypond-broken.ly"))
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)
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
()
238 (insert-file-contents (concat
239 org-babel-lilypond-here
240 "../examples/ob-lilypond-test.error")
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"))
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
))
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"))
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
))
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
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
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
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
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
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
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")
386 (:results .
"silent")
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")
398 (:results .
"silent")
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