emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
03df6ef9df28563674e9bcda3565d342c6fe0d3b blob 12851 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
 
;;; test-ob-lilypond.el --- tests for ob-lilypond.el

;; Copyright (c) 2010-2012 Martyn Jago
;; Authors: Martyn Jago

;; Released under the GNU General Public License version 3
;; see: http://www.gnu.org/licenses/gpl-3.0.html

;;; Code:
(unless (featurep 'ob-lilypond)
  (signal 'missing-test-dependency "Support for Lilypond code blocks"))

(save-excursion
  (set-buffer (get-buffer-create "test-ob-lilypond.el"))
  (setq ly-here
        (file-name-directory
         (or load-file-name (buffer-file-name)))))

(ert-deftest ob-lilypond/assert ()
  (should t))
 
(ert-deftest ob-lilypond/feature-provision ()
  (should (featurep 'ob-lilypond)))
  
(ert-deftest ob-lilypond/check-lilypond-alias ()
  (should (fboundp 'lilypond-mode)))

(ert-deftest ob-lilypond/org-babel-tangle-lang-exts ()
  (let ((found nil)
        (list org-babel-tangle-lang-exts))
    (while list
      (when (equal (car list) '("LilyPond" . "ly"))
        (setq found t))
      (setq list (cdr list)))
    (should found)))
     
(ert-deftest ob-lilypond/org-babel-prep-session:lilypond ()
  (should-error (org-babel-prep-session:lilypond nil nil))
  :type 'error)

(ert-deftest ob-lilypond/ly-version-const () 
  (should (boundp 'ly-version)))

(ert-deftest ob-lilypond/ly-version-command ()
  (should (equal "ob-lilypond version 0.3" (ly-version)))
  (with-temp-buffer
    (ly-version t)
    (should (equal "ob-lilypond version 0.3"
                   (buffer-substring (point-min) (point-max))))))

(ert-deftest ob-lilypond/ly-compile-lilyfile ()
  (should (equal
           `(,(ly-determine-ly-path)    ;program
             nil                        ;infile
             "*lilypond*"               ;buffer
             t                          ;display
             ,(if ly-gen-png  "--png"  "") ;&rest...
             ,(if ly-gen-html "--html" "")   
             ,(if ly-use-eps  "-dbackend=eps" "")
             ,(if ly-gen-svg  "-dbackend=svg" "")
             "--output=test-file"
             "test-file.ly")
           (ly-compile-lilyfile "test-file.ly" t))))

(ert-deftest ob-lilypond/ly-compile-post-tangle ()
  (should (boundp 'ly-compile-post-tangle)))

(ert-deftest ob-lilypond/ly-display-pdf-post-tangle ()
  (should (boundp 'ly-display-pdf-post-tangle)))

(ert-deftest ob-lilypond/ly-play-midi-post-tangle ()
  (should (boundp 'ly-play-midi-post-tangle)))

(ert-deftest ob-lilypond/ly-OSX-ly-path ()
  (should (boundp 'ly-OSX-ly-path))
  (should (stringp ly-OSX-ly-path)))

(ert-deftest ob-lilypond/ly-OSX-pdf-path ()
  (should (boundp 'ly-OSX-pdf-path))
  (should (stringp ly-OSX-pdf-path)))

(ert-deftest ob-lilypond/ly-OSX-midi-path ()
  (should (boundp 'ly-OSX-midi-path))
  (should (stringp ly-OSX-midi-path)))

(ert-deftest ob-lilypond/ly-nix-ly-path ()
  (should (boundp 'ly-nix-ly-path))
  (should (stringp ly-nix-ly-path)))

(ert-deftest ob-lilypond/ly-nix-pdf-path ()
  (should (boundp 'ly-nix-pdf-path))
  (should (stringp ly-nix-pdf-path)))

(ert-deftest ob-lilypond/ly-nix-midi-path ()
  (should (boundp 'ly-nix-midi-path))
  (should (stringp ly-nix-midi-path)))

(ert-deftest ob-lilypond/ly-win32-ly-path ()
  (should (boundp 'ly-win32-ly-path))
  (should (stringp ly-win32-ly-path)))

(ert-deftest ob-lilypond/ly-win32-pdf-path ()
  (should (boundp 'ly-win32-pdf-path))
  (should (stringp ly-win32-pdf-path)))

(ert-deftest ob-lilypond/ly-win32-midi-path ()
  (should (boundp 'ly-win32-midi-path))
  (should (stringp ly-win32-midi-path)))

(ert-deftest ob-lilypond/ly-gen-png ()
  (should (boundp 'ly-gen-png)))

(ert-deftest ob-lilypond/ly-gen-svg ()
  (should (boundp 'ly-gen-svg)))

(ert-deftest ob-lilypond/ly-gen-html ()
  (should (boundp 'ly-gen-html)))

(ert-deftest ob-lilypond/use-eps ()
  (should (boundp 'ly-use-eps)))

(ert-deftest ob-lilypond/ly-arrange-mode ()
  (should (boundp 'ly-arrange-mode)))

;; (ert-deftest ob-lilypond/org-babel-default-header-args:lilypond ()
;;   (should (equal  '((:tangle . "yes")
;;                     (:noweb . "yes")
;;                     (:results . "silent")
;;                     (:comments . "yes"))
;;                   org-babel-default-header-args:lilypond)))

;;TODO finish...
(ert-deftest ob-lilypond/org-babel-expand-body:lilypond ()
  (should (equal "This is a test"
                 (org-babel-expand-body:lilypond "This is a test" ()))))

;;TODO (ert-deftest ly-test-org-babel-execute:lilypond ())
(ert-deftest ob-lilypond/ly-check-for-compile-error ()
  (set-buffer (get-buffer-create "*lilypond*"))
  (erase-buffer)
  (should (not (ly-check-for-compile-error nil t)))
  (insert-file-contents (concat ly-here
                                "../examples/ob-lilypond-test.error")
                        nil nil nil t)
  (goto-char (point-min))
  (should (ly-check-for-compile-error nil t))
  (kill-buffer "*lilypond*"))

(ert-deftest ob-lilypond/ly-process-compile-error ()
  (find-file-other-window (concat
                           ly-here
                           "../examples/ob-lilypond-broken.org"))
  (set-buffer (get-buffer-create "*lilypond*"))
  (insert-file-contents (concat
                         ly-here
                         "../examples/ob-lilypond-test.error")
                        nil nil nil t)
  (goto-char (point-min))
  (search-forward "error:" nil t)
  (should-error
   (ly-process-compile-error (concat
                              ly-here
                              "../examples/ob-lilypond-broken.ly"))
   :type 'error)
  (set-buffer "ob-lilypond-broken.org")
  (should (equal 238 (point)))
  (exchange-point-and-mark)
  (should (equal (+ 238 (length "line 25")) (point)))
  (kill-buffer "*lilypond*")
  (kill-buffer "ob-lilypond-broken.org"))
   
(ert-deftest ob-lilypond/ly-mark-error-line ()
  (let ((file-name (concat
                    ly-here
                    "../examples/ob-lilypond-broken.org"))
        (expected-point-min 198)
        (expected-point-max 205)
        (line "line 20"))
    (find-file-other-window file-name)
    (ly-mark-error-line file-name line)
    (should (equal expected-point-min (point)))
  
    (exchange-point-and-mark)
    (should (= expected-point-max (point)))
    (kill-buffer (file-name-nondirectory file-name))))

(ert-deftest ob-lilypond/ly-parse-line-num ()
  (with-temp-buffer
    (insert-file-contents (concat
                           ly-here
                           "../examples/ob-lilypond-test.error")
                          nil nil nil t)
    (goto-char (point-min))
    (search-forward "error:")
    (should (equal 25 (ly-parse-line-num (current-buffer))))))
  
(ert-deftest ob-lilypond/ly-parse-error-line ()
  (let ((ly-file (concat
                  ly-here
                  "../examples/ob-lilypond-broken.ly")))
    (should (equal "line 20"
                   (ly-parse-error-line ly-file 20)))
    (should (not (ly-parse-error-line ly-file 0)))))
    
(ert-deftest ob-lilypond/ly-attempt-to-open-pdf ()
  (let ((post-tangle ly-display-pdf-post-tangle)
        (ly-file (concat
                  ly-here
                  "../examples/ob-lilypond-test.ly"))
        (pdf-file (concat
                   ly-here
                   "../examples/ob-lilypond-test.pdf")))
    (setq ly-display-pdf-post-tangle t)
    (when (not (file-exists-p pdf-file))
      (set-buffer (get-buffer-create (file-name-nondirectory pdf-file)))
      (write-file pdf-file))
    (should (equal 
             (concat
              (ly-determine-pdf-path) " " pdf-file)
             (ly-attempt-to-open-pdf ly-file t)))
    (delete-file pdf-file)
    (kill-buffer (file-name-nondirectory pdf-file))
    (should (equal
             "No pdf file generated so can't display!"
             (ly-attempt-to-open-pdf pdf-file)))
    (setq ly-display-pdf-post-tangle post-tangle)))

(ert-deftest ob-lilypond/ly-attempt-to-play-midi ()
  (let ((post-tangle ly-play-midi-post-tangle)
        (ly-file (concat
                  ly-here
                  "../examples/ob-lilypond-test.ly"))
        (midi-file (concat
                    ly-here
                    "../examples/ob-lilypond-test.midi")))
    (setq ly-play-midi-post-tangle t)
    (when (not (file-exists-p midi-file))
      (set-buffer (get-buffer-create (file-name-nondirectory midi-file)))
      (write-file midi-file))
    (should (equal
             (concat
              (ly-determine-midi-path) " " midi-file)
             (ly-attempt-to-play-midi ly-file t)))
    (delete-file midi-file)
    (kill-buffer (file-name-nondirectory midi-file))
    (should (equal
             "No midi file generated so can't play!"
             (ly-attempt-to-play-midi midi-file)))
    (setq ly-play-midi-post-tangle post-tangle)))

(ert-deftest ob-lilypond/ly-determine-ly-path ()
  (should (equal ly-OSX-ly-path
                 (ly-determine-ly-path "darwin")))
  (should (equal ly-win32-ly-path
                 (ly-determine-ly-path "win32")))
  (should (equal ly-nix-ly-path
                 (ly-determine-ly-path "nix"))))

(ert-deftest ob-lilypond/ly-determine-pdf-path ()
  (should (equal ly-OSX-pdf-path
                 (ly-determine-pdf-path "darwin")))
  (should (equal ly-win32-pdf-path
                 (ly-determine-pdf-path "win32")))
  (should (equal ly-nix-pdf-path
                 (ly-determine-pdf-path "nix"))))

(ert-deftest ob-lilypond/ly-determine-midi-path ()
  (should (equal ly-OSX-midi-path
                 (ly-determine-midi-path "darwin")))
  (should (equal ly-win32-midi-path
                 (ly-determine-midi-path "win32")))
  (should (equal ly-nix-midi-path
                 (ly-determine-midi-path "nix"))))

(ert-deftest ob-lilypond/ly-toggle-midi-play-toggles-flag ()
  (if ly-play-midi-post-tangle
      (progn
        (ly-toggle-midi-play)
         (should (not ly-play-midi-post-tangle))
        (ly-toggle-midi-play)
        (should ly-play-midi-post-tangle))
    (ly-toggle-midi-play)
    (should ly-play-midi-post-tangle)
    (ly-toggle-midi-play)
    (should (not ly-play-midi-post-tangle))))

(ert-deftest ob-lilypond/ly-toggle-pdf-display-toggles-flag ()
  (if ly-display-pdf-post-tangle
      (progn
        (ly-toggle-pdf-display)
         (should (not ly-display-pdf-post-tangle))
        (ly-toggle-pdf-display)
        (should ly-display-pdf-post-tangle))
    (ly-toggle-pdf-display)
    (should ly-display-pdf-post-tangle)
    (ly-toggle-pdf-display)
    (should (not ly-display-pdf-post-tangle))))

(ert-deftest ob-lilypond/ly-toggle-arrange-mode ()
  (if ly-arrange-mode
      (progn
        (ly-toggle-arrange-mode)
        (should (not ly-arrange-mode))
        (ly-toggle-arrange-mode)
        (should ly-arrange-mode))
    (ly-toggle-arrange-mode)
    (should ly-arrange-mode)
    (ly-toggle-arrange-mode)
    (should (not ly-arrange-mode))))

(ert-deftest ob-lilypond/ly-toggle-png-generation-toggles-flag ()
  (if ly-gen-png
      (progn
        (ly-toggle-png-generation)
         (should (not ly-gen-png))
        (ly-toggle-png-generation)
        (should ly-gen-png))
    (ly-toggle-png-generation)
    (should ly-gen-png)
    (ly-toggle-png-generation)
    (should (not ly-gen-png))))
 
(ert-deftest ob-lilypond/ly-toggle-html-generation-toggles-flag ()
  (if ly-gen-html
      (progn
        (ly-toggle-html-generation)
         (should (not ly-gen-html))
        (ly-toggle-html-generation)
        (should ly-gen-html))
    (ly-toggle-html-generation)
    (should ly-gen-html)
    (ly-toggle-html-generation)
    (should (not ly-gen-html))))

(ert-deftest ob-lilypond/ly-switch-extension-with-extensions ()
  (should (equal "test-name.xyz"
                 (ly-switch-extension "test-name" ".xyz")))
  (should (equal "test-name.xyz"
                 (ly-switch-extension "test-name.abc" ".xyz")))
  (should (equal "test-name"
                 (ly-switch-extension "test-name.abc" ""))))

(ert-deftest ob-lilypond/ly-switch-extension-with-paths ()
  (should (equal "/some/path/to/test-name.xyz"
                  (ly-switch-extension "/some/path/to/test-name" ".xyz"))))

(ert-deftest ob-lilypond/ly-get-header-args ()
  (should (equal '((:tangle . "yes")
                   (:noweb . "yes")
                   (:results . "silent")
                   (:comments . "yes"))
                 (ly-set-header-args t)))
  (should (equal '((:results . "file")
                   (:exports . "results"))
                 (ly-set-header-args nil))))

(ert-deftest ob-lilypond/ly-set-header-args ()
  (ly-set-header-args t)
  (should (equal '((:tangle . "yes")
                   (:noweb . "yes")
                   (:results . "silent")
                   (:comments . "yes"))
                 org-babel-default-header-args:lilypond))
  (ly-set-header-args nil)
  (should (equal '((:results . "file")
                   (:exports . "results"))
                 org-babel-default-header-args:lilypond)))
                 
(provide 'test-ob-lilypond)

;;; test-ob-lilypond.el ends here
 
debug log:

solving 03df6ef ...
found 03df6ef in https://git.savannah.gnu.org/cgit/emacs/org-mode.git

Code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).