test-ob-lilypond.el 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. (save-excursion
  2. (set-buffer (get-buffer-create "test-ob-lilypond.el"))
  3. (setq ly-here
  4. (file-name-directory
  5. (or load-file-name (buffer-file-name)))))
  6. (require 'ob-lilypond)
  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.3" (ly-version)))
  28. (with-temp-buffer
  29. (ly-version t)
  30. (should (equal "ob-lilypond version 0.3"
  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/ly-arrange-mode ()
  87. (should (boundp 'ly-arrange-mode)))
  88. ;; (ert-deftest ob-lilypond/org-babel-default-header-args:lilypond ()
  89. ;; (should (equal '((:tangle . "yes")
  90. ;; (:noweb . "yes")
  91. ;; (:results . "silent")
  92. ;; (:comments . "yes"))
  93. ;; org-babel-default-header-args:lilypond)))
  94. ;;TODO finish...
  95. (ert-deftest ob-lilypond/org-babel-expand-body:lilypond ()
  96. (should (equal "This is a test"
  97. (org-babel-expand-body:lilypond "This is a test" ()))))
  98. ;;TODO (ert-deftest ly-test-org-babel-execute:lilypond ())
  99. (ert-deftest ob-lilypond/ly-check-for-compile-error ()
  100. (set-buffer (get-buffer-create "*lilypond*"))
  101. (erase-buffer)
  102. (should (not (ly-check-for-compile-error nil t)))
  103. (insert-file-contents (concat ly-here
  104. "../examples/ob-lilypond-test.error")
  105. nil nil nil t)
  106. (goto-char (point-min))
  107. (should (ly-check-for-compile-error nil t))
  108. (kill-buffer "*lilypond*"))
  109. (ert-deftest ob-lilypond/ly-process-compile-error ()
  110. (find-file-other-window (concat
  111. ly-here
  112. "../examples/ob-lilypond-broken.org"))
  113. (set-buffer (get-buffer-create "*lilypond*"))
  114. (insert-file-contents (concat
  115. ly-here
  116. "../examples/ob-lilypond-test.error")
  117. nil nil nil t)
  118. (goto-char (point-min))
  119. (search-forward "error:" nil t)
  120. (should-error
  121. (ly-process-compile-error (concat
  122. ly-here
  123. "../examples/ob-lilypond-broken.ly"))
  124. :type 'error)
  125. (set-buffer "ob-lilypond-broken.org")
  126. (should (equal 238 (point)))
  127. (exchange-point-and-mark)
  128. (should (equal (+ 238 (length "line 25")) (point)))
  129. (kill-buffer "*lilypond*")
  130. (kill-buffer "ob-lilypond-broken.org"))
  131. (ert-deftest ob-lilypond/ly-mark-error-line ()
  132. (let ((file-name (concat
  133. ly-here
  134. "../examples/ob-lilypond-broken.org"))
  135. (expected-point-min 198)
  136. (expected-point-max 205)
  137. (line "line 20"))
  138. (find-file-other-window file-name)
  139. (ly-mark-error-line file-name line)
  140. (should (equal expected-point-min (point)))
  141. (exchange-point-and-mark)
  142. (should (= expected-point-max (point)))
  143. (kill-buffer (file-name-nondirectory file-name))))
  144. (ert-deftest ob-lilypond/ly-parse-line-num ()
  145. (with-temp-buffer
  146. (insert-file-contents (concat
  147. ly-here
  148. "../examples/ob-lilypond-test.error")
  149. nil nil nil t)
  150. (goto-char (point-min))
  151. (search-forward "error:")
  152. (should (equal 25 (ly-parse-line-num (current-buffer))))))
  153. (ert-deftest ob-lilypond/ly-parse-error-line ()
  154. (let ((ly-file (concat
  155. ly-here
  156. "../examples/ob-lilypond-broken.ly")))
  157. (should (equal "line 20"
  158. (ly-parse-error-line ly-file 20)))
  159. (should (not (ly-parse-error-line ly-file 0)))))
  160. (ert-deftest ob-lilypond/ly-attempt-to-open-pdf ()
  161. (let ((post-tangle ly-display-pdf-post-tangle)
  162. (ly-file (concat
  163. ly-here
  164. "../examples/ob-lilypond-test.ly"))
  165. (pdf-file (concat
  166. ly-here
  167. "../examples/ob-lilypond-test.pdf")))
  168. (setq ly-display-pdf-post-tangle t)
  169. (when (not (file-exists-p pdf-file))
  170. (set-buffer (get-buffer-create (file-name-nondirectory pdf-file)))
  171. (write-file pdf-file))
  172. (should (equal
  173. (concat
  174. (ly-determine-pdf-path) " " pdf-file)
  175. (ly-attempt-to-open-pdf ly-file t)))
  176. (delete-file pdf-file)
  177. (kill-buffer (file-name-nondirectory pdf-file))
  178. (should (equal
  179. "No pdf file generated so can't display!"
  180. (ly-attempt-to-open-pdf pdf-file)))
  181. (setq ly-display-pdf-post-tangle post-tangle)))
  182. (ert-deftest ob-lilypond/ly-attempt-to-play-midi ()
  183. (let ((post-tangle ly-play-midi-post-tangle)
  184. (ly-file (concat
  185. ly-here
  186. "../examples/ob-lilypond-test.ly"))
  187. (midi-file (concat
  188. ly-here
  189. "../examples/ob-lilypond-test.midi")))
  190. (setq ly-play-midi-post-tangle t)
  191. (when (not (file-exists-p midi-file))
  192. (set-buffer (get-buffer-create (file-name-nondirectory midi-file)))
  193. (write-file midi-file))
  194. (should (equal
  195. (concat
  196. (ly-determine-midi-path) " " midi-file)
  197. (ly-attempt-to-play-midi ly-file t)))
  198. (delete-file midi-file)
  199. (kill-buffer (file-name-nondirectory midi-file))
  200. (should (equal
  201. "No midi file generated so can't play!"
  202. (ly-attempt-to-play-midi midi-file)))
  203. (setq ly-play-midi-post-tangle post-tangle)))
  204. (ert-deftest ob-lilypond/ly-determine-ly-path ()
  205. (should (equal ly-OSX-ly-path
  206. (ly-determine-ly-path "darwin")))
  207. (should (equal ly-win32-ly-path
  208. (ly-determine-ly-path "win32")))
  209. (should (equal ly-nix-ly-path
  210. (ly-determine-ly-path "nix"))))
  211. (ert-deftest ob-lilypond/ly-determine-pdf-path ()
  212. (should (equal ly-OSX-pdf-path
  213. (ly-determine-pdf-path "darwin")))
  214. (should (equal ly-win32-pdf-path
  215. (ly-determine-pdf-path "win32")))
  216. (should (equal ly-nix-pdf-path
  217. (ly-determine-pdf-path "nix"))))
  218. (ert-deftest ob-lilypond/ly-determine-midi-path ()
  219. (should (equal ly-OSX-midi-path
  220. (ly-determine-midi-path "darwin")))
  221. (should (equal ly-win32-midi-path
  222. (ly-determine-midi-path "win32")))
  223. (should (equal ly-nix-midi-path
  224. (ly-determine-midi-path "nix"))))
  225. (ert-deftest ob-lilypond/ly-toggle-midi-play-toggles-flag ()
  226. (if ly-play-midi-post-tangle
  227. (progn
  228. (ly-toggle-midi-play)
  229. (should (not ly-play-midi-post-tangle))
  230. (ly-toggle-midi-play)
  231. (should ly-play-midi-post-tangle))
  232. (ly-toggle-midi-play)
  233. (should ly-play-midi-post-tangle)
  234. (ly-toggle-midi-play)
  235. (should (not ly-play-midi-post-tangle))))
  236. (ert-deftest ob-lilypond/ly-toggle-pdf-display-toggles-flag ()
  237. (if ly-display-pdf-post-tangle
  238. (progn
  239. (ly-toggle-pdf-display)
  240. (should (not ly-display-pdf-post-tangle))
  241. (ly-toggle-pdf-display)
  242. (should ly-display-pdf-post-tangle))
  243. (ly-toggle-pdf-display)
  244. (should ly-display-pdf-post-tangle)
  245. (ly-toggle-pdf-display)
  246. (should (not ly-display-pdf-post-tangle))))
  247. (ert-deftest ob-lilypond/ly-toggle-arrange-mode ()
  248. (if ly-arrange-mode
  249. (progn
  250. (ly-toggle-arrange-mode)
  251. (should (not ly-arrange-mode))
  252. (ly-toggle-arrange-mode)
  253. (should ly-arrange-mode))
  254. (ly-toggle-arrange-mode)
  255. (should ly-arrange-mode)
  256. (ly-toggle-arrange-mode)
  257. (should (not ly-arrange-mode))))
  258. (ert-deftest ob-lilypond/ly-toggle-png-generation-toggles-flag ()
  259. (if ly-gen-png
  260. (progn
  261. (ly-toggle-png-generation)
  262. (should (not ly-gen-png))
  263. (ly-toggle-png-generation)
  264. (should ly-gen-png))
  265. (ly-toggle-png-generation)
  266. (should ly-gen-png)
  267. (ly-toggle-png-generation)
  268. (should (not ly-gen-png))))
  269. (ert-deftest ob-lilypond/ly-toggle-html-generation-toggles-flag ()
  270. (if ly-gen-html
  271. (progn
  272. (ly-toggle-html-generation)
  273. (should (not ly-gen-html))
  274. (ly-toggle-html-generation)
  275. (should ly-gen-html))
  276. (ly-toggle-html-generation)
  277. (should ly-gen-html)
  278. (ly-toggle-html-generation)
  279. (should (not ly-gen-html))))
  280. (ert-deftest ob-lilypond/ly-switch-extension-with-extensions ()
  281. (should (equal "test-name.xyz"
  282. (ly-switch-extension "test-name" ".xyz")))
  283. (should (equal "test-name.xyz"
  284. (ly-switch-extension "test-name.abc" ".xyz")))
  285. (should (equal "test-name"
  286. (ly-switch-extension "test-name.abc" ""))))
  287. (ert-deftest ob-lilypond/ly-switch-extension-with-paths ()
  288. (should (equal "/some/path/to/test-name.xyz"
  289. (ly-switch-extension "/some/path/to/test-name" ".xyz"))))
  290. (ert-deftest ob-lilypond/ly-get-header-args ()
  291. (should (equal '((:tangle . "yes")
  292. (:noweb . "yes")
  293. (:results . "silent")
  294. (:comments . "yes"))
  295. (ly-set-header-args t)))
  296. (should (equal '((:results . "file")
  297. (:exports . "results"))
  298. (ly-set-header-args nil))))
  299. (ert-deftest ob-lilypond/ly-set-header-args ()
  300. (ly-set-header-args t)
  301. (should (equal '((:tangle . "yes")
  302. (:noweb . "yes")
  303. (:results . "silent")
  304. (:comments . "yes"))
  305. org-babel-default-header-args:lilypond))
  306. (ly-set-header-args nil)
  307. (should (equal '((:results . "file")
  308. (:exports . "results"))
  309. org-babel-default-header-args:lilypond)))
  310. (provide 'test-ob-lilypond)
  311. ;;; test-ob-lilypond.el ends here