org-odt.el: Embed links to mathml files as ODF formula
[org-mode.git] / testing / lisp / test-ob-lilypond.el
blob8469823cb5ac8e2da411797e0dae601e9c395a3d
1 (save-excursion
2 (set-buffer (get-buffer-create "test-ob-lilypond.el"))
3 (setq ly-here
4 (file-name-directory
5 (or load-file-name (buffer-file-name)))))
7 (require 'ob-lilypond)
9 (ert-deftest ob-lilypond/assert ()
10 (should t))
12 (ert-deftest ob-lilypond/feature-provision ()
13 (should (featurep 'ob-lilypond)))
15 (ert-deftest ob-lilypond/check-lilypond-alias ()
16 (should (fboundp 'lilypond-mode)))
18 (ert-deftest ob-lilypond/org-babel-tangle-lang-exts ()
19 (let ((found nil)
20 (list org-babel-tangle-lang-exts))
21 (while list
22 (when (equal (car list) '("LilyPond" . "ly"))
23 (setq found t))
24 (setq list (cdr list)))
25 (should found)))
27 (ert-deftest ob-lilypond/org-babel-prep-session:lilypond ()
28 (should-error (org-babel-prep-session:lilypond nil nil))
29 :type 'error)
31 (ert-deftest ob-lilypond/ly-version-const ()
32 (should (boundp 'ly-version)))
34 (ert-deftest ob-lilypond/ly-version-command ()
35 (should (equal "ob-lilypond version 0.3" (ly-version)))
36 (with-temp-buffer
37 (ly-version t)
38 (should (equal "ob-lilypond version 0.3"
39 (buffer-substring (point-min) (point-max))))))
41 (ert-deftest ob-lilypond/ly-compile-lilyfile ()
42 (should (equal
43 `(,(ly-determine-ly-path) ;program
44 nil ;infile
45 "*lilypond*" ;buffer
46 t ;display
47 ,(if ly-gen-png "--png" "") ;&rest...
48 ,(if ly-gen-html "--html" "")
49 ,(if ly-use-eps "-dbackend=eps" "")
50 ,(if ly-gen-svg "-dbackend=svg" "")
51 "--output=test-file"
52 "test-file.ly")
53 (ly-compile-lilyfile "test-file.ly" t))))
55 (ert-deftest ob-lilypond/ly-compile-post-tangle ()
56 (should (boundp 'ly-compile-post-tangle)))
58 (ert-deftest ob-lilypond/ly-display-pdf-post-tangle ()
59 (should (boundp 'ly-display-pdf-post-tangle)))
61 (ert-deftest ob-lilypond/ly-play-midi-post-tangle ()
62 (should (boundp 'ly-play-midi-post-tangle)))
64 (ert-deftest ob-lilypond/ly-OSX-ly-path ()
65 (should (boundp 'ly-OSX-ly-path))
66 (should (stringp ly-OSX-ly-path)))
68 (ert-deftest ob-lilypond/ly-OSX-pdf-path ()
69 (should (boundp 'ly-OSX-pdf-path))
70 (should (stringp ly-OSX-pdf-path)))
72 (ert-deftest ob-lilypond/ly-OSX-midi-path ()
73 (should (boundp 'ly-OSX-midi-path))
74 (should (stringp ly-OSX-midi-path)))
76 (ert-deftest ob-lilypond/ly-nix-ly-path ()
77 (should (boundp 'ly-nix-ly-path))
78 (should (stringp ly-nix-ly-path)))
80 (ert-deftest ob-lilypond/ly-nix-pdf-path ()
81 (should (boundp 'ly-nix-pdf-path))
82 (should (stringp ly-nix-pdf-path)))
84 (ert-deftest ob-lilypond/ly-nix-midi-path ()
85 (should (boundp 'ly-nix-midi-path))
86 (should (stringp ly-nix-midi-path)))
88 (ert-deftest ob-lilypond/ly-win32-ly-path ()
89 (should (boundp 'ly-win32-ly-path))
90 (should (stringp ly-win32-ly-path)))
92 (ert-deftest ob-lilypond/ly-win32-pdf-path ()
93 (should (boundp 'ly-win32-pdf-path))
94 (should (stringp ly-win32-pdf-path)))
96 (ert-deftest ob-lilypond/ly-win32-midi-path ()
97 (should (boundp 'ly-win32-midi-path))
98 (should (stringp ly-win32-midi-path)))
100 (ert-deftest ob-lilypond/ly-gen-png ()
101 (should (boundp 'ly-gen-png)))
103 (ert-deftest ob-lilypond/ly-gen-svg ()
104 (should (boundp 'ly-gen-svg)))
106 (ert-deftest ob-lilypond/ly-gen-html ()
107 (should (boundp 'ly-gen-html)))
109 (ert-deftest ob-lilypond/use-eps ()
110 (should (boundp 'ly-use-eps)))
112 (ert-deftest ob-lilypond/ly-arrange-mode ()
113 (should (boundp 'ly-arrange-mode)))
115 ;; (ert-deftest ob-lilypond/org-babel-default-header-args:lilypond ()
116 ;; (should (equal '((:tangle . "yes")
117 ;; (:noweb . "yes")
118 ;; (:results . "silent")
119 ;; (:comments . "yes"))
120 ;; org-babel-default-header-args:lilypond)))
122 ;;TODO finish...
123 (ert-deftest ob-lilypond/org-babel-expand-body:lilypond ()
124 (should (equal "This is a test"
125 (org-babel-expand-body:lilypond "This is a test" ()))))
127 ;;TODO (ert-deftest ly-test-org-babel-execute:lilypond ())
128 (ert-deftest ob-lilypond/ly-check-for-compile-error ()
129 (set-buffer (get-buffer-create "*lilypond*"))
130 (erase-buffer)
131 (should (not (ly-check-for-compile-error nil t)))
132 (insert-file-contents (concat ly-here
133 "../examples/ob-lilypond-test.error")
134 nil nil nil t)
135 (goto-char (point-min))
136 (should (ly-check-for-compile-error nil t))
137 (kill-buffer "*lilypond*"))
139 (ert-deftest ob-lilypond/ly-process-compile-error ()
140 (find-file-other-window (concat
141 ly-here
142 "../examples/ob-lilypond-broken.org"))
143 (set-buffer (get-buffer-create "*lilypond*"))
144 (insert-file-contents (concat
145 ly-here
146 "../examples/ob-lilypond-test.error")
147 nil nil nil t)
148 (goto-char (point-min))
149 (search-forward "error:" nil t)
150 (should-error
151 (ly-process-compile-error (concat
152 ly-here
153 "../examples/ob-lilypond-broken.ly"))
154 :type 'error)
155 (set-buffer "ob-lilypond-broken.org")
156 (should (equal 238 (point)))
157 (exchange-point-and-mark)
158 (should (equal (+ 238 (length "line 25")) (point)))
159 (kill-buffer "*lilypond*")
160 (kill-buffer "ob-lilypond-broken.org"))
162 (ert-deftest ob-lilypond/ly-mark-error-line ()
163 (let ((file-name (concat
164 ly-here
165 "../examples/ob-lilypond-broken.org"))
166 (expected-point-min 198)
167 (expected-point-max 205)
168 (line "line 20"))
169 (find-file-other-window file-name)
170 (ly-mark-error-line file-name line)
171 (should (equal expected-point-min (point)))
173 (exchange-point-and-mark)
174 (should (= expected-point-max (point)))
175 (kill-buffer (file-name-nondirectory file-name))))
177 (ert-deftest ob-lilypond/ly-parse-line-num ()
178 (with-temp-buffer
179 (insert-file-contents (concat
180 ly-here
181 "../examples/ob-lilypond-test.error")
182 nil nil nil t)
183 (goto-char (point-min))
184 (search-forward "error:")
185 (should (equal 25 (ly-parse-line-num (current-buffer))))))
187 (ert-deftest ob-lilypond/ly-parse-error-line ()
188 (let ((ly-file (concat
189 ly-here
190 "../examples/ob-lilypond-broken.ly")))
191 (should (equal "line 20"
192 (ly-parse-error-line ly-file 20)))
193 (should (not (ly-parse-error-line ly-file 0)))))
195 (ert-deftest ob-lilypond/ly-attempt-to-open-pdf ()
196 (let ((post-tangle ly-display-pdf-post-tangle)
197 (ly-file (concat
198 ly-here
199 "../examples/ob-lilypond-test.ly"))
200 (pdf-file (concat
201 ly-here
202 "../examples/ob-lilypond-test.pdf")))
203 (setq ly-display-pdf-post-tangle t)
204 (when (not (file-exists-p pdf-file))
205 (set-buffer (get-buffer-create (file-name-nondirectory pdf-file)))
206 (write-file pdf-file))
207 (should (equal
208 (concat
209 (ly-determine-pdf-path) " " pdf-file)
210 (ly-attempt-to-open-pdf ly-file t)))
211 (delete-file pdf-file)
212 (kill-buffer (file-name-nondirectory pdf-file))
213 (should (equal
214 "No pdf file generated so can't display!"
215 (ly-attempt-to-open-pdf pdf-file)))
216 (setq ly-display-pdf-post-tangle post-tangle)))
218 (ert-deftest ob-lilypond/ly-attempt-to-play-midi ()
219 (let ((post-tangle ly-play-midi-post-tangle)
220 (ly-file (concat
221 ly-here
222 "../examples/ob-lilypond-test.ly"))
223 (midi-file (concat
224 ly-here
225 "../examples/ob-lilypond-test.midi")))
226 (setq ly-play-midi-post-tangle t)
227 (when (not (file-exists-p midi-file))
228 (set-buffer (get-buffer-create (file-name-nondirectory midi-file)))
229 (write-file midi-file))
230 (should (equal
231 (concat
232 (ly-determine-midi-path) " " midi-file)
233 (ly-attempt-to-play-midi ly-file t)))
234 (delete-file midi-file)
235 (kill-buffer (file-name-nondirectory midi-file))
236 (should (equal
237 "No midi file generated so can't play!"
238 (ly-attempt-to-play-midi midi-file)))
239 (setq ly-play-midi-post-tangle post-tangle)))
241 (ert-deftest ob-lilypond/ly-determine-ly-path ()
242 (should (equal ly-OSX-ly-path
243 (ly-determine-ly-path "darwin")))
244 (should (equal ly-win32-ly-path
245 (ly-determine-ly-path "win32")))
246 (should (equal ly-nix-ly-path
247 (ly-determine-ly-path "nix"))))
249 (ert-deftest ob-lilypond/ly-determine-pdf-path ()
250 (should (equal ly-OSX-pdf-path
251 (ly-determine-pdf-path "darwin")))
252 (should (equal ly-win32-pdf-path
253 (ly-determine-pdf-path "win32")))
254 (should (equal ly-nix-pdf-path
255 (ly-determine-pdf-path "nix"))))
257 (ert-deftest ob-lilypond/ly-determine-midi-path ()
258 (should (equal ly-OSX-midi-path
259 (ly-determine-midi-path "darwin")))
260 (should (equal ly-win32-midi-path
261 (ly-determine-midi-path "win32")))
262 (should (equal ly-nix-midi-path
263 (ly-determine-midi-path "nix"))))
265 (ert-deftest ob-lilypond/ly-toggle-midi-play-toggles-flag ()
266 (if ly-play-midi-post-tangle
267 (progn
268 (ly-toggle-midi-play)
269 (should (not ly-play-midi-post-tangle))
270 (ly-toggle-midi-play)
271 (should ly-play-midi-post-tangle))
272 (ly-toggle-midi-play)
273 (should ly-play-midi-post-tangle)
274 (ly-toggle-midi-play)
275 (should (not ly-play-midi-post-tangle))))
277 (ert-deftest ob-lilypond/ly-toggle-pdf-display-toggles-flag ()
278 (if ly-display-pdf-post-tangle
279 (progn
280 (ly-toggle-pdf-display)
281 (should (not ly-display-pdf-post-tangle))
282 (ly-toggle-pdf-display)
283 (should ly-display-pdf-post-tangle))
284 (ly-toggle-pdf-display)
285 (should ly-display-pdf-post-tangle)
286 (ly-toggle-pdf-display)
287 (should (not ly-display-pdf-post-tangle))))
289 (ert-deftest ob-lilypond/ly-toggle-arrange-mode ()
290 (if ly-arrange-mode
291 (progn
292 (ly-toggle-arrange-mode)
293 (should (not ly-arrange-mode))
294 (ly-toggle-arrange-mode)
295 (should ly-arrange-mode))
296 (ly-toggle-arrange-mode)
297 (should ly-arrange-mode)
298 (ly-toggle-arrange-mode)
299 (should (not ly-arrange-mode))))
301 (ert-deftest ob-lilypond/ly-toggle-png-generation-toggles-flag ()
302 (if ly-gen-png
303 (progn
304 (ly-toggle-png-generation)
305 (should (not ly-gen-png))
306 (ly-toggle-png-generation)
307 (should ly-gen-png))
308 (ly-toggle-png-generation)
309 (should ly-gen-png)
310 (ly-toggle-png-generation)
311 (should (not ly-gen-png))))
313 (ert-deftest ob-lilypond/ly-toggle-html-generation-toggles-flag ()
314 (if ly-gen-html
315 (progn
316 (ly-toggle-html-generation)
317 (should (not ly-gen-html))
318 (ly-toggle-html-generation)
319 (should ly-gen-html))
320 (ly-toggle-html-generation)
321 (should ly-gen-html)
322 (ly-toggle-html-generation)
323 (should (not ly-gen-html))))
325 (ert-deftest ob-lilypond/ly-switch-extension-with-extensions ()
326 (should (equal "test-name.xyz"
327 (ly-switch-extension "test-name" ".xyz")))
328 (should (equal "test-name.xyz"
329 (ly-switch-extension "test-name.abc" ".xyz")))
330 (should (equal "test-name"
331 (ly-switch-extension "test-name.abc" ""))))
333 (ert-deftest ob-lilypond/ly-switch-extension-with-paths ()
334 (should (equal "/some/path/to/test-name.xyz"
335 (ly-switch-extension "/some/path/to/test-name" ".xyz"))))
337 (ert-deftest ob-lilypond/ly-get-header-args ()
338 (should (equal '((:tangle . "yes")
339 (:noweb . "yes")
340 (:results . "silent")
341 (:comments . "yes"))
342 (ly-set-header-args t)))
343 (should (equal '((:results . "file")
344 (:exports . "results"))
345 (ly-set-header-args nil))))
347 (ert-deftest ob-lilypond/ly-set-header-args ()
348 (ly-set-header-args t)
349 (should (equal '((:tangle . "yes")
350 (:noweb . "yes")
351 (:results . "silent")
352 (:comments . "yes"))
353 org-babel-default-header-args:lilypond))
354 (ly-set-header-args nil)
355 (should (equal '((:results . "file")
356 (:exports . "results"))
357 org-babel-default-header-args:lilypond)))
359 (provide 'test-ob-lilypond)
361 ;;; test-ob-lilypond.el ends here