fix whitespace errors
[org-mode.git] / testing / lisp / test-ob-lilypond.el
blob306c48ae1b62901ae286e553ddc821a9c69c0d48
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
9 ;;; Code:
10 (unless (featurep 'ob-lilypond)
11 (signal 'missing-test-dependency "Support for Lilypond code blocks"))
13 (save-excursion
14 (set-buffer (get-buffer-create "test-ob-lilypond.el"))
15 (setq ly-here
16 (file-name-directory
17 (or load-file-name (buffer-file-name)))))
19 (ert-deftest ob-lilypond/assert ()
20 (should t))
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 ()
29 (let ((found nil)
30 (list org-babel-tangle-lang-exts))
31 (while list
32 (when (equal (car list) '("LilyPond" . "ly"))
33 (setq found t))
34 (setq list (cdr list)))
35 (should found)))
37 (ert-deftest ob-lilypond/org-babel-prep-session:lilypond ()
38 (should-error (org-babel-prep-session:lilypond nil nil))
39 :type 'error)
41 (ert-deftest ob-lilypond/ly-version-const ()
42 (should (boundp 'ly-version)))
44 (ert-deftest ob-lilypond/ly-version-command ()
45 (should (equal "ob-lilypond version 7.6" (ly-version)))
46 (with-temp-buffer
47 (ly-version t)
48 (should (equal "ob-lilypond version 7.6"
49 (buffer-substring (point-min) (point-max))))))
51 (ert-deftest ob-lilypond/ly-compile-lilyfile ()
52 (should (equal
53 `(,(ly-determine-ly-path) ;program
54 nil ;infile
55 "*lilypond*" ;buffer
56 t ;display
57 ,(if ly-gen-png "--png" "") ;&rest...
58 ,(if ly-gen-html "--html" "")
59 ,(if ly-gen-pdf "--pdf" "")
60 ,(if ly-use-eps "-dbackend=eps" "")
61 ,(if ly-gen-svg "-dbackend=svg" "")
62 "--output=test-file"
63 "test-file.ly")
64 (ly-compile-lilyfile "test-file.ly" t))))
66 (ert-deftest ob-lilypond/ly-compile-post-tangle ()
67 (should (boundp 'ly-compile-post-tangle)))
69 (ert-deftest ob-lilypond/ly-display-pdf-post-tangle ()
70 (should (boundp 'ly-display-pdf-post-tangle)))
72 (ert-deftest ob-lilypond/ly-play-midi-post-tangle ()
73 (should (boundp 'ly-play-midi-post-tangle)))
75 (ert-deftest ob-lilypond/ly-OSX-ly-path ()
76 (should (boundp 'ly-OSX-ly-path))
77 (should (stringp ly-OSX-ly-path)))
79 (ert-deftest ob-lilypond/ly-OSX-pdf-path ()
80 (should (boundp 'ly-OSX-pdf-path))
81 (should (stringp ly-OSX-pdf-path)))
83 (ert-deftest ob-lilypond/ly-OSX-midi-path ()
84 (should (boundp 'ly-OSX-midi-path))
85 (should (stringp ly-OSX-midi-path)))
87 (ert-deftest ob-lilypond/ly-nix-ly-path ()
88 (should (boundp 'ly-nix-ly-path))
89 (should (stringp ly-nix-ly-path)))
91 (ert-deftest ob-lilypond/ly-nix-pdf-path ()
92 (should (boundp 'ly-nix-pdf-path))
93 (should (stringp ly-nix-pdf-path)))
95 (ert-deftest ob-lilypond/ly-nix-midi-path ()
96 (should (boundp 'ly-nix-midi-path))
97 (should (stringp ly-nix-midi-path)))
99 (ert-deftest ob-lilypond/ly-win32-ly-path ()
100 (should (boundp 'ly-win32-ly-path))
101 (should (stringp ly-win32-ly-path)))
103 (ert-deftest ob-lilypond/ly-win32-pdf-path ()
104 (should (boundp 'ly-win32-pdf-path))
105 (should (stringp ly-win32-pdf-path)))
107 (ert-deftest ob-lilypond/ly-win32-midi-path ()
108 (should (boundp 'ly-win32-midi-path))
109 (should (stringp ly-win32-midi-path)))
111 (ert-deftest ob-lilypond/ly-gen-png ()
112 (should (boundp 'ly-gen-png)))
114 (ert-deftest ob-lilypond/ly-gen-svg ()
115 (should (boundp 'ly-gen-svg)))
117 (ert-deftest ob-lilypond/ly-gen-html ()
118 (should (boundp 'ly-gen-html)))
120 (ert-deftest ob-lilypond/ly-gen-html ()
121 (should (boundp 'ly-gen-pdf)))
123 (ert-deftest ob-lilypond/use-eps ()
124 (should (boundp 'ly-use-eps)))
126 (ert-deftest ob-lilypond/ly-arrange-mode ()
127 (should (boundp 'ly-arrange-mode)))
129 ;; (ert-deftest ob-lilypond/org-babel-default-header-args:lilypond ()
130 ;; (should (equal '((:tangle . "yes")
131 ;; (:noweb . "yes")
132 ;; (:results . "silent")
133 ;; (:comments . "yes"))
134 ;; org-babel-default-header-args:lilypond)))
136 ;;TODO finish...
137 (ert-deftest ob-lilypond/org-babel-expand-body:lilypond ()
138 (should (equal "This is a test"
139 (org-babel-expand-body:lilypond "This is a test" ()))))
141 ;;TODO (ert-deftest ly-test-org-babel-execute:lilypond ())
142 (ert-deftest ob-lilypond/ly-check-for-compile-error ()
143 (set-buffer (get-buffer-create "*lilypond*"))
144 (erase-buffer)
145 (should (not (ly-check-for-compile-error nil t)))
146 (insert-file-contents (concat ly-here
147 "../examples/ob-lilypond-test.error")
148 nil nil nil t)
149 (goto-char (point-min))
150 (should (ly-check-for-compile-error nil t))
151 (kill-buffer "*lilypond*"))
153 (ert-deftest ob-lilypond/ly-process-compile-error ()
154 (find-file-other-window (concat
155 ly-here
156 "../examples/ob-lilypond-broken.org"))
157 (set-buffer (get-buffer-create "*lilypond*"))
158 (insert-file-contents (concat
159 ly-here
160 "../examples/ob-lilypond-test.error")
161 nil nil nil t)
162 (goto-char (point-min))
163 (search-forward "error:" nil t)
164 (should-error
165 (ly-process-compile-error (concat
166 ly-here
167 "../examples/ob-lilypond-broken.ly"))
168 :type 'error)
169 (set-buffer "ob-lilypond-broken.org")
170 (should (equal 238 (point)))
171 (exchange-point-and-mark)
172 (should (equal (+ 238 (length "line 25")) (point)))
173 (kill-buffer "*lilypond*")
174 (kill-buffer "ob-lilypond-broken.org"))
176 (ert-deftest ob-lilypond/ly-mark-error-line ()
177 (let ((file-name (concat
178 ly-here
179 "../examples/ob-lilypond-broken.org"))
180 (expected-point-min 198)
181 (expected-point-max 205)
182 (line "line 20"))
183 (find-file-other-window file-name)
184 (ly-mark-error-line file-name line)
185 (should (equal expected-point-min (point)))
187 (exchange-point-and-mark)
188 (should (= expected-point-max (point)))
189 (kill-buffer (file-name-nondirectory file-name))))
191 (ert-deftest ob-lilypond/ly-parse-line-num ()
192 (with-temp-buffer
193 (insert-file-contents (concat
194 ly-here
195 "../examples/ob-lilypond-test.error")
196 nil nil nil t)
197 (goto-char (point-min))
198 (search-forward "error:")
199 (should (equal 25 (ly-parse-line-num (current-buffer))))))
201 (ert-deftest ob-lilypond/ly-parse-error-line ()
202 (let ((ly-file (concat
203 ly-here
204 "../examples/ob-lilypond-broken.ly")))
205 (should (equal "line 20"
206 (ly-parse-error-line ly-file 20)))
207 (should (not (ly-parse-error-line ly-file 0)))))
209 (ert-deftest ob-lilypond/ly-attempt-to-open-pdf ()
210 (let ((post-tangle ly-display-pdf-post-tangle)
211 (ly-file (concat
212 ly-here
213 "../examples/ob-lilypond-test.ly"))
214 (pdf-file (concat
215 ly-here
216 "../examples/ob-lilypond-test.pdf")))
217 (setq ly-display-pdf-post-tangle t)
218 (when (not (file-exists-p pdf-file))
219 (set-buffer (get-buffer-create (file-name-nondirectory pdf-file)))
220 (write-file pdf-file))
221 (should (equal
222 (concat
223 (ly-determine-pdf-path) " " pdf-file)
224 (ly-attempt-to-open-pdf ly-file t)))
225 (delete-file pdf-file)
226 (kill-buffer (file-name-nondirectory pdf-file))
227 (should (equal
228 "No pdf file generated so can't display!"
229 (ly-attempt-to-open-pdf pdf-file)))
230 (setq ly-display-pdf-post-tangle post-tangle)))
232 (ert-deftest ob-lilypond/ly-attempt-to-play-midi ()
233 (let ((post-tangle ly-play-midi-post-tangle)
234 (ly-file (concat
235 ly-here
236 "../examples/ob-lilypond-test.ly"))
237 (midi-file (concat
238 ly-here
239 "../examples/ob-lilypond-test.midi")))
240 (setq ly-play-midi-post-tangle t)
241 (when (not (file-exists-p midi-file))
242 (set-buffer (get-buffer-create (file-name-nondirectory midi-file)))
243 (write-file midi-file))
244 (should (equal
245 (concat
246 (ly-determine-midi-path) " " midi-file)
247 (ly-attempt-to-play-midi ly-file t)))
248 (delete-file midi-file)
249 (kill-buffer (file-name-nondirectory midi-file))
250 (should (equal
251 "No midi file generated so can't play!"
252 (ly-attempt-to-play-midi midi-file)))
253 (setq ly-play-midi-post-tangle post-tangle)))
255 (ert-deftest ob-lilypond/ly-determine-ly-path ()
256 (should (equal ly-OSX-ly-path
257 (ly-determine-ly-path "darwin")))
258 (should (equal ly-win32-ly-path
259 (ly-determine-ly-path "win32")))
260 (should (equal ly-nix-ly-path
261 (ly-determine-ly-path "nix"))))
263 (ert-deftest ob-lilypond/ly-determine-pdf-path ()
264 (should (equal ly-OSX-pdf-path
265 (ly-determine-pdf-path "darwin")))
266 (should (equal ly-win32-pdf-path
267 (ly-determine-pdf-path "win32")))
268 (should (equal ly-nix-pdf-path
269 (ly-determine-pdf-path "nix"))))
271 (ert-deftest ob-lilypond/ly-determine-midi-path ()
272 (should (equal ly-OSX-midi-path
273 (ly-determine-midi-path "darwin")))
274 (should (equal ly-win32-midi-path
275 (ly-determine-midi-path "win32")))
276 (should (equal ly-nix-midi-path
277 (ly-determine-midi-path "nix"))))
279 (ert-deftest ob-lilypond/ly-toggle-midi-play-toggles-flag ()
280 (if ly-play-midi-post-tangle
281 (progn
282 (ly-toggle-midi-play)
283 (should (not ly-play-midi-post-tangle))
284 (ly-toggle-midi-play)
285 (should ly-play-midi-post-tangle))
286 (ly-toggle-midi-play)
287 (should ly-play-midi-post-tangle)
288 (ly-toggle-midi-play)
289 (should (not ly-play-midi-post-tangle))))
291 (ert-deftest ob-lilypond/ly-toggle-pdf-display-toggles-flag ()
292 (if ly-display-pdf-post-tangle
293 (progn
294 (ly-toggle-pdf-display)
295 (should (not ly-display-pdf-post-tangle))
296 (ly-toggle-pdf-display)
297 (should ly-display-pdf-post-tangle))
298 (ly-toggle-pdf-display)
299 (should ly-display-pdf-post-tangle)
300 (ly-toggle-pdf-display)
301 (should (not ly-display-pdf-post-tangle))))
303 (ert-deftest ob-lilypond/ly-toggle-pdf-generation-toggles-flag ()
304 (if ly-gen-pdf
305 (progn
306 (ly-toggle-pdf-generation)
307 (should (not ly-gen-pdf))
308 (ly-toggle-pdf-generation)
309 (should ly-gen-pdf))
310 (ly-toggle-pdf-generation)
311 (should ly-gen-pdf)
312 (ly-toggle-pdf-generation)
313 (should (not ly-gen-pdf))))
315 (ert-deftest ob-lilypond/ly-toggle-arrange-mode ()
316 (if ly-arrange-mode
317 (progn
318 (ly-toggle-arrange-mode)
319 (should (not ly-arrange-mode))
320 (ly-toggle-arrange-mode)
321 (should ly-arrange-mode))
322 (ly-toggle-arrange-mode)
323 (should ly-arrange-mode)
324 (ly-toggle-arrange-mode)
325 (should (not ly-arrange-mode))))
327 (ert-deftest ob-lilypond/ly-toggle-png-generation-toggles-flag ()
328 (if ly-gen-png
329 (progn
330 (ly-toggle-png-generation)
331 (should (not ly-gen-png))
332 (ly-toggle-png-generation)
333 (should ly-gen-png))
334 (ly-toggle-png-generation)
335 (should ly-gen-png)
336 (ly-toggle-png-generation)
337 (should (not ly-gen-png))))
339 (ert-deftest ob-lilypond/ly-toggle-html-generation-toggles-flag ()
340 (if ly-gen-html
341 (progn
342 (ly-toggle-html-generation)
343 (should (not ly-gen-html))
344 (ly-toggle-html-generation)
345 (should ly-gen-html))
346 (ly-toggle-html-generation)
347 (should ly-gen-html)
348 (ly-toggle-html-generation)
349 (should (not ly-gen-html))))
351 (ert-deftest ob-lilypond/ly-switch-extension-with-extensions ()
352 (should (equal "test-name.xyz"
353 (ly-switch-extension "test-name" ".xyz")))
354 (should (equal "test-name.xyz"
355 (ly-switch-extension "test-name.abc" ".xyz")))
356 (should (equal "test-name"
357 (ly-switch-extension "test-name.abc" ""))))
359 (ert-deftest ob-lilypond/ly-switch-extension-with-paths ()
360 (should (equal "/some/path/to/test-name.xyz"
361 (ly-switch-extension "/some/path/to/test-name" ".xyz"))))
363 (ert-deftest ob-lilypond/ly-get-header-args ()
364 (should (equal '((:tangle . "yes")
365 (:noweb . "yes")
366 (:results . "silent")
367 (:cache . "yes")
368 (:comments . "yes"))
369 (ly-set-header-args t)))
370 (should (equal '((:results . "file")
371 (:exports . "results"))
372 (ly-set-header-args nil))))
374 (ert-deftest ob-lilypond/ly-set-header-args ()
375 (ly-set-header-args t)
376 (should (equal '((:tangle . "yes")
377 (:noweb . "yes")
378 (:results . "silent")
379 (:cache . "yes")
380 (:comments . "yes"))
381 org-babel-default-header-args:lilypond))
382 (ly-set-header-args nil)
383 (should (equal '((:results . "file")
384 (:exports . "results"))
385 org-babel-default-header-args:lilypond)))
387 (provide 'test-ob-lilypond)
389 ;;; test-ob-lilypond.el ends here