test-ob-lilypond.el 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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)))))
  7. (ert-deftest ob-lilypond/assert ()
  8. (should t))
  9. (ert-deftest ob-lilypond/feature-provision ()
  10. (should (featurep 'ob-lilypond)))
  11. (ert-deftest ob-lilypond/check-lilypond-alias ()
  12. (should (fboundp 'lilypond-mode)))
  13. (ert-deftest ob-lilypond/org-babel-tangle-lang-exts ()
  14. (let ((found nil)
  15. (list org-babel-tangle-lang-exts))
  16. (while list
  17. (when (equal (car list) '("LilyPond" . "ly"))
  18. (setq found t))
  19. (setq list (cdr list)))
  20. (should found)))
  21. (ert-deftest ob-lilypond/org-babel-prep-session:lilypond ()
  22. (should-error (org-babel-prep-session:lilypond nil nil))
  23. :type 'error)
  24. (ert-deftest ob-lilypond/ly-version-const ()
  25. (should (boundp 'ly-version)))
  26. (ert-deftest ob-lilypond/ly-version-command ()
  27. (should (equal "ob-lilypond version 0.2" (ly-version)))
  28. (with-temp-buffer
  29. (ly-version t)
  30. (should (equal "ob-lilypond version 0.2"
  31. (buffer-substring (point-min) (point-max))))))
  32. (ert-deftest ob-lilypond/ly-compile-lilyfile ()
  33. (should (equal
  34. `(,(ly-determine-ly-path) ;program
  35. nil ;infile
  36. "*lilypond*" ;buffer
  37. t ;display
  38. ,(if ly-gen-png "--png" "") ;&rest...
  39. ,(if ly-gen-html "--html" "")
  40. ,(if ly-use-eps "-dbackend=eps" "")
  41. ,(if ly-gen-svg "-dbackend=svg" "")
  42. "--output=test-file"
  43. "test-file.ly")
  44. (ly-compile-lilyfile "test-file.ly" t))))
  45. (ert-deftest ob-lilypond/ly-compile-post-tangle ()
  46. (should (boundp 'ly-compile-post-tangle)))
  47. (ert-deftest ob-lilypond/ly-display-pdf-post-tangle ()
  48. (should (boundp 'ly-display-pdf-post-tangle)))
  49. (ert-deftest ob-lilypond/ly-play-midi-post-tangle ()
  50. (should (boundp 'ly-play-midi-post-tangle)))
  51. (ert-deftest ob-lilypond/ly-OSX-ly-path ()
  52. (should (boundp 'ly-OSX-ly-path))
  53. (should (stringp ly-OSX-ly-path)))
  54. (ert-deftest ob-lilypond/ly-OSX-pdf-path ()
  55. (should (boundp 'ly-OSX-pdf-path))
  56. (should (stringp ly-OSX-pdf-path)))
  57. (ert-deftest ob-lilypond/ly-OSX-midi-path ()
  58. (should (boundp 'ly-OSX-midi-path))
  59. (should (stringp ly-OSX-midi-path)))
  60. (ert-deftest ob-lilypond/ly-nix-ly-path ()
  61. (should (boundp 'ly-nix-ly-path))
  62. (should (stringp ly-nix-ly-path)))
  63. (ert-deftest ob-lilypond/ly-nix-pdf-path ()
  64. (should (boundp 'ly-nix-pdf-path))
  65. (should (stringp ly-nix-pdf-path)))
  66. (ert-deftest ob-lilypond/ly-nix-midi-path ()
  67. (should (boundp 'ly-nix-midi-path))
  68. (should (stringp ly-nix-midi-path)))
  69. (ert-deftest ob-lilypond/ly-win32-ly-path ()
  70. (should (boundp 'ly-win32-ly-path))
  71. (should (stringp ly-win32-ly-path)))
  72. (ert-deftest ob-lilypond/ly-win32-pdf-path ()
  73. (should (boundp 'ly-win32-pdf-path))
  74. (should (stringp ly-win32-pdf-path)))
  75. (ert-deftest ob-lilypond/ly-win32-midi-path ()
  76. (should (boundp 'ly-win32-midi-path))
  77. (should (stringp ly-win32-midi-path)))
  78. (ert-deftest ob-lilypond/ly-gen-png ()
  79. (should (boundp 'ly-gen-png)))
  80. (ert-deftest ob-lilypond/ly-gen-svg ()
  81. (should (boundp 'ly-gen-svg)))
  82. (ert-deftest ob-lilypond/ly-gen-html ()
  83. (should (boundp 'ly-gen-html)))
  84. (ert-deftest ob-lilypond/use-eps ()
  85. (should (boundp 'ly-use-eps)))
  86. (ert-deftest ob-lilypond/org-babel-default-header-args:lilypond ()
  87. (should (equal '((:tangle . "yes")
  88. (:noweb . "yes")
  89. (:results . "silent")
  90. (:comments . "yes"))
  91. org-babel-default-header-args:lilypond)))
  92. ;;TODO finish...
  93. (ert-deftest ob-lilypond/org-babel-expand-body:lilypond ()
  94. (should (equal "This is a test"
  95. (org-babel-expand-body:lilypond "This is a test" ()))))
  96. ;;TODO (ert-deftest ly-test-org-babel-execute:lilypond ())
  97. (ert-deftest ob-lilypond/ly-check-for-compile-error ()
  98. (set-buffer (get-buffer-create "*lilypond*"))
  99. (erase-buffer)
  100. (should (not (ly-check-for-compile-error nil t)))
  101. (insert-file-contents (concat ly-here
  102. "../examples/ob-lilypond-test.error")
  103. nil nil nil t)
  104. (goto-char (point-min))
  105. (should (ly-check-for-compile-error nil t))
  106. (kill-buffer "*lilypond*"))
  107. (ert-deftest ob-lilypond/ly-process-compile-error ()
  108. (find-file-other-window (concat
  109. ly-here
  110. "../examples/ob-lilypond-broken.org"))
  111. (set-buffer (get-buffer-create "*lilypond*"))
  112. (insert-file-contents (concat
  113. ly-here
  114. "../examples/ob-lilypond-test.error")
  115. nil nil nil t)
  116. (goto-char (point-min))
  117. (search-forward "error:" nil t)
  118. (should-error
  119. (ly-process-compile-error (concat
  120. ly-here
  121. "../examples/ob-lilypond-broken.ly"))
  122. :type 'error)
  123. (set-buffer "ob-lilypond-broken.org")
  124. (should (equal 238 (point)))
  125. (exchange-point-and-mark)
  126. (should (equal (+ 238 (length "line 25")) (point)))
  127. (kill-buffer "*lilypond*")
  128. (kill-buffer "ob-lilypond-broken.org"))
  129. (ert-deftest ob-lilypond/ly-mark-error-line ()
  130. (let ((file-name (concat
  131. ly-here
  132. "../examples/ob-lilypond-broken.org"))
  133. (expected-point-min 198)
  134. (expected-point-max 205)
  135. (line "line 20"))
  136. (find-file-other-window file-name)
  137. (ly-mark-error-line file-name line)
  138. (should (equal expected-point-min (point)))
  139. (exchange-point-and-mark)
  140. (should (= expected-point-max (point)))
  141. (kill-buffer (file-name-nondirectory file-name))))
  142. (ert-deftest ob-lilypond/ly-parse-line-num ()
  143. (with-temp-buffer
  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:")
  150. (should (equal 25 (ly-parse-line-num (current-buffer))))))
  151. (ert-deftest ob-lilypond/ly-parse-error-line ()
  152. (let ((ly-file (concat
  153. ly-here
  154. "../examples/ob-lilypond-broken.ly")))
  155. (should (equal "line 20"
  156. (ly-parse-error-line ly-file 20)))
  157. (should (not (ly-parse-error-line ly-file 0)))))
  158. (ert-deftest ob-lilypond/ly-attempt-to-open-pdf ()
  159. (let ((post-tangle ly-display-pdf-post-tangle)
  160. (ly-file (concat
  161. ly-here
  162. "../examples/ob-lilypond-test.ly"))
  163. (pdf-file (concat
  164. ly-here
  165. "../examples/ob-lilypond-test.pdf")))
  166. (setq ly-open-pdf-post-tangle t)
  167. (when (not (file-exists-p pdf-file))
  168. (set-buffer (get-buffer-create (file-name-nondirectory pdf-file)))
  169. (write-file pdf-file))
  170. (should (equal
  171. (concat
  172. (ly-determine-pdf-path) " " pdf-file)
  173. (ly-attempt-to-open-pdf ly-file t)))
  174. (delete-file pdf-file)
  175. (kill-buffer (file-name-nondirectory pdf-file))
  176. (should (equal
  177. "No pdf file generated so can't display!"
  178. (ly-attempt-to-open-pdf pdf-file)))
  179. (setq ly-display-pdf-post-tangle post-tangle)))
  180. (ert-deftest ob-lilypond/ly-attempt-to-play-midi ()
  181. (let ((post-tangle ly-play-midi-post-tangle)
  182. (ly-file (concat
  183. ly-here
  184. "../examples/ob-lilypond-test.ly"))
  185. (midi-file (concat
  186. ly-here
  187. "../examples/ob-lilypond-test.midi")))
  188. (setq ly-play-midi-post-tangle t)
  189. (when (not (file-exists-p midi-file))
  190. (set-buffer (get-buffer-create (file-name-nondirectory midi-file)))
  191. (write-file midi-file))
  192. (should (equal
  193. (concat
  194. (ly-determine-midi-path) " " midi-file)
  195. (ly-attempt-to-play-midi ly-file t)))
  196. (delete-file midi-file)
  197. (kill-buffer (file-name-nondirectory midi-file))
  198. (should (equal
  199. "No midi file generated so can't play!"
  200. (ly-attempt-to-play-midi midi-file)))
  201. (setq ly-play-midi-post-tangle post-tangle)))
  202. (ert-deftest ob-lilypond/ly-determine-ly-path ()
  203. (should (equal ly-OSX-ly-path
  204. (ly-determine-ly-path "darwin")))
  205. (should (equal ly-win32-ly-path
  206. (ly-determine-ly-path "win32")))
  207. (should (equal ly-nix-ly-path
  208. (ly-determine-ly-path "nix"))))
  209. (ert-deftest ob-lilypond/ly-determine-pdf-path ()
  210. (should (equal ly-OSX-pdf-path
  211. (ly-determine-pdf-path "darwin")))
  212. (should (equal ly-win32-pdf-path
  213. (ly-determine-pdf-path "win32")))
  214. (should (equal ly-nix-pdf-path
  215. (ly-determine-pdf-path "nix"))))
  216. (ert-deftest ob-lilypond/ly-determine-midi-path ()
  217. (should (equal ly-OSX-midi-path
  218. (ly-determine-midi-path "darwin")))
  219. (should (equal ly-win32-midi-path
  220. (ly-determine-midi-path "win32")))
  221. (should (equal ly-nix-midi-path
  222. (ly-determine-midi-path "nix"))))
  223. (ert-deftest ob-lilypond/ly-toggle-midi-play-toggles-flag ()
  224. (if ly-play-midi-post-tangle
  225. (progn
  226. (ly-toggle-midi-play)
  227. (should (not ly-play-midi-post-tangle))
  228. (ly-toggle-midi-play)
  229. (should ly-play-midi-post-tangle))
  230. (ly-toggle-midi-play)
  231. (should ly-play-midi-post-tangle)
  232. (ly-toggle-midi-play)
  233. (should (not ly-play-midi-post-tangle))))
  234. (ert-deftest ob-lilypond/ly-toggle-pdf-display-toggles-flag ()
  235. (if ly-display-pdf-post-tangle
  236. (progn
  237. (ly-toggle-pdf-display)
  238. (should (not ly-display-pdf-post-tangle))
  239. (ly-toggle-pdf-display)
  240. (should ly-display-pdf-post-tangle))
  241. (ly-toggle-pdf-display)
  242. (should ly-display-pdf-post-tangle)
  243. (ly-toggle-pdf-display)
  244. (should (not ly-display-pdf-post-tangle))))
  245. (ert-deftest ob-lilypond/ly-toggle-png-generation-toggles-flag ()
  246. (if ly-gen-png
  247. (progn
  248. (ly-toggle-png-generation)
  249. (should (not ly-gen-png))
  250. (ly-toggle-png-generation)
  251. (should ly-gen-png))
  252. (ly-toggle-png-generation)
  253. (should ly-gen-png)
  254. (ly-toggle-png-generation)
  255. (should (not ly-gen-png))))
  256. (ert-deftest ob-lilypond/ly-toggle-html-generation-toggles-flag ()
  257. (if ly-gen-html
  258. (progn
  259. (ly-toggle-html-generation)
  260. (should (not ly-gen-html))
  261. (ly-toggle-html-generation)
  262. (should ly-gen-html))
  263. (ly-toggle-html-generation)
  264. (should ly-gen-html)
  265. (ly-toggle-html-generation)
  266. (should (not ly-gen-html))))
  267. (ert-deftest ob-lilypond/ly-switch-extension-with-extensions ()
  268. (should (equal "test-name.xyz"
  269. (ly-switch-extension "test-name" ".xyz")))
  270. (should (equal "test-name.xyz"
  271. (ly-switch-extension "test-name.abc" ".xyz")))
  272. (should (equal "test-name"
  273. (ly-switch-extension "test-name.abc" ""))))
  274. (ert-deftest ob-lilypond/ly-switch-extension-with-paths ()
  275. (should (equal "/some/path/to/test-name.xyz"
  276. (ly-switch-extension "/some/path/to/test-name" ".xyz"))))
  277. (provide 'test-ob-lilypond)
  278. ;;; test-ob-lilypond.el ends here