2 (set-buffer (get-buffer-create "test-ob-lilypond.el"))
8 (ert-deftest ob-lilypond
/assert
()
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
()
19 (list org-babel-tangle-lang-exts
))
21 (when (equal (car list
) '("LilyPond" .
"ly"))
23 (setq list
(cdr list
)))
26 (ert-deftest ob-lilypond
/org-babel-prep-session
:lilypond
()
27 (should-error (org-babel-prep-session:lilypond nil nil
))
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)))
37 (should (equal "ob-lilypond version 0.2"
38 (buffer-substring (point-min) (point-max))))))
40 (ert-deftest ob-lilypond
/ly-compile-lilyfile
()
42 `(,(ly-determine-ly-path) ;program
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" "")
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")
114 (:results .
"silent")
116 org-babel-default-header-args
:lilypond
)))
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*"))
127 (should (not (ly-check-for-compile-error nil t
)))
128 (insert-file-contents (concat ly-here
129 "../examples/ob-lilypond-test.error")
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
138 "../examples/ob-lilypond-broken.org"))
139 (set-buffer (get-buffer-create "*lilypond*"))
140 (insert-file-contents (concat
142 "../examples/ob-lilypond-test.error")
144 (goto-char (point-min))
145 (search-forward "error:" nil t
)
147 (ly-process-compile-error (concat
149 "../examples/ob-lilypond-broken.ly"))
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
161 "../examples/ob-lilypond-broken.org"))
162 (expected-point-min 198)
163 (expected-point-max 205)
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
()
175 (insert-file-contents (concat
177 "../examples/ob-lilypond-test.error")
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
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
)
195 "../examples/ob-lilypond-test.ly"))
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
))
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
))
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
)
218 "../examples/ob-lilypond-test.ly"))
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
))
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
))
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
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
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
()
288 (ly-toggle-png-generation)
289 (should (not ly-gen-png
))
290 (ly-toggle-png-generation)
292 (ly-toggle-png-generation)
294 (ly-toggle-png-generation)
295 (should (not ly-gen-png
))))
297 (ert-deftest ob-lilypond
/ly-toggle-html-generation-toggles-flag
()
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)
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