From: Leo Butler <Leo.Butler@umanitoba.ca>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: Org Mode Mailing List <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] lisp/ob-octave.el, was [PATCH] rfc: using ert-deftest with side-effects
Date: Tue, 15 Nov 2022 19:43:24 +0000 [thread overview]
Message-ID: <87leocuhpg.fsf@t14.reltub.ca> (raw)
In-Reply-To: <87bkpaguy3.fsf@localhost> (Ihor Radchenko's message of "Mon, 14 Nov 2022 01:56:36 +0000")
[-- Attachment #1: Type: text/plain, Size: 605 bytes --]
On Mon, Nov 14 2022, Ihor Radchenko <yantar92@posteo.net> wrote:
> Leo Butler <Leo.Butler@umanitoba.ca> writes:
>
>> The amended patch is attached. Thanks for your helpful feedback.
>
> Thanks for the patch!
> It looks good, and the tests are passing. However, there is a side effect
> leaving testing/examples/octave-workspace file after running the tests.
>
> Can something be done about this?
Yes, sorry about that, I should have caught that while testing the
patch. the amended patch (attached) prevents Octave from dumping a core
file when running the :session test.
Best,
Leo
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-prevent-error-in-Octave-process-add-tests-update-tes.patch --]
[-- Type: text/x-diff; name="0001-prevent-error-in-Octave-process-add-tests-update-tes.patch", Size: 6736 bytes --]
From 386c9c2f65730459bdc69b2e0b0b76e22e32dbc9 Mon Sep 17 00:00:00 2001
From: Leo Butler <leo.butler@umanitoba.ca>
Date: Tue, 8 Nov 2022 13:31:47 -0600
Subject: [PATCH] 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
---
lisp/ob-octave.el | 2 +-
testing/examples/ob-octave-test.org | 12 +++++-
testing/lisp/test-ob-octave.el | 65 +++++++++++++++++++++++++++++
3 files changed, 76 insertions(+), 3 deletions(-)
diff --git a/lisp/ob-octave.el b/lisp/ob-octave.el
index 55926b789..1cb0e70b5 100644
--- a/lisp/ob-octave.el
+++ b/lisp/ob-octave.el
@@ -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)))
diff --git a/testing/examples/ob-octave-test.org b/testing/examples/ob-octave-test.org
index 9839d637e..bc19051a1 100644
--- a/testing/examples/ob-octave-test.org
+++ b/testing/examples/ob-octave-test.org
@@ -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
+
+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
-#+begin_src octave :session
+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
diff --git a/testing/lisp/test-ob-octave.el b/testing/lisp/test-ob-octave.el
index 78ce10214..57f40d00b 100644
--- a/testing/lisp/test-ob-octave.el
+++ b/testing/lisp/test-ob-octave.el
@@ -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)
--
2.35.1
next prev parent reply other threads:[~2022-11-15 19:49 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-07 17:03 [PATCH] rfc: using ert-deftest with side-effects Leo Butler
2022-11-08 7:40 ` Ihor Radchenko
2022-11-08 19:55 ` [PATCH] lisp/ob-octave.el, was " Leo Butler
2022-11-09 5:14 ` Ihor Radchenko
2022-11-09 20:33 ` Leo Butler
2022-11-14 1:56 ` Ihor Radchenko
2022-11-15 19:43 ` Leo Butler [this message]
2022-12-17 8:25 ` Ihor Radchenko
2022-12-17 10:06 ` Ihor Radchenko
2022-12-21 11:56 ` Ihor Radchenko
2022-12-22 13:32 ` Leo Butler
2022-12-27 14:45 ` Ihor Radchenko
2022-12-29 9:54 ` Ihor Radchenko
2023-01-02 8:42 ` Ihor Radchenko
2023-01-05 20:08 ` Leo Butler
2023-01-06 15:11 ` Ihor Radchenko
2023-01-07 3:08 ` Leo Butler
2023-01-10 20:30 ` Leo Butler
2023-01-11 11:15 ` Ihor Radchenko
2023-01-11 21:51 ` Leo Butler
2023-01-12 8:42 ` Ihor Radchenko
2023-01-13 18:00 ` Ihor Radchenko
2023-01-14 13:04 ` Leo Butler
2023-01-14 13:13 ` Ihor Radchenko
2023-01-14 15:16 ` Max Nikulin
2023-01-23 10:32 ` Ihor Radchenko
2023-01-24 18:08 ` Leo Butler
2023-01-07 12:48 ` Ihor Radchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87leocuhpg.fsf@t14.reltub.ca \
--to=leo.butler@umanitoba.ca \
--cc=emacs-orgmode@gnu.org \
--cc=yantar92@posteo.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.