ob-lilypond: test suite, all tests passing
[org-mode.git] / testing / lisp / test-ob-lilypond.el
blob16d6f095934a4de8a80204b720a2b88f4c39065b
1 (save-excursion
2 (set-buffer (get-buffer-create "test-ob-lilypond.el"))
3 (setq ly-here
4 (file-name-directory
5 (buffer-file-name
6 (current-buffer)))))
8 (ert-deftest ob-lilypond/assert ()
9 (should t))
11 (ert-deftest ob-lilypond/feature-provision ()
12 (should (featurep 'ob-lilypond)))
14 (ert-deftest ob-lilypond/check-lilypond-alias ()
15 (should (fboundp 'lilypond-mode)))
17 (ert-deftest ob-lilypond/org-babel-tangle-lang-exts ()
18 (let ((found nil)
19 (list org-babel-tangle-lang-exts))
20 (while list
21 (when (equal (car list) '("LilyPond" . "ly"))
22 (setq found t))
23 (setq list (cdr list)))
24 (should found)))
26 (ert-deftest ob-lilypond/org-babel-prep-session:lilypond ()
27 (should-error (org-babel-prep-session:lilypond nil nil))
28 :type 'error)
30 (ert-deftest ob-lilypond/ly-version-const ()
31 (should (boundp 'ly-version)))
33 (ert-deftest ob-lilypond/ly-version-command ()
34 (should (equal "ob-lilypond version 0.2" (ly-version)))
35 (with-temp-buffer
36 (ly-version t)
37 (should (equal "ob-lilypond version 0.2"
38 (buffer-substring (point-min) (point-max))))))
40 (ert-deftest ob-lilypond/ly-compile-lilyfile ()
41 (should (equal
42 `(,(ly-determine-ly-path) ;program
43 nil ;infile
44 "*lilypond*" ;buffer
45 t ;display
46 ,(if ly-gen-png "--png" "") ;&rest...
47 ,(if ly-gen-html "--html" "")
48 ,(if ly-use-eps "-dbackend=eps" "")
49 ,(if ly-gen-svg "-dbackend=svg" "")
50 "--output=test-file"
51 "test-file.ly")
52 (ly-compile-lilyfile "test-file.ly" t))))
54 (ert-deftest ob-lilypond/ly-compile-post-tangle ()
55 (should (boundp 'ly-compile-post-tangle)))
57 (ert-deftest ob-lilypond/ly-display-pdf-post-tangle ()
58 (should (boundp 'ly-display-pdf-post-tangle)))
60 (ert-deftest ob-lilypond/ly-play-midi-post-tangle ()
61 (should (boundp 'ly-play-midi-post-tangle)))
63 (ert-deftest ob-lilypond/ly-OSX-ly-path ()
64 (should (boundp 'ly-OSX-ly-path))
65 (should (stringp ly-OSX-ly-path)))
67 (ert-deftest ob-lilypond/ly-OSX-pdf-path ()
68 (should (boundp 'ly-OSX-pdf-path))
69 (should (stringp ly-OSX-pdf-path)))
71 (ert-deftest ob-lilypond/ly-OSX-midi-path ()
72 (should (boundp 'ly-OSX-midi-path))
73 (should (stringp ly-OSX-midi-path)))
75 (ert-deftest ob-lilypond/ly-nix-ly-path ()
76 (should (boundp 'ly-nix-ly-path))
77 (should (stringp ly-nix-ly-path)))
79 (ert-deftest ob-lilypond/ly-nix-pdf-path ()
80 (should (boundp 'ly-nix-pdf-path))
81 (should (stringp ly-nix-pdf-path)))
83 (ert-deftest ob-lilypond/ly-nix-midi-path ()
84 (should (boundp 'ly-nix-midi-path))
85 (should (stringp ly-nix-midi-path)))
87 (ert-deftest ob-lilypond/ly-win32-ly-path ()
88 (should (boundp 'ly-win32-ly-path))
89 (should (stringp ly-win32-ly-path)))
91 (ert-deftest ob-lilypond/ly-win32-pdf-path ()
92 (should (boundp 'ly-win32-pdf-path))
93 (should (stringp ly-win32-pdf-path)))
95 (ert-deftest ob-lilypond/ly-win32-midi-path ()
96 (should (boundp 'ly-win32-midi-path))
97 (should (stringp ly-win32-midi-path)))
99 (ert-deftest ob-lilypond/ly-gen-png ()
100 (should (boundp 'ly-gen-png)))
102 (ert-deftest ob-lilypond/ly-gen-svg ()
103 (should (boundp 'ly-gen-svg)))
105 (ert-deftest ob-lilypond/ly-gen-html ()
106 (should (boundp 'ly-gen-html)))
108 (ert-deftest ob-lilypond/use-eps ()
109 (should (boundp 'ly-use-eps)))
111 (ert-deftest ob-lilypond/org-babel-default-header-args:lilypond ()
112 (should (equal '((:tangle . "yes")
113 (:noweb . "yes")
114 (:results . "silent")
115 (:comments . "yes"))
116 org-babel-default-header-args:lilypond)))
118 ;;TODO finish...
119 (ert-deftest ob-lilypond/org-babel-expand-body:lilypond ()
120 (should (equal "This is a test"
121 (org-babel-expand-body:lilypond "This is a test" ()))))
123 ;;TODO (ert-deftest ly-test-org-babel-execute:lilypond ())
124 (ert-deftest ob-lilypond/ly-check-for-compile-error ()
125 (set-buffer (get-buffer-create "*lilypond*"))
126 (erase-buffer)
127 (should (not (ly-check-for-compile-error nil t)))
128 (insert-file-contents (concat ly-here
129 "../examples/ob-lilypond-test.error")
130 nil nil nil t)
131 (goto-char (point-min))
132 (should (ly-check-for-compile-error nil t))
133 (kill-buffer "*lilypond*"))
135 (ert-deftest ob-lilypond/ly-process-compile-error ()
136 (find-file-other-window (concat
137 ly-here
138 "../examples/ob-lilypond-broken.org"))
139 (set-buffer (get-buffer-create "*lilypond*"))
140 (insert-file-contents (concat
141 ly-here
142 "../examples/ob-lilypond-test.error")
143 nil nil nil t)
144 (goto-char (point-min))
145 (search-forward "error:" nil t)
146 (should-error
147 (ly-process-compile-error (concat
148 ly-here
149 "../examples/ob-lilypond-broken.ly"))
150 :type 'error)
151 (set-buffer "ob-lilypond-broken.org")
152 (should (equal 238 (point)))
153 (exchange-point-and-mark)
154 (should (equal (+ 238 (length "line 25")) (point)))
155 (kill-buffer "*lilypond*")
156 (kill-buffer "ob-lilypond-broken.org"))
158 (ert-deftest ob-lilypond/ly-mark-error-line ()
159 (let ((file-name (concat
160 ly-here
161 "../examples/ob-lilypond-broken.org"))
162 (expected-point-min 198)
163 (expected-point-max 205)
164 (line "line 20"))
165 (find-file-other-window file-name)
166 (ly-mark-error-line file-name line)
167 (should (equal expected-point-min (point)))
169 (exchange-point-and-mark)
170 (should (= expected-point-max (point)))
171 (kill-buffer (file-name-nondirectory file-name))))
173 (ert-deftest ob-lilypond/ly-parse-line-num ()
174 (with-temp-buffer
175 (insert-file-contents (concat
176 ly-here
177 "../examples/ob-lilypond-test.error")
178 nil nil nil t)
179 (goto-char (point-min))
180 (search-forward "error:")
181 (should (equal 25 (ly-parse-line-num (current-buffer))))))
183 (ert-deftest ob-lilypond/ly-parse-error-line ()
184 (let ((ly-file (concat
185 ly-here
186 "../examples/ob-lilypond-broken.ly")))
187 (should (equal "line 20"
188 (ly-parse-error-line ly-file 20)))
189 (should (not (ly-parse-error-line ly-file 0)))))
191 (ert-deftest ob-lilypond/ly-attempt-to-open-pdf ()
192 (let ((post-tangle ly-display-pdf-post-tangle)
193 (ly-file (concat
194 ly-here
195 "../examples/ob-lilypond-test.ly"))
196 (pdf-file (concat
197 ly-here
198 "../examples/ob-lilypond-test.pdf")))
199 (setq ly-open-pdf-post-tangle t)
200 (when (not (file-exists-p pdf-file))
201 (set-buffer (get-buffer-create (file-name-nondirectory pdf-file)))
202 (write-file pdf-file))
203 (should (equal
204 (concat
205 (ly-determine-pdf-path) " " pdf-file)
206 (ly-attempt-to-open-pdf ly-file t)))
207 (delete-file pdf-file)
208 (kill-buffer (file-name-nondirectory pdf-file))
209 (should (equal
210 "No pdf file generated so can't display!"
211 (ly-attempt-to-open-pdf pdf-file)))
212 (setq ly-display-pdf-post-tangle post-tangle)))
214 (ert-deftest ob-lilypond/ly-attempt-to-play-midi ()
215 (let ((post-tangle ly-play-midi-post-tangle)
216 (ly-file (concat
217 ly-here
218 "../examples/ob-lilypond-test.ly"))
219 (midi-file (concat
220 ly-here
221 "../examples/ob-lilypond-test.midi")))
222 (setq ly-play-midi-post-tangle t)
223 (when (not (file-exists-p midi-file))
224 (set-buffer (get-buffer-create (file-name-nondirectory midi-file)))
225 (write-file midi-file))
226 (should (equal
227 (concat
228 (ly-determine-midi-path) " " midi-file)
229 (ly-attempt-to-play-midi ly-file t)))
230 (delete-file midi-file)
231 (kill-buffer (file-name-nondirectory midi-file))
232 (should (equal
233 "No midi file generated so can't play!"
234 (ly-attempt-to-play-midi midi-file)))
235 (setq ly-play-midi-post-tangle post-tangle)))
237 (ert-deftest ob-lilypond/ly-determine-ly-path ()
238 (should (equal ly-OSX-ly-path
239 (ly-determine-ly-path "darwin")))
240 (should (equal ly-win32-ly-path
241 (ly-determine-ly-path "win32")))
242 (should (equal ly-nix-ly-path
243 (ly-determine-ly-path "nix"))))
245 (ert-deftest ob-lilypond/ly-determine-pdf-path ()
246 (should (equal ly-OSX-pdf-path
247 (ly-determine-pdf-path "darwin")))
248 (should (equal ly-win32-pdf-path
249 (ly-determine-pdf-path "win32")))
250 (should (equal ly-nix-pdf-path
251 (ly-determine-pdf-path "nix"))))
253 (ert-deftest ob-lilypond/ly-determine-midi-path ()
254 (should (equal ly-OSX-midi-path
255 (ly-determine-midi-path "darwin")))
256 (should (equal ly-win32-midi-path
257 (ly-determine-midi-path "win32")))
258 (should (equal ly-nix-midi-path
259 (ly-determine-midi-path "nix"))))
261 (ert-deftest ob-lilypond/ly-toggle-midi-play-toggles-flag ()
262 (if ly-play-midi-post-tangle
263 (progn
264 (ly-toggle-midi-play)
265 (should (not ly-play-midi-post-tangle))
266 (ly-toggle-midi-play)
267 (should ly-play-midi-post-tangle))
268 (ly-toggle-midi-play)
269 (should ly-play-midi-post-tangle)
270 (ly-toggle-midi-play)
271 (should (not ly-play-midi-post-tangle))))
273 (ert-deftest ob-lilypond/ly-toggle-pdf-display-toggles-flag ()
274 (if ly-display-pdf-post-tangle
275 (progn
276 (ly-toggle-pdf-display)
277 (should (not ly-display-pdf-post-tangle))
278 (ly-toggle-pdf-display)
279 (should ly-display-pdf-post-tangle))
280 (ly-toggle-pdf-display)
281 (should ly-display-pdf-post-tangle)
282 (ly-toggle-pdf-display)
283 (should (not ly-display-pdf-post-tangle))))
285 (ert-deftest ob-lilypond/ly-toggle-png-generation-toggles-flag ()
286 (if ly-gen-png
287 (progn
288 (ly-toggle-png-generation)
289 (should (not ly-gen-png))
290 (ly-toggle-png-generation)
291 (should ly-gen-png))
292 (ly-toggle-png-generation)
293 (should ly-gen-png)
294 (ly-toggle-png-generation)
295 (should (not ly-gen-png))))
297 (ert-deftest ob-lilypond/ly-toggle-html-generation-toggles-flag ()
298 (if ly-gen-html
299 (progn
300 (ly-toggle-html-generation)
301 (should (not ly-gen-html))
302 (ly-toggle-html-generation)
303 (should ly-gen-html))
304 (ly-toggle-html-generation)
305 (should ly-gen-html)
306 (ly-toggle-html-generation)
307 (should (not ly-gen-html))))
309 (ert-deftest ob-lilypond/ly-switch-extension-with-extensions ()
310 (should (equal "test-name.xyz"
311 (ly-switch-extension "test-name" ".xyz")))
312 (should (equal "test-name.xyz"
313 (ly-switch-extension "test-name.abc" ".xyz")))
314 (should (equal "test-name"
315 (ly-switch-extension "test-name.abc" ""))))
317 (ert-deftest ob-lilypond/ly-switch-extension-with-paths ()
318 (should (equal "/some/path/to/test-name.xyz"
319 (ly-switch-extension "/some/path/to/test-name" ".xyz"))))
321 (provide 'test-ob-lilypond)
323 ;;; test-ob-lilypond.el ends here