Manually revert back to commit e85080.
[org-mode.git] / testing / lisp / test-ob-lilypond.el
blob2ca0597b106d08af5f665fba2c931c873af1e1fd
1 ;;; test-ob-lilypond.el --- tests for ob-lilypond.el
3 ;; Copyright (c) 2010 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 (let ((load-path (cons (expand-file-name
10 ".." (file-name-directory
11 (or load-file-name buffer-file-name)))
12 load-path)))
13 (require 'org-test)
14 (require 'org-test-ob-consts))
16 (require 'ob-lilypond)
18 (save-excursion
19 (set-buffer (get-buffer-create "test-ob-lilypond.el"))
20 (setq ly-here
21 (file-name-directory
22 (or load-file-name (buffer-file-name)))))
24 (ert-deftest ob-lilypond/assert ()
25 (should t))
27 (ert-deftest ob-lilypond/feature-provision ()
28 (should (featurep 'ob-lilypond)))
30 (ert-deftest ob-lilypond/check-lilypond-alias ()
31 (should (fboundp 'lilypond-mode)))
33 (ert-deftest ob-lilypond/org-babel-tangle-lang-exts ()
34 (let ((found nil)
35 (list org-babel-tangle-lang-exts))
36 (while list
37 (when (equal (car list) '("LilyPond" . "ly"))
38 (setq found t))
39 (setq list (cdr list)))
40 (should found)))
42 (ert-deftest ob-lilypond/org-babel-prep-session:lilypond ()
43 (should-error (org-babel-prep-session:lilypond nil nil))
44 :type 'error)
46 (ert-deftest ob-lilypond/ly-version-const ()
47 (should (boundp 'ly-version)))
49 (ert-deftest ob-lilypond/ly-version-command ()
50 (should (equal "ob-lilypond version 0.3" (ly-version)))
51 (with-temp-buffer
52 (ly-version t)
53 (should (equal "ob-lilypond version 0.3"
54 (buffer-substring (point-min) (point-max))))))
56 (ert-deftest ob-lilypond/ly-compile-lilyfile ()
57 (should (equal
58 `(,(ly-determine-ly-path) ;program
59 nil ;infile
60 "*lilypond*" ;buffer
61 t ;display
62 ,(if ly-gen-png "--png" "") ;&rest...
63 ,(if ly-gen-html "--html" "")
64 ,(if ly-use-eps "-dbackend=eps" "")
65 ,(if ly-gen-svg "-dbackend=svg" "")
66 "--output=test-file"
67 "test-file.ly")
68 (ly-compile-lilyfile "test-file.ly" t))))
70 (ert-deftest ob-lilypond/ly-compile-post-tangle ()
71 (should (boundp 'ly-compile-post-tangle)))
73 (ert-deftest ob-lilypond/ly-display-pdf-post-tangle ()
74 (should (boundp 'ly-display-pdf-post-tangle)))
76 (ert-deftest ob-lilypond/ly-play-midi-post-tangle ()
77 (should (boundp 'ly-play-midi-post-tangle)))
79 (ert-deftest ob-lilypond/ly-OSX-ly-path ()
80 (should (boundp 'ly-OSX-ly-path))
81 (should (stringp ly-OSX-ly-path)))
83 (ert-deftest ob-lilypond/ly-OSX-pdf-path ()
84 (should (boundp 'ly-OSX-pdf-path))
85 (should (stringp ly-OSX-pdf-path)))
87 (ert-deftest ob-lilypond/ly-OSX-midi-path ()
88 (should (boundp 'ly-OSX-midi-path))
89 (should (stringp ly-OSX-midi-path)))
91 (ert-deftest ob-lilypond/ly-nix-ly-path ()
92 (should (boundp 'ly-nix-ly-path))
93 (should (stringp ly-nix-ly-path)))
95 (ert-deftest ob-lilypond/ly-nix-pdf-path ()
96 (should (boundp 'ly-nix-pdf-path))
97 (should (stringp ly-nix-pdf-path)))
99 (ert-deftest ob-lilypond/ly-nix-midi-path ()
100 (should (boundp 'ly-nix-midi-path))
101 (should (stringp ly-nix-midi-path)))
103 (ert-deftest ob-lilypond/ly-win32-ly-path ()
104 (should (boundp 'ly-win32-ly-path))
105 (should (stringp ly-win32-ly-path)))
107 (ert-deftest ob-lilypond/ly-win32-pdf-path ()
108 (should (boundp 'ly-win32-pdf-path))
109 (should (stringp ly-win32-pdf-path)))
111 (ert-deftest ob-lilypond/ly-win32-midi-path ()
112 (should (boundp 'ly-win32-midi-path))
113 (should (stringp ly-win32-midi-path)))
115 (ert-deftest ob-lilypond/ly-gen-png ()
116 (should (boundp 'ly-gen-png)))
118 (ert-deftest ob-lilypond/ly-gen-svg ()
119 (should (boundp 'ly-gen-svg)))
121 (ert-deftest ob-lilypond/ly-gen-html ()
122 (should (boundp 'ly-gen-html)))
124 (ert-deftest ob-lilypond/use-eps ()
125 (should (boundp 'ly-use-eps)))
127 (ert-deftest ob-lilypond/ly-arrange-mode ()
128 (should (boundp 'ly-arrange-mode)))
130 ;; (ert-deftest ob-lilypond/org-babel-default-header-args:lilypond ()
131 ;; (should (equal '((:tangle . "yes")
132 ;; (:noweb . "yes")
133 ;; (:results . "silent")
134 ;; (:comments . "yes"))
135 ;; org-babel-default-header-args:lilypond)))
137 ;;TODO finish...
138 (ert-deftest ob-lilypond/org-babel-expand-body:lilypond ()
139 (should (equal "This is a test"
140 (org-babel-expand-body:lilypond "This is a test" ()))))
142 ;;TODO (ert-deftest ly-test-org-babel-execute:lilypond ())
143 (ert-deftest ob-lilypond/ly-check-for-compile-error ()
144 (set-buffer (get-buffer-create "*lilypond*"))
145 (erase-buffer)
146 (should (not (ly-check-for-compile-error nil t)))
147 (insert-file-contents (concat ly-here
148 "../examples/ob-lilypond-test.error")
149 nil nil nil t)
150 (goto-char (point-min))
151 (should (ly-check-for-compile-error nil t))
152 (kill-buffer "*lilypond*"))
154 (ert-deftest ob-lilypond/ly-process-compile-error ()
155 (find-file-other-window (concat
156 ly-here
157 "../examples/ob-lilypond-broken.org"))
158 (set-buffer (get-buffer-create "*lilypond*"))
159 (insert-file-contents (concat
160 ly-here
161 "../examples/ob-lilypond-test.error")
162 nil nil nil t)
163 (goto-char (point-min))
164 (search-forward "error:" nil t)
165 (should-error
166 (ly-process-compile-error (concat
167 ly-here
168 "../examples/ob-lilypond-broken.ly"))
169 :type 'error)
170 (set-buffer "ob-lilypond-broken.org")
171 (should (equal 238 (point)))
172 (exchange-point-and-mark)
173 (should (equal (+ 238 (length "line 25")) (point)))
174 (kill-buffer "*lilypond*")
175 (kill-buffer "ob-lilypond-broken.org"))
177 (ert-deftest ob-lilypond/ly-mark-error-line ()
178 (let ((file-name (concat
179 ly-here
180 "../examples/ob-lilypond-broken.org"))
181 (expected-point-min 198)
182 (expected-point-max 205)
183 (line "line 20"))
184 (find-file-other-window file-name)
185 (ly-mark-error-line file-name line)
186 (should (equal expected-point-min (point)))
188 (exchange-point-and-mark)
189 (should (= expected-point-max (point)))
190 (kill-buffer (file-name-nondirectory file-name))))
192 (ert-deftest ob-lilypond/ly-parse-line-num ()
193 (with-temp-buffer
194 (insert-file-contents (concat
195 ly-here
196 "../examples/ob-lilypond-test.error")
197 nil nil nil t)
198 (goto-char (point-min))
199 (search-forward "error:")
200 (should (equal 25 (ly-parse-line-num (current-buffer))))))
202 (ert-deftest ob-lilypond/ly-parse-error-line ()
203 (let ((ly-file (concat
204 ly-here
205 "../examples/ob-lilypond-broken.ly")))
206 (should (equal "line 20"
207 (ly-parse-error-line ly-file 20)))
208 (should (not (ly-parse-error-line ly-file 0)))))
210 (ert-deftest ob-lilypond/ly-attempt-to-open-pdf ()
211 (let ((post-tangle ly-display-pdf-post-tangle)
212 (ly-file (concat
213 ly-here
214 "../examples/ob-lilypond-test.ly"))
215 (pdf-file (concat
216 ly-here
217 "../examples/ob-lilypond-test.pdf")))
218 (setq ly-display-pdf-post-tangle t)
219 (when (not (file-exists-p pdf-file))
220 (set-buffer (get-buffer-create (file-name-nondirectory pdf-file)))
221 (write-file pdf-file))
222 (should (equal
223 (concat
224 (ly-determine-pdf-path) " " pdf-file)
225 (ly-attempt-to-open-pdf ly-file t)))
226 (delete-file pdf-file)
227 (kill-buffer (file-name-nondirectory pdf-file))
228 (should (equal
229 "No pdf file generated so can't display!"
230 (ly-attempt-to-open-pdf pdf-file)))
231 (setq ly-display-pdf-post-tangle post-tangle)))
233 (ert-deftest ob-lilypond/ly-attempt-to-play-midi ()
234 (let ((post-tangle ly-play-midi-post-tangle)
235 (ly-file (concat
236 ly-here
237 "../examples/ob-lilypond-test.ly"))
238 (midi-file (concat
239 ly-here
240 "../examples/ob-lilypond-test.midi")))
241 (setq ly-play-midi-post-tangle t)
242 (when (not (file-exists-p midi-file))
243 (set-buffer (get-buffer-create (file-name-nondirectory midi-file)))
244 (write-file midi-file))
245 (should (equal
246 (concat
247 (ly-determine-midi-path) " " midi-file)
248 (ly-attempt-to-play-midi ly-file t)))
249 (delete-file midi-file)
250 (kill-buffer (file-name-nondirectory midi-file))
251 (should (equal
252 "No midi file generated so can't play!"
253 (ly-attempt-to-play-midi midi-file)))
254 (setq ly-play-midi-post-tangle post-tangle)))
256 (ert-deftest ob-lilypond/ly-determine-ly-path ()
257 (should (equal ly-OSX-ly-path
258 (ly-determine-ly-path "darwin")))
259 (should (equal ly-win32-ly-path
260 (ly-determine-ly-path "win32")))
261 (should (equal ly-nix-ly-path
262 (ly-determine-ly-path "nix"))))
264 (ert-deftest ob-lilypond/ly-determine-pdf-path ()
265 (should (equal ly-OSX-pdf-path
266 (ly-determine-pdf-path "darwin")))
267 (should (equal ly-win32-pdf-path
268 (ly-determine-pdf-path "win32")))
269 (should (equal ly-nix-pdf-path
270 (ly-determine-pdf-path "nix"))))
272 (ert-deftest ob-lilypond/ly-determine-midi-path ()
273 (should (equal ly-OSX-midi-path
274 (ly-determine-midi-path "darwin")))
275 (should (equal ly-win32-midi-path
276 (ly-determine-midi-path "win32")))
277 (should (equal ly-nix-midi-path
278 (ly-determine-midi-path "nix"))))
280 (ert-deftest ob-lilypond/ly-toggle-midi-play-toggles-flag ()
281 (if ly-play-midi-post-tangle
282 (progn
283 (ly-toggle-midi-play)
284 (should (not ly-play-midi-post-tangle))
285 (ly-toggle-midi-play)
286 (should ly-play-midi-post-tangle))
287 (ly-toggle-midi-play)
288 (should ly-play-midi-post-tangle)
289 (ly-toggle-midi-play)
290 (should (not ly-play-midi-post-tangle))))
292 (ert-deftest ob-lilypond/ly-toggle-pdf-display-toggles-flag ()
293 (if ly-display-pdf-post-tangle
294 (progn
295 (ly-toggle-pdf-display)
296 (should (not ly-display-pdf-post-tangle))
297 (ly-toggle-pdf-display)
298 (should ly-display-pdf-post-tangle))
299 (ly-toggle-pdf-display)
300 (should ly-display-pdf-post-tangle)
301 (ly-toggle-pdf-display)
302 (should (not ly-display-pdf-post-tangle))))
304 (ert-deftest ob-lilypond/ly-toggle-arrange-mode ()
305 (if ly-arrange-mode
306 (progn
307 (ly-toggle-arrange-mode)
308 (should (not ly-arrange-mode))
309 (ly-toggle-arrange-mode)
310 (should ly-arrange-mode))
311 (ly-toggle-arrange-mode)
312 (should ly-arrange-mode)
313 (ly-toggle-arrange-mode)
314 (should (not ly-arrange-mode))))
316 (ert-deftest ob-lilypond/ly-toggle-png-generation-toggles-flag ()
317 (if ly-gen-png
318 (progn
319 (ly-toggle-png-generation)
320 (should (not ly-gen-png))
321 (ly-toggle-png-generation)
322 (should ly-gen-png))
323 (ly-toggle-png-generation)
324 (should ly-gen-png)
325 (ly-toggle-png-generation)
326 (should (not ly-gen-png))))
328 (ert-deftest ob-lilypond/ly-toggle-html-generation-toggles-flag ()
329 (if ly-gen-html
330 (progn
331 (ly-toggle-html-generation)
332 (should (not ly-gen-html))
333 (ly-toggle-html-generation)
334 (should ly-gen-html))
335 (ly-toggle-html-generation)
336 (should ly-gen-html)
337 (ly-toggle-html-generation)
338 (should (not ly-gen-html))))
340 (ert-deftest ob-lilypond/ly-switch-extension-with-extensions ()
341 (should (equal "test-name.xyz"
342 (ly-switch-extension "test-name" ".xyz")))
343 (should (equal "test-name.xyz"
344 (ly-switch-extension "test-name.abc" ".xyz")))
345 (should (equal "test-name"
346 (ly-switch-extension "test-name.abc" ""))))
348 (ert-deftest ob-lilypond/ly-switch-extension-with-paths ()
349 (should (equal "/some/path/to/test-name.xyz"
350 (ly-switch-extension "/some/path/to/test-name" ".xyz"))))
352 (ert-deftest ob-lilypond/ly-get-header-args ()
353 (should (equal '((:tangle . "yes")
354 (:noweb . "yes")
355 (:results . "silent")
356 (:comments . "yes"))
357 (ly-set-header-args t)))
358 (should (equal '((:results . "file")
359 (:exports . "results"))
360 (ly-set-header-args nil))))
362 (ert-deftest ob-lilypond/ly-set-header-args ()
363 (ly-set-header-args t)
364 (should (equal '((:tangle . "yes")
365 (:noweb . "yes")
366 (:results . "silent")
367 (:comments . "yes"))
368 org-babel-default-header-args:lilypond))
369 (ly-set-header-args nil)
370 (should (equal '((:results . "file")
371 (:exports . "results"))
372 org-babel-default-header-args:lilypond)))
374 (provide 'test-ob-lilypond)
376 ;;; test-ob-lilypond.el ends here