test-ob-lilypond.el 13 KB

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