1 ;;; test-ob-lilypond.el --- tests for ob-lilypond.el
3 ;; Copyright (c) 2010-2013 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"))
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 `(,(ly-determine-ly-path) ;program
59 ,(if ly-gen-png
"--png" "") ;&rest...
60 ,(if ly-gen-html
"--html" "")
61 ,(if ly-gen-pdf
"--pdf" "")
62 ,(if ly-use-eps
"-dbackend=eps" "")
63 ,(if ly-gen-svg
"-dbackend=svg" "")
66 (ly-compile-lilyfile "test-file.ly" t
))))
68 (ert-deftest ob-lilypond
/ly-compile-post-tangle
()
69 (should (boundp 'ly-compile-post-tangle
)))
71 (ert-deftest ob-lilypond
/ly-display-pdf-post-tangle
()
72 (should (boundp 'ly-display-pdf-post-tangle
)))
74 (ert-deftest ob-lilypond
/ly-play-midi-post-tangle
()
75 (should (boundp 'ly-play-midi-post-tangle
)))
77 (ert-deftest ob-lilypond
/ly-OSX-ly-path
()
78 (should (boundp 'ly-OSX-ly-path
))
79 (should (stringp ly-OSX-ly-path
)))
81 (ert-deftest ob-lilypond
/ly-OSX-pdf-path
()
82 (should (boundp 'ly-OSX-pdf-path
))
83 (should (stringp ly-OSX-pdf-path
)))
85 (ert-deftest ob-lilypond
/ly-OSX-midi-path
()
86 (should (boundp 'ly-OSX-midi-path
))
87 (should (stringp ly-OSX-midi-path
)))
89 (ert-deftest ob-lilypond
/ly-nix-ly-path
()
90 (should (boundp 'ly-nix-ly-path
))
91 (should (stringp ly-nix-ly-path
)))
93 (ert-deftest ob-lilypond
/ly-nix-pdf-path
()
94 (should (boundp 'ly-nix-pdf-path
))
95 (should (stringp ly-nix-pdf-path
)))
97 (ert-deftest ob-lilypond
/ly-nix-midi-path
()
98 (should (boundp 'ly-nix-midi-path
))
99 (should (stringp ly-nix-midi-path
)))
101 (ert-deftest ob-lilypond
/ly-w32-ly-path
()
102 (should (boundp 'ly-w32-ly-path
))
103 (should (stringp ly-w32-ly-path
)))
105 (ert-deftest ob-lilypond
/ly-w32-pdf-path
()
106 (should (boundp 'ly-w32-pdf-path
))
107 (should (stringp ly-w32-pdf-path
)))
109 (ert-deftest ob-lilypond
/ly-w32-midi-path
()
110 (should (boundp 'ly-w32-midi-path
))
111 (should (stringp ly-w32-midi-path
)))
113 (ert-deftest ob-lilypond
/ly-gen-png
()
114 (should (boundp 'ly-gen-png
)))
116 (ert-deftest ob-lilypond
/ly-gen-svg
()
117 (should (boundp 'ly-gen-svg
)))
119 (ert-deftest ob-lilypond
/ly-gen-html
()
120 (should (boundp 'ly-gen-html
)))
122 (ert-deftest ob-lilypond
/ly-gen-html
()
123 (should (boundp 'ly-gen-pdf
)))
125 (ert-deftest ob-lilypond
/use-eps
()
126 (should (boundp 'ly-use-eps
)))
128 (ert-deftest ob-lilypond
/ly-arrange-mode
()
129 (should (boundp 'ly-arrange-mode
)))
131 ;; (ert-deftest ob-lilypond/org-babel-default-header-args:lilypond ()
132 ;; (should (equal '((:tangle . "yes")
134 ;; (:results . "silent")
135 ;; (:comments . "yes"))
136 ;; org-babel-default-header-args:lilypond)))
139 (ert-deftest ob-lilypond
/org-babel-expand-body
:lilypond
()
140 (should (equal "This is a test"
141 (org-babel-expand-body:lilypond
"This is a test" ()))))
143 ;;TODO (ert-deftest ly-test-org-babel-execute:lilypond ())
144 (ert-deftest ob-lilypond
/ly-check-for-compile-error
()
145 (set-buffer (get-buffer-create "*lilypond*"))
147 (should (not (ly-check-for-compile-error nil t
)))
148 (insert-file-contents (concat ly-here
149 "../examples/ob-lilypond-test.error")
151 (goto-char (point-min))
152 (should (ly-check-for-compile-error nil t
))
153 (kill-buffer "*lilypond*"))
155 (ert-deftest ob-lilypond
/ly-process-compile-error
()
156 (find-file-other-window (concat
158 "../examples/ob-lilypond-broken.org"))
159 (set-buffer (get-buffer-create "*lilypond*"))
160 (insert-file-contents (concat
162 "../examples/ob-lilypond-test.error")
164 (goto-char (point-min))
165 (search-forward "error:" nil t
)
167 (ly-process-compile-error (concat
169 "../examples/ob-lilypond-broken.ly"))
171 (set-buffer "ob-lilypond-broken.org")
172 (should (equal 238 (point)))
173 (exchange-point-and-mark)
174 (should (equal (+ 238 (length "line 25")) (point)))
175 (kill-buffer "*lilypond*")
176 (kill-buffer "ob-lilypond-broken.org"))
178 (ert-deftest ob-lilypond
/ly-mark-error-line
()
179 (let ((file-name (concat
181 "../examples/ob-lilypond-broken.org"))
182 (expected-point-min 198)
183 (expected-point-max 205)
185 (find-file-other-window file-name
)
186 (ly-mark-error-line file-name line
)
187 (should (equal expected-point-min
(point)))
189 (exchange-point-and-mark)
190 (should (= expected-point-max
(point)))
191 (kill-buffer (file-name-nondirectory file-name
))))
193 (ert-deftest ob-lilypond
/ly-parse-line-num
()
195 (insert-file-contents (concat
197 "../examples/ob-lilypond-test.error")
199 (goto-char (point-min))
200 (search-forward "error:")
201 (should (equal 25 (ly-parse-line-num (current-buffer))))))
203 (ert-deftest ob-lilypond
/ly-parse-error-line
()
204 (let ((ly-file (concat
206 "../examples/ob-lilypond-broken.ly")))
207 (should (equal "line 20"
208 (ly-parse-error-line ly-file
20)))
209 (should (not (ly-parse-error-line ly-file
0)))))
211 (ert-deftest ob-lilypond
/ly-attempt-to-open-pdf
()
212 (let ((post-tangle ly-display-pdf-post-tangle
)
215 "../examples/ob-lilypond-test.ly"))
218 "../examples/ob-lilypond-test.pdf")))
219 (setq ly-display-pdf-post-tangle t
)
220 (when (not (file-exists-p pdf-file
))
221 (set-buffer (get-buffer-create (file-name-nondirectory pdf-file
)))
222 (write-file pdf-file
))
225 (ly-determine-pdf-path) " " pdf-file
)
226 (ly-attempt-to-open-pdf ly-file t
)))
227 (delete-file pdf-file
)
228 (kill-buffer (file-name-nondirectory pdf-file
))
230 "No pdf file generated so can't display!"
231 (ly-attempt-to-open-pdf pdf-file
)))
232 (setq ly-display-pdf-post-tangle post-tangle
)))
234 (ert-deftest ob-lilypond
/ly-attempt-to-play-midi
()
235 (let ((post-tangle ly-play-midi-post-tangle
)
238 "../examples/ob-lilypond-test.ly"))
241 "../examples/ob-lilypond-test.midi")))
242 (setq ly-play-midi-post-tangle t
)
243 (when (not (file-exists-p midi-file
))
244 (set-buffer (get-buffer-create (file-name-nondirectory midi-file
)))
245 (write-file midi-file
))
248 (ly-determine-midi-path) " " midi-file
)
249 (ly-attempt-to-play-midi ly-file t
)))
250 (delete-file midi-file
)
251 (kill-buffer (file-name-nondirectory midi-file
))
253 "No midi file generated so can't play!"
254 (ly-attempt-to-play-midi midi-file
)))
255 (setq ly-play-midi-post-tangle post-tangle
)))
257 (ert-deftest ob-lilypond
/ly-determine-ly-path
()
258 (should (equal ly-OSX-ly-path
259 (ly-determine-ly-path "darwin")))
260 (should (equal ly-w32-ly-path
261 (ly-determine-ly-path "windows-nt")))
262 (should (equal ly-nix-ly-path
263 (ly-determine-ly-path "nix"))))
265 (ert-deftest ob-lilypond
/ly-determine-pdf-path
()
266 (should (equal ly-OSX-pdf-path
267 (ly-determine-pdf-path "darwin")))
268 (should (equal ly-w32-pdf-path
269 (ly-determine-pdf-path "windows-nt")))
270 (should (equal ly-nix-pdf-path
271 (ly-determine-pdf-path "nix"))))
273 (ert-deftest ob-lilypond
/ly-determine-midi-path
()
274 (should (equal ly-OSX-midi-path
275 (ly-determine-midi-path "darwin")))
276 (should (equal ly-w32-midi-path
277 (ly-determine-midi-path "windows-nt")))
278 (should (equal ly-nix-midi-path
279 (ly-determine-midi-path "nix"))))
281 (ert-deftest ob-lilypond
/ly-toggle-midi-play-toggles-flag
()
282 (if ly-play-midi-post-tangle
284 (ly-toggle-midi-play)
285 (should (not ly-play-midi-post-tangle
))
286 (ly-toggle-midi-play)
287 (should ly-play-midi-post-tangle
))
288 (ly-toggle-midi-play)
289 (should ly-play-midi-post-tangle
)
290 (ly-toggle-midi-play)
291 (should (not ly-play-midi-post-tangle
))))
293 (ert-deftest ob-lilypond
/ly-toggle-pdf-display-toggles-flag
()
294 (if ly-display-pdf-post-tangle
296 (ly-toggle-pdf-display)
297 (should (not ly-display-pdf-post-tangle
))
298 (ly-toggle-pdf-display)
299 (should ly-display-pdf-post-tangle
))
300 (ly-toggle-pdf-display)
301 (should ly-display-pdf-post-tangle
)
302 (ly-toggle-pdf-display)
303 (should (not ly-display-pdf-post-tangle
))))
305 (ert-deftest ob-lilypond
/ly-toggle-pdf-generation-toggles-flag
()
308 (ly-toggle-pdf-generation)
309 (should (not ly-gen-pdf
))
310 (ly-toggle-pdf-generation)
312 (ly-toggle-pdf-generation)
314 (ly-toggle-pdf-generation)
315 (should (not ly-gen-pdf
))))
317 (ert-deftest ob-lilypond
/ly-toggle-arrange-mode
()
320 (ly-toggle-arrange-mode)
321 (should (not ly-arrange-mode
))
322 (ly-toggle-arrange-mode)
323 (should ly-arrange-mode
))
324 (ly-toggle-arrange-mode)
325 (should ly-arrange-mode
)
326 (ly-toggle-arrange-mode)
327 (should (not ly-arrange-mode
))))
329 (ert-deftest ob-lilypond
/ly-toggle-png-generation-toggles-flag
()
332 (ly-toggle-png-generation)
333 (should (not ly-gen-png
))
334 (ly-toggle-png-generation)
336 (ly-toggle-png-generation)
338 (ly-toggle-png-generation)
339 (should (not ly-gen-png
))))
341 (ert-deftest ob-lilypond
/ly-toggle-html-generation-toggles-flag
()
344 (ly-toggle-html-generation)
345 (should (not ly-gen-html
))
346 (ly-toggle-html-generation)
347 (should ly-gen-html
))
348 (ly-toggle-html-generation)
350 (ly-toggle-html-generation)
351 (should (not ly-gen-html
))))
353 (ert-deftest ob-lilypond
/ly-switch-extension-with-extensions
()
354 (should (equal "test-name.xyz"
355 (ly-switch-extension "test-name" ".xyz")))
356 (should (equal "test-name.xyz"
357 (ly-switch-extension "test-name.abc" ".xyz")))
358 (should (equal "test-name"
359 (ly-switch-extension "test-name.abc" ""))))
361 (ert-deftest ob-lilypond
/ly-switch-extension-with-paths
()
362 (should (equal "/some/path/to/test-name.xyz"
363 (ly-switch-extension "/some/path/to/test-name" ".xyz"))))
365 (ert-deftest ob-lilypond
/ly-get-header-args
()
366 (should (equal '((:tangle .
"yes")
368 (:results .
"silent")
371 (ly-set-header-args t
)))
372 (should (equal '((:results .
"file")
373 (:exports .
"results"))
374 (ly-set-header-args nil
))))
376 (ert-deftest ob-lilypond
/ly-set-header-args
()
377 (ly-set-header-args t
)
378 (should (equal '((:tangle .
"yes")
380 (:results .
"silent")
383 org-babel-default-header-args
:lilypond
))
384 (ly-set-header-args nil
)
385 (should (equal '((:results .
"file")
386 (:exports .
"results"))
387 org-babel-default-header-args
:lilypond
)))
389 (provide 'test-ob-lilypond
)
391 ;;; test-ob-lilypond.el ends here