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
)))
14 (require 'org-test-ob-consts
))
16 (require 'ob-lilypond
)
19 (set-buffer (get-buffer-create "test-ob-lilypond.el"))
22 (or load-file-name
(buffer-file-name)))))
24 (ert-deftest ob-lilypond
/assert
()
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
()
35 (list org-babel-tangle-lang-exts
))
37 (when (equal (car list
) '("LilyPond" .
"ly"))
39 (setq list
(cdr list
)))
42 (ert-deftest ob-lilypond
/org-babel-prep-session
:lilypond
()
43 (should-error (org-babel-prep-session:lilypond nil nil
))
46 (ert-deftest ob-lilypond
/ly-compile-lilyfile
()
48 `(,(ly-determine-ly-path) ;program
52 ,(if ly-gen-png
"--png" "") ;&rest...
53 ,(if ly-gen-html
"--html" "")
54 ,(if ly-use-eps
"-dbackend=eps" "")
55 ,(if ly-gen-svg
"-dbackend=svg" "")
58 (ly-compile-lilyfile "test-file.ly" t
))))
60 (ert-deftest ob-lilypond
/ly-compile-post-tangle
()
61 (should (boundp 'ly-compile-post-tangle
)))
63 (ert-deftest ob-lilypond
/ly-display-pdf-post-tangle
()
64 (should (boundp 'ly-display-pdf-post-tangle
)))
66 (ert-deftest ob-lilypond
/ly-play-midi-post-tangle
()
67 (should (boundp 'ly-play-midi-post-tangle
)))
69 (ert-deftest ob-lilypond
/ly-OSX-ly-path
()
70 (should (boundp 'ly-OSX-ly-path
))
71 (should (stringp ly-OSX-ly-path
)))
73 (ert-deftest ob-lilypond
/ly-OSX-pdf-path
()
74 (should (boundp 'ly-OSX-pdf-path
))
75 (should (stringp ly-OSX-pdf-path
)))
77 (ert-deftest ob-lilypond
/ly-OSX-midi-path
()
78 (should (boundp 'ly-OSX-midi-path
))
79 (should (stringp ly-OSX-midi-path
)))
81 (ert-deftest ob-lilypond
/ly-nix-ly-path
()
82 (should (boundp 'ly-nix-ly-path
))
83 (should (stringp ly-nix-ly-path
)))
85 (ert-deftest ob-lilypond
/ly-nix-pdf-path
()
86 (should (boundp 'ly-nix-pdf-path
))
87 (should (stringp ly-nix-pdf-path
)))
89 (ert-deftest ob-lilypond
/ly-nix-midi-path
()
90 (should (boundp 'ly-nix-midi-path
))
91 (should (stringp ly-nix-midi-path
)))
93 (ert-deftest ob-lilypond
/ly-win32-ly-path
()
94 (should (boundp 'ly-win32-ly-path
))
95 (should (stringp ly-win32-ly-path
)))
97 (ert-deftest ob-lilypond
/ly-win32-pdf-path
()
98 (should (boundp 'ly-win32-pdf-path
))
99 (should (stringp ly-win32-pdf-path
)))
101 (ert-deftest ob-lilypond
/ly-win32-midi-path
()
102 (should (boundp 'ly-win32-midi-path
))
103 (should (stringp ly-win32-midi-path
)))
105 (ert-deftest ob-lilypond
/ly-gen-png
()
106 (should (boundp 'ly-gen-png
)))
108 (ert-deftest ob-lilypond
/ly-gen-svg
()
109 (should (boundp 'ly-gen-svg
)))
111 (ert-deftest ob-lilypond
/ly-gen-html
()
112 (should (boundp 'ly-gen-html
)))
114 (ert-deftest ob-lilypond
/use-eps
()
115 (should (boundp 'ly-use-eps
)))
117 (ert-deftest ob-lilypond
/ly-arrange-mode
()
118 (should (boundp 'ly-arrange-mode
)))
120 ;; (ert-deftest ob-lilypond/org-babel-default-header-args:lilypond ()
121 ;; (should (equal '((:tangle . "yes")
123 ;; (:results . "silent")
124 ;; (:comments . "yes"))
125 ;; org-babel-default-header-args:lilypond)))
128 (ert-deftest ob-lilypond
/org-babel-expand-body
:lilypond
()
129 (should (equal "This is a test"
130 (org-babel-expand-body:lilypond
"This is a test" ()))))
132 ;;TODO (ert-deftest ly-test-org-babel-execute:lilypond ())
133 (ert-deftest ob-lilypond
/ly-check-for-compile-error
()
134 (set-buffer (get-buffer-create "*lilypond*"))
136 (should (not (ly-check-for-compile-error nil t
)))
137 (insert-file-contents (concat ly-here
138 "../examples/ob-lilypond-test.error")
140 (goto-char (point-min))
141 (should (ly-check-for-compile-error nil t
))
142 (kill-buffer "*lilypond*"))
144 (ert-deftest ob-lilypond
/ly-process-compile-error
()
145 (find-file-other-window (concat
147 "../examples/ob-lilypond-broken.org"))
148 (set-buffer (get-buffer-create "*lilypond*"))
149 (insert-file-contents (concat
151 "../examples/ob-lilypond-test.error")
153 (goto-char (point-min))
154 (search-forward "error:" nil t
)
156 (ly-process-compile-error (concat
158 "../examples/ob-lilypond-broken.ly"))
160 (set-buffer "ob-lilypond-broken.org")
161 (should (equal 238 (point)))
162 (exchange-point-and-mark)
163 (should (equal (+ 238 (length "line 25")) (point)))
164 (kill-buffer "*lilypond*")
165 (kill-buffer "ob-lilypond-broken.org"))
167 (ert-deftest ob-lilypond
/ly-mark-error-line
()
168 (let ((file-name (concat
170 "../examples/ob-lilypond-broken.org"))
171 (expected-point-min 198)
172 (expected-point-max 205)
174 (find-file-other-window file-name
)
175 (ly-mark-error-line file-name line
)
176 (should (equal expected-point-min
(point)))
178 (exchange-point-and-mark)
179 (should (= expected-point-max
(point)))
180 (kill-buffer (file-name-nondirectory file-name
))))
182 (ert-deftest ob-lilypond
/ly-parse-line-num
()
184 (insert-file-contents (concat
186 "../examples/ob-lilypond-test.error")
188 (goto-char (point-min))
189 (search-forward "error:")
190 (should (equal 25 (ly-parse-line-num (current-buffer))))))
192 (ert-deftest ob-lilypond
/ly-parse-error-line
()
193 (let ((ly-file (concat
195 "../examples/ob-lilypond-broken.ly")))
196 (should (equal "line 20"
197 (ly-parse-error-line ly-file
20)))
198 (should (not (ly-parse-error-line ly-file
0)))))
200 (ert-deftest ob-lilypond
/ly-attempt-to-open-pdf
()
201 (let ((post-tangle ly-display-pdf-post-tangle
)
204 "../examples/ob-lilypond-test.ly"))
207 "../examples/ob-lilypond-test.pdf")))
208 (setq ly-display-pdf-post-tangle t
)
209 (when (not (file-exists-p pdf-file
))
210 (set-buffer (get-buffer-create (file-name-nondirectory pdf-file
)))
211 (write-file pdf-file
))
214 (ly-determine-pdf-path) " " pdf-file
)
215 (ly-attempt-to-open-pdf ly-file t
)))
216 (delete-file pdf-file
)
217 (kill-buffer (file-name-nondirectory pdf-file
))
219 "No pdf file generated so can't display!"
220 (ly-attempt-to-open-pdf pdf-file
)))
221 (setq ly-display-pdf-post-tangle post-tangle
)))
223 (ert-deftest ob-lilypond
/ly-attempt-to-play-midi
()
224 (let ((post-tangle ly-play-midi-post-tangle
)
227 "../examples/ob-lilypond-test.ly"))
230 "../examples/ob-lilypond-test.midi")))
231 (setq ly-play-midi-post-tangle t
)
232 (when (not (file-exists-p midi-file
))
233 (set-buffer (get-buffer-create (file-name-nondirectory midi-file
)))
234 (write-file midi-file
))
237 (ly-determine-midi-path) " " midi-file
)
238 (ly-attempt-to-play-midi ly-file t
)))
239 (delete-file midi-file
)
240 (kill-buffer (file-name-nondirectory midi-file
))
242 "No midi file generated so can't play!"
243 (ly-attempt-to-play-midi midi-file
)))
244 (setq ly-play-midi-post-tangle post-tangle
)))
246 (ert-deftest ob-lilypond
/ly-determine-ly-path
()
247 (should (equal ly-OSX-ly-path
248 (ly-determine-ly-path "darwin")))
249 (should (equal ly-win32-ly-path
250 (ly-determine-ly-path "win32")))
251 (should (equal ly-nix-ly-path
252 (ly-determine-ly-path "nix"))))
254 (ert-deftest ob-lilypond
/ly-determine-pdf-path
()
255 (should (equal ly-OSX-pdf-path
256 (ly-determine-pdf-path "darwin")))
257 (should (equal ly-win32-pdf-path
258 (ly-determine-pdf-path "win32")))
259 (should (equal ly-nix-pdf-path
260 (ly-determine-pdf-path "nix"))))
262 (ert-deftest ob-lilypond
/ly-determine-midi-path
()
263 (should (equal ly-OSX-midi-path
264 (ly-determine-midi-path "darwin")))
265 (should (equal ly-win32-midi-path
266 (ly-determine-midi-path "win32")))
267 (should (equal ly-nix-midi-path
268 (ly-determine-midi-path "nix"))))
270 (ert-deftest ob-lilypond
/ly-toggle-midi-play-toggles-flag
()
271 (if ly-play-midi-post-tangle
273 (ly-toggle-midi-play)
274 (should (not ly-play-midi-post-tangle
))
275 (ly-toggle-midi-play)
276 (should ly-play-midi-post-tangle
))
277 (ly-toggle-midi-play)
278 (should ly-play-midi-post-tangle
)
279 (ly-toggle-midi-play)
280 (should (not ly-play-midi-post-tangle
))))
282 (ert-deftest ob-lilypond
/ly-toggle-pdf-display-toggles-flag
()
283 (if ly-display-pdf-post-tangle
285 (ly-toggle-pdf-display)
286 (should (not ly-display-pdf-post-tangle
))
287 (ly-toggle-pdf-display)
288 (should ly-display-pdf-post-tangle
))
289 (ly-toggle-pdf-display)
290 (should ly-display-pdf-post-tangle
)
291 (ly-toggle-pdf-display)
292 (should (not ly-display-pdf-post-tangle
))))
294 (ert-deftest ob-lilypond
/ly-toggle-arrange-mode
()
297 (ly-toggle-arrange-mode)
298 (should (not ly-arrange-mode
))
299 (ly-toggle-arrange-mode)
300 (should ly-arrange-mode
))
301 (ly-toggle-arrange-mode)
302 (should ly-arrange-mode
)
303 (ly-toggle-arrange-mode)
304 (should (not ly-arrange-mode
))))
306 (ert-deftest ob-lilypond
/ly-toggle-png-generation-toggles-flag
()
309 (ly-toggle-png-generation)
310 (should (not ly-gen-png
))
311 (ly-toggle-png-generation)
313 (ly-toggle-png-generation)
315 (ly-toggle-png-generation)
316 (should (not ly-gen-png
))))
318 (ert-deftest ob-lilypond
/ly-toggle-html-generation-toggles-flag
()
321 (ly-toggle-html-generation)
322 (should (not ly-gen-html
))
323 (ly-toggle-html-generation)
324 (should ly-gen-html
))
325 (ly-toggle-html-generation)
327 (ly-toggle-html-generation)
328 (should (not ly-gen-html
))))
330 (ert-deftest ob-lilypond
/ly-switch-extension-with-extensions
()
331 (should (equal "test-name.xyz"
332 (ly-switch-extension "test-name" ".xyz")))
333 (should (equal "test-name.xyz"
334 (ly-switch-extension "test-name.abc" ".xyz")))
335 (should (equal "test-name"
336 (ly-switch-extension "test-name.abc" ""))))
338 (ert-deftest ob-lilypond
/ly-switch-extension-with-paths
()
339 (should (equal "/some/path/to/test-name.xyz"
340 (ly-switch-extension "/some/path/to/test-name" ".xyz"))))
342 (ert-deftest ob-lilypond
/ly-get-header-args
()
343 (should (equal '((:tangle .
"yes")
345 (:results .
"silent")
347 (ly-set-header-args t
)))
348 (should (equal '((:results .
"file")
349 (:exports .
"results"))
350 (ly-set-header-args nil
))))
352 (ert-deftest ob-lilypond
/ly-set-header-args
()
353 (ly-set-header-args t
)
354 (should (equal '((:tangle .
"yes")
356 (:results .
"silent")
358 org-babel-default-header-args
:lilypond
))
359 (ly-set-header-args nil
)
360 (should (equal '((:results .
"file")
361 (:exports .
"results"))
362 org-babel-default-header-args
:lilypond
)))
364 (provide 'test-ob-lilypond
)
366 ;;; test-ob-lilypond.el ends here