test-ob-lilypond.el 12 KB

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