mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-08-25 18:32:51 +00:00
prevent error in Octave process, add tests, update test docs
* lisp/ob-octave.el (org-babel-execute:octave): -Ensure that the special Octave variable `ans' is bound when GFX-FILE is non-nil. The glue code in ORG-BABEL-OCTAVE-WRAPPER-METHOD causes Octave to exit with a non-zero exit code when `ans' is not bound. -Change format control string to %S from %s. Ensure the graphics filename is quoted. If it is not, Octave may create a mis-named file or fail entirely. * testing/examples/ob-octave-test.org: Update the Graphical tests section: -put in the correct headers; -add a remark about where to find each test. * testing/lisp/test-ob-octave.el: Add the three tests ob-octave/graphics-file, ob-octave/graphics-file-session and ob-octave/graphics-file-space. -ob-octave/graphics-file: The first test verifies that the first bug identified above is fixed; it also verifies that graphics file creation works correctly for scripting. -ob-octave/graphics-file-session: The second test verifies graphics file creation works correctly for sessions. The Octave command `crash_dumps_octave_core(0)' is included to prevent the creation of a core file (`octave-workspace'). -ob-octave/graphics-file-space: The third test verifies that a graphics filename with a space in it is created correctly. Thanks to Ihor Radchenko for helpful feedback. Ref: https://list.orgmode.org/8735asbtfe.fsf@localhost/T/#u
This commit is contained in:
parent
555dacfa8b
commit
01c0ebee2f
|
@ -91,7 +91,7 @@ end")
|
|||
(list
|
||||
"set (0, \"defaultfigurevisible\", \"off\");"
|
||||
full-body
|
||||
(format "print -dpng %s" gfx-file))
|
||||
(format "print -dpng %S\nans=%S" gfx-file gfx-file))
|
||||
"\n")
|
||||
full-body)
|
||||
result-type matlabp)))
|
||||
|
|
|
@ -46,10 +46,18 @@ ans = s
|
|||
|
||||
|
||||
* Graphical tests
|
||||
#+begin_src octave :results graphics :file chart.png
|
||||
|
||||
Graphics file. This test is performed by =ob-octave/graphics-file= in =testing/lisp/test-ob-octave.el=.
|
||||
#+begin_src octave :results file graphics :file sombrero.png
|
||||
sombrero;
|
||||
#+end_src
|
||||
|
||||
#+begin_src octave :session
|
||||
Graphics file in a session. This test is performed by =ob-octave/graphics-file-session= in =testing/lisp/test-ob-octave.el=.
|
||||
#+begin_src octave :session :results graphics file :file sombrero.png
|
||||
sombrero;
|
||||
#+end_src
|
||||
|
||||
Graphics file with a space in name. This test is performed by =ob-octave/graphics-file-space= in =testing/lisp/test-ob-octave.el=.
|
||||
#+begin_src octave :results graphics file :file sombrero hat.png
|
||||
sombrero;
|
||||
#+end_src
|
||||
|
|
|
@ -64,4 +64,69 @@
|
|||
(org-babel-next-src-block 5)
|
||||
(should (equal nil (org-babel-execute-src-block)))))
|
||||
|
||||
(ert-deftest ob-octave/graphics-file ()
|
||||
"Graphics file. Test that link is correctly inserted and graphics file is created (and not empty). Clean-up side-effects."
|
||||
;; In case a prior test left the Error Output buffer hanging around.
|
||||
(when (get-buffer "*Org-Babel Error Output*")
|
||||
(kill-buffer "*Org-Babel Error Output*"))
|
||||
(let ((file (make-temp-file "test-ob-octave-" nil ".png")))
|
||||
(unwind-protect
|
||||
(org-test-with-temp-text
|
||||
(format "#+begin_src octave :results file graphics :file %s
|
||||
sombrero;
|
||||
#+end_src"
|
||||
file)
|
||||
(org-babel-execute-src-block)
|
||||
(should (search-forward (format "[[file:%s]]" file) nil nil))
|
||||
(should (file-readable-p file))
|
||||
(should (> (file-attribute-size (file-attributes file)) 0))
|
||||
(should-not (get-buffer "*Org-Babel Error Output*")))
|
||||
;; clean-up
|
||||
(delete-file file)
|
||||
(when (get-buffer "*Org-Babel Error Output*")
|
||||
(kill-buffer "*Org-Babel Error Output*")))))
|
||||
|
||||
(ert-deftest ob-octave/graphics-file-session ()
|
||||
"Graphics file in a session. Test that session is started in *Inferior Octave* buffer, link is correctly inserted and graphics file is created (and not empty). Clean-up side-effects."
|
||||
(let ((file (make-temp-file "test-ob-octave-" nil ".png")))
|
||||
(unwind-protect
|
||||
(org-test-with-temp-text
|
||||
(format "#+begin_src octave :session :results file graphics :file %s
|
||||
crash_dumps_octave_core(0);
|
||||
sombrero;
|
||||
#+end_src"
|
||||
file)
|
||||
(org-babel-execute-src-block)
|
||||
(should (get-buffer "*Inferior Octave*"))
|
||||
(should (search-forward (format "[[file:%s]]" file) nil nil))
|
||||
(should (file-readable-p file))
|
||||
(should (> (file-attribute-size (file-attributes file)) 0))
|
||||
(should-not (get-buffer "*Org-Babel Error Output*")))
|
||||
;; clean-up
|
||||
(delete-file file)
|
||||
(let (kill-buffer-query-functions kill-buffer-hook)
|
||||
(kill-buffer "*Inferior Octave*"))
|
||||
(when (get-buffer "*Org-Babel Error Output*")
|
||||
(kill-buffer "*Org-Babel Error Output*")))))
|
||||
|
||||
(ert-deftest ob-octave/graphics-file-space ()
|
||||
"Graphics file with a space in filename. Test that session is started in *Inferior Octave* buffer, link is correctly inserted and graphics file is created (and not empty). Clean-up side-effects."
|
||||
(let ((file (make-temp-file "test ob octave-" nil ".png")))
|
||||
(unwind-protect
|
||||
(org-test-with-temp-text
|
||||
(format "#+begin_src octave :results file graphics :file %s
|
||||
sombrero;
|
||||
#+end_src"
|
||||
file)
|
||||
(org-babel-execute-src-block)
|
||||
(should (search-forward (format "[[file:%s]]" file) nil nil))
|
||||
(should (file-readable-p file))
|
||||
(should (> (file-attribute-size (file-attributes file)) 0))
|
||||
(should-not (get-buffer "*Org-Babel Error Output*")))
|
||||
;; clean-up
|
||||
(delete-file file)
|
||||
(when (get-buffer "*Org-Babel Error Output*")
|
||||
(kill-buffer "*Org-Babel Error Output*")))))
|
||||
|
||||
|
||||
(provide 'test-ob-octave)
|
||||
|
|
Loading…
Reference in a new issue