1 ;;; test-ob-lilypond.el --- tests for ob-lilypond.el
3 ;; Copyright (c) 2010-2012 Martyn Jago
4 ;; Authors: Martyn Jago
6 ;; Released under the GNU General Public License version 3
7 ;; see: http://www.gnu.org/licenses/gpl-3.0.html
10 (unless (featurep 'ob-lilypond
)
11 (signal 'missing-test-dependency
"Support for Lilypond code blocks"))
14 (set-buffer (get-buffer-create "test-ob-lilypond.el"))
17 (or load-file-name
(buffer-file-name)))))
19 (ert-deftest ob-lilypond
/assert
()
22 (ert-deftest ob-lilypond
/feature-provision
()
23 (should (featurep 'ob-lilypond
)))
25 (ert-deftest ob-lilypond
/check-lilypond-alias
()
26 (should (fboundp 'lilypond-mode
)))
28 (ert-deftest ob-lilypond
/org-babel-tangle-lang-exts
()
30 (list org-babel-tangle-lang-exts
))
32 (when (equal (car list
) '("LilyPond" .
"ly"))
34 (setq list
(cdr list
)))
37 (ert-deftest ob-lilypond
/org-babel-prep-session
:lilypond
()
38 (should-error (org-babel-prep-session:lilypond nil nil
))
41 (ert-deftest ob-lilypond
/ly-compile-lilyfile
()
43 `(,(ly-determine-ly-path) ;program
47 ,(if ly-gen-png
"--png" "") ;&rest...
48 ,(if ly-gen-html
"--html" "")
49 ,(if ly-gen-pdf
"--pdf" "")
50 ,(if ly-use-eps
"-dbackend=eps" "")
51 ,(if ly-gen-svg
"-dbackend=svg" "")
54 (ly-compile-lilyfile "test-file.ly" t
))))
56 (ert-deftest ob-lilypond
/ly-compile-post-tangle
()
57 (should (boundp 'ly-compile-post-tangle
)))
59 (ert-deftest ob-lilypond
/ly-display-pdf-post-tangle
()
60 (should (boundp 'ly-display-pdf-post-tangle
)))
62 (ert-deftest ob-lilypond
/ly-play-midi-post-tangle
()
63 (should (boundp 'ly-play-midi-post-tangle
)))
65 (ert-deftest ob-lilypond
/ly-OSX-ly-path
()
66 (should (boundp 'ly-OSX-ly-path
))
67 (should (stringp ly-OSX-ly-path
)))
69 (ert-deftest ob-lilypond
/ly-OSX-pdf-path
()
70 (should (boundp 'ly-OSX-pdf-path
))
71 (should (stringp ly-OSX-pdf-path
)))
73 (ert-deftest ob-lilypond
/ly-OSX-midi-path
()
74 (should (boundp 'ly-OSX-midi-path
))
75 (should (stringp ly-OSX-midi-path
)))
77 (ert-deftest ob-lilypond
/ly-nix-ly-path
()
78 (should (boundp 'ly-nix-ly-path
))
79 (should (stringp ly-nix-ly-path
)))
81 (ert-deftest ob-lilypond
/ly-nix-pdf-path
()
82 (should (boundp 'ly-nix-pdf-path
))
83 (should (stringp ly-nix-pdf-path
)))
85 (ert-deftest ob-lilypond
/ly-nix-midi-path
()
86 (should (boundp 'ly-nix-midi-path
))
87 (should (stringp ly-nix-midi-path
)))
89 (ert-deftest ob-lilypond
/ly-win32-ly-path
()
90 (should (boundp 'ly-win32-ly-path
))
91 (should (stringp ly-win32-ly-path
)))
93 (ert-deftest ob-lilypond
/ly-win32-pdf-path
()
94 (should (boundp 'ly-win32-pdf-path
))
95 (should (stringp ly-win32-pdf-path
)))
97 (ert-deftest ob-lilypond
/ly-win32-midi-path
()
98 (should (boundp 'ly-win32-midi-path
))
99 (should (stringp ly-win32-midi-path
)))
101 (ert-deftest ob-lilypond
/ly-gen-png
()
102 (should (boundp 'ly-gen-png
)))
104 (ert-deftest ob-lilypond
/ly-gen-svg
()
105 (should (boundp 'ly-gen-svg
)))
107 (ert-deftest ob-lilypond
/ly-gen-html
()
108 (should (boundp 'ly-gen-html
)))
110 (ert-deftest ob-lilypond
/ly-gen-html
()
111 (should (boundp 'ly-gen-pdf
)))
113 (ert-deftest ob-lilypond
/use-eps
()
114 (should (boundp 'ly-use-eps
)))
116 (ert-deftest ob-lilypond
/ly-arrange-mode
()
117 (should (boundp 'ly-arrange-mode
)))
119 ;; (ert-deftest ob-lilypond/org-babel-default-header-args:lilypond ()
120 ;; (should (equal '((:tangle . "yes")
122 ;; (:results . "silent")
123 ;; (:comments . "yes"))
124 ;; org-babel-default-header-args:lilypond)))
127 (ert-deftest ob-lilypond
/org-babel-expand-body
:lilypond
()
128 (should (equal "This is a test"
129 (org-babel-expand-body:lilypond
"This is a test" ()))))
131 ;;TODO (ert-deftest ly-test-org-babel-execute:lilypond ())
132 (ert-deftest ob-lilypond
/ly-check-for-compile-error
()
133 (set-buffer (get-buffer-create "*lilypond*"))
135 (should (not (ly-check-for-compile-error nil t
)))
136 (insert-file-contents (concat ly-here
137 "../examples/ob-lilypond-test.error")
139 (goto-char (point-min))
140 (should (ly-check-for-compile-error nil t
))
141 (kill-buffer "*lilypond*"))
143 (ert-deftest ob-lilypond
/ly-process-compile-error
()
144 (find-file-other-window (concat
146 "../examples/ob-lilypond-broken.org"))
147 (set-buffer (get-buffer-create "*lilypond*"))
148 (insert-file-contents (concat
150 "../examples/ob-lilypond-test.error")
152 (goto-char (point-min))
153 (search-forward "error:" nil t
)
155 (ly-process-compile-error (concat
157 "../examples/ob-lilypond-broken.ly"))
159 (set-buffer "ob-lilypond-broken.org")
160 (should (equal 238 (point)))
161 (exchange-point-and-mark)
162 (should (equal (+ 238 (length "line 25")) (point)))
163 (kill-buffer "*lilypond*")
164 (kill-buffer "ob-lilypond-broken.org"))
166 (ert-deftest ob-lilypond
/ly-mark-error-line
()
167 (let ((file-name (concat
169 "../examples/ob-lilypond-broken.org"))
170 (expected-point-min 198)
171 (expected-point-max 205)
173 (find-file-other-window file-name
)
174 (ly-mark-error-line file-name line
)
175 (should (equal expected-point-min
(point)))
177 (exchange-point-and-mark)
178 (should (= expected-point-max
(point)))
179 (kill-buffer (file-name-nondirectory file-name
))))
181 (ert-deftest ob-lilypond
/ly-parse-line-num
()
183 (insert-file-contents (concat
185 "../examples/ob-lilypond-test.error")
187 (goto-char (point-min))
188 (search-forward "error:")
189 (should (equal 25 (ly-parse-line-num (current-buffer))))))
191 (ert-deftest ob-lilypond
/ly-parse-error-line
()
192 (let ((ly-file (concat
194 "../examples/ob-lilypond-broken.ly")))
195 (should (equal "line 20"
196 (ly-parse-error-line ly-file
20)))
197 (should (not (ly-parse-error-line ly-file
0)))))
199 (ert-deftest ob-lilypond
/ly-attempt-to-open-pdf
()
200 (let ((post-tangle ly-display-pdf-post-tangle
)
203 "../examples/ob-lilypond-test.ly"))
206 "../examples/ob-lilypond-test.pdf")))
207 (setq ly-display-pdf-post-tangle t
)
208 (when (not (file-exists-p pdf-file
))
209 (set-buffer (get-buffer-create (file-name-nondirectory pdf-file
)))
210 (write-file pdf-file
))
213 (ly-determine-pdf-path) " " pdf-file
)
214 (ly-attempt-to-open-pdf ly-file t
)))
215 (delete-file pdf-file
)
216 (kill-buffer (file-name-nondirectory pdf-file
))
218 "No pdf file generated so can't display!"
219 (ly-attempt-to-open-pdf pdf-file
)))
220 (setq ly-display-pdf-post-tangle post-tangle
)))
222 (ert-deftest ob-lilypond
/ly-attempt-to-play-midi
()
223 (let ((post-tangle ly-play-midi-post-tangle
)
226 "../examples/ob-lilypond-test.ly"))
229 "../examples/ob-lilypond-test.midi")))
230 (setq ly-play-midi-post-tangle t
)
231 (when (not (file-exists-p midi-file
))
232 (set-buffer (get-buffer-create (file-name-nondirectory midi-file
)))
233 (write-file midi-file
))
236 (ly-determine-midi-path) " " midi-file
)
237 (ly-attempt-to-play-midi ly-file t
)))
238 (delete-file midi-file
)
239 (kill-buffer (file-name-nondirectory midi-file
))
241 "No midi file generated so can't play!"
242 (ly-attempt-to-play-midi midi-file
)))
243 (setq ly-play-midi-post-tangle post-tangle
)))
245 (ert-deftest ob-lilypond
/ly-determine-ly-path
()
246 (should (equal ly-OSX-ly-path
247 (ly-determine-ly-path "darwin")))
248 (should (equal ly-win32-ly-path
249 (ly-determine-ly-path "win32")))
250 (should (equal ly-nix-ly-path
251 (ly-determine-ly-path "nix"))))
253 (ert-deftest ob-lilypond
/ly-determine-pdf-path
()
254 (should (equal ly-OSX-pdf-path
255 (ly-determine-pdf-path "darwin")))
256 (should (equal ly-win32-pdf-path
257 (ly-determine-pdf-path "win32")))
258 (should (equal ly-nix-pdf-path
259 (ly-determine-pdf-path "nix"))))
261 (ert-deftest ob-lilypond
/ly-determine-midi-path
()
262 (should (equal ly-OSX-midi-path
263 (ly-determine-midi-path "darwin")))
264 (should (equal ly-win32-midi-path
265 (ly-determine-midi-path "win32")))
266 (should (equal ly-nix-midi-path
267 (ly-determine-midi-path "nix"))))
269 (ert-deftest ob-lilypond
/ly-toggle-midi-play-toggles-flag
()
270 (if ly-play-midi-post-tangle
272 (ly-toggle-midi-play)
273 (should (not ly-play-midi-post-tangle
))
274 (ly-toggle-midi-play)
275 (should ly-play-midi-post-tangle
))
276 (ly-toggle-midi-play)
277 (should ly-play-midi-post-tangle
)
278 (ly-toggle-midi-play)
279 (should (not ly-play-midi-post-tangle
))))
281 (ert-deftest ob-lilypond
/ly-toggle-pdf-display-toggles-flag
()
282 (if ly-display-pdf-post-tangle
284 (ly-toggle-pdf-display)
285 (should (not ly-display-pdf-post-tangle
))
286 (ly-toggle-pdf-display)
287 (should ly-display-pdf-post-tangle
))
288 (ly-toggle-pdf-display)
289 (should ly-display-pdf-post-tangle
)
290 (ly-toggle-pdf-display)
291 (should (not ly-display-pdf-post-tangle
))))
293 (ert-deftest ob-lilypond
/ly-toggle-pdf-generation-toggles-flag
()
296 (ly-toggle-pdf-generation)
297 (should (not ly-gen-pdf
))
298 (ly-toggle-pdf-generation)
300 (ly-toggle-pdf-generation)
302 (ly-toggle-pdf-generation)
303 (should (not ly-gen-pdf
))))
305 (ert-deftest ob-lilypond
/ly-toggle-arrange-mode
()
308 (ly-toggle-arrange-mode)
309 (should (not ly-arrange-mode
))
310 (ly-toggle-arrange-mode)
311 (should ly-arrange-mode
))
312 (ly-toggle-arrange-mode)
313 (should ly-arrange-mode
)
314 (ly-toggle-arrange-mode)
315 (should (not ly-arrange-mode
))))
317 (ert-deftest ob-lilypond
/ly-toggle-png-generation-toggles-flag
()
320 (ly-toggle-png-generation)
321 (should (not ly-gen-png
))
322 (ly-toggle-png-generation)
324 (ly-toggle-png-generation)
326 (ly-toggle-png-generation)
327 (should (not ly-gen-png
))))
329 (ert-deftest ob-lilypond
/ly-toggle-html-generation-toggles-flag
()
332 (ly-toggle-html-generation)
333 (should (not ly-gen-html
))
334 (ly-toggle-html-generation)
335 (should ly-gen-html
))
336 (ly-toggle-html-generation)
338 (ly-toggle-html-generation)
339 (should (not ly-gen-html
))))
341 (ert-deftest ob-lilypond
/ly-switch-extension-with-extensions
()
342 (should (equal "test-name.xyz"
343 (ly-switch-extension "test-name" ".xyz")))
344 (should (equal "test-name.xyz"
345 (ly-switch-extension "test-name.abc" ".xyz")))
346 (should (equal "test-name"
347 (ly-switch-extension "test-name.abc" ""))))
349 (ert-deftest ob-lilypond
/ly-switch-extension-with-paths
()
350 (should (equal "/some/path/to/test-name.xyz"
351 (ly-switch-extension "/some/path/to/test-name" ".xyz"))))
353 (ert-deftest ob-lilypond
/ly-get-header-args
()
354 (should (equal '((:tangle .
"yes")
356 (:results .
"silent")
359 (ly-set-header-args t
)))
360 (should (equal '((:results .
"file")
361 (:exports .
"results"))
362 (ly-set-header-args nil
))))
364 (ert-deftest ob-lilypond
/ly-set-header-args
()
365 (ly-set-header-args t
)
366 (should (equal '((:tangle .
"yes")
368 (:results .
"silent")
371 org-babel-default-header-args
:lilypond
))
372 (ly-set-header-args nil
)
373 (should (equal '((:results .
"file")
374 (:exports .
"results"))
375 org-babel-default-header-args
:lilypond
)))
377 (provide 'test-ob-lilypond
)
379 ;;; test-ob-lilypond.el ends here