From mboxrd@z Thu Jan 1 00:00:00 1970 From: stardiviner Subject: Need help on my writing org-mode test. Date: Sun, 08 Apr 2018 21:01:41 +0800 Message-ID: <87in91c0ne.fsf@gmail.com> Reply-To: numbchild@gmail.com Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35497) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f59xK-0002O1-8i for emacs-orgmode@gnu.org; Sun, 08 Apr 2018 09:02:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f59xG-000810-3G for emacs-orgmode@gnu.org; Sun, 08 Apr 2018 09:02:02 -0400 Received: from [183.249.132.203] (port=10353 helo=dark.localdomain) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f59xE-0007fs-8J for emacs-orgmode@gnu.org; Sun, 08 Apr 2018 09:01:58 -0400 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: org-mode --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable I'm try to write a test for following src block: #+begin_src sh :results link :file "test.txt" echo "hello" > test.txt echo "test" #+end_src #+RESULTS[<2018-04-08 18:30:51> 22a787defa349526768722f4bfc8509dd16ab154]: [[file:test.txt]] And here is my ert test: (ert-deftest test-ob/result-file-link-type-header-argument () "Ensure that the result is a link to a file. The file is just a link to :file value. Inhibit non-empty result write to := file." (org-test-with-temp-text " #+begin_src sh :results link :file \"/tmp/test.txt\" echo \"hello\" > /tmp/test.txt echo \"test\" #+end_src" (org-babel-next-src-block 1) (org-babel-execute-src-block) (goto-char (point-min)) (should (search-forward "[[file:test.txt]]" nil nil)) (should (with-temp-buffer (insert-file-contents "/tmp/test.txt") (string=3D "hello\n" (buffer-substring-no-properties (point-min) (point-max))))) )) I run test with async shell command in Emacs: make BTEST_RE=3D"test-ob/result-file-link-type-header-argument" test-dirty =20=20=20 But I got error: ``` selected tests: test-ob/result-file-link-type-header-argument Running 1 tests (2018-04-08 20:52:41+0800, selector =E2=80=98"test-ob/resul= t-file-link-type-header-argument"=E2=80=99) executing Sh code block... Code block evaluation complete. Test test-ob/result-file-link-type-header-argument backtrace: search-forward("[[file:test.txt]]" nil nil nil) apply(search-forward ("[[file:test.txt]]" nil nil)) (setq value-1950 (apply fn-1948 args-1949)) (unwind-protect (setq value-1950 (apply fn-1948 args-1949)) (setq fo (if (unwind-protect (setq value-1950 (apply fn-1948 args-1949)) (set (let (form-description-1952) (if (unwind-protect (setq value-1950 (a (let ((value-1950 'ert-form-evaluation-aborted-1951)) (let (form-des (let* ((fn-1948 (function search-forward)) (args-1949 (condition-cas (progn (org-mode) (let ((point (string-match "" inside-text)) (unwind-protect (progn (org-mode) (let ((point (string-match " Date: Sun, 8 Apr 2018 20:56:28 +0800 Subject: [PATCH] ob-core.el: add :results link type result for babel. * lisp/ob-core.el (org-babel-execute-src-block): handle :results link type. Like :results graphics, don't write result to :file specified file. * etc/ORG-NEWS: declare new :results type "link". * testing/lisp/test-ob.el (test-ob/result-file-link-type-header-argument): Add test for new added :results type "link". =2D-- etc/ORG-NEWS | 9 +++++++++ lisp/ob-core.el | 12 ++++++------ testing/lisp/test-ob.el | 20 ++++++++++++++++++++ 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 0edd77115..3833b57b2 100644 =2D-- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -113,6 +113,15 @@ now sort according to the locale=E2=80=99s collation r= ules instead of by code-point. =20 ** New features +*** Add ~:results link~ support for org-babel +This will support only insert file link without writing result to file. +Like this case: +#+begin_src shell :dir "data/tmp" :results link :file "crackzor_1.0.c.gz" +wget -c "http://ben.akrin.com/crackzor/crackzor_1.0.c.gz" +#+end_src + +#+RESULTS: +[[file:data/tmp/crackzor_1.0.c.gz]] *** Add ~:session~ support of ob-js for js-comint #+begin_src js :session "*Javascript REPL*" console.log("stardiviner") diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 129e17f62..2dce0639e 100644 =2D-- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -413,7 +413,7 @@ then run `org-babel-switch-to-session'." (padline . ((yes no))) (post . :any) (prologue . :any) =2D (results . ((file list vector table scalar verbatim) + (results . ((file link list vector table scalar verbatim) (raw html latex org code pp drawer) (replace silent none append prepend) (output value))) @@ -706,11 +706,11 @@ block." (let ((file (cdr (assq :file params)))) ;; If non-empty result and :file then write to :file. (when file =2D (let ((graphics? =2D (member "graphics" (cdr (assq :result-params params))))) =2D ;; Handle :results graphics :file case. Don't =2D ;; write result to file if result is graphics. =2D (when (and result (not graphics?)) + (let ((graphics? (member "graphics" (cdr (assq :result-params params))= )) + (file-link? (member "link" (cdr (assq :result-params params))))) + ;; If :results are special types like `link', `graphics' etc. + ;; don't write result to `:file'. Literately only insert link to :fi= le. + (when (and result (not graphics?) (not file-link?)) (with-temp-file file (insert (org-babel-format-result result (cdr (assq :sep params))))))) diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index a4a590d6a..c1f5f3517 100644 =2D-- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -996,6 +996,26 @@ trying to find the :END: marker." (should (search-forward "[[file:foo][bar]]" nil t)) (should (search-forward "[[file:foo][foo]]" nil t)))) =20 +(ert-deftest test-ob/result-file-link-type-header-argument () + "Ensure that the result is a link to a file. +The file is just a link to :file value. Inhibit non-empty result write to = :file." + (org-test-with-temp-text + " +#+begin_src sh :results link :file \"/tmp/test.txt\" +echo \"hello\" > /tmp/test.txt +echo \"test\" +#+end_src" + (org-babel-next-src-block 1) + (org-babel-execute-src-block) + (goto-char (point-min)) + (should (search-forward "[[file:test.txt]]" nil nil)) + (should (with-temp-buffer + (insert-file-contents "/tmp/test.txt") + (string=3D + "hello\n" + (buffer-substring-no-properties (point-min) (point-max))))) + )) + (ert-deftest test-ob/inline-src_blk-preceded-punct-preceded-by-point () (let ((test-line ".src_emacs-lisp[ :results verbatim ]{ \"x\" }") (org-babel-inline-result-wrap "=3D%s=3D")) =2D-=20 2.17.0 --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable =2D-=20 [ stardiviner ] don't need to convince with trends. Blog: https://stardiviner.github.io/ IRC(freenode): stardiviner GPG: F09F650D7D674819892591401B5DF1C95AE89AC3 =20=20=20=20=20=20 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAlrKErUACgkQG13xyVro msMDGgf/RcBzx7X+y4tXHGuZwilogWow9mlRX59h0AWwc0kMe47OegktfimyNAlG F6j5Fy5z9pU3IMPTVerbYymFSN7+DMgOufpeIJsNK94RsAg5zwu1d3bt/eP9jxbU wmMKH1eMoBQ0bIvQvn6XhsfLf9IHxZwrsEfVrepLxeZw9qDDhCQM3pqXv/OPBqhk 33QP70sNLfXOnVc6wiYfPQ0dFFWKwDfnJmiSmOb1MWRb+mtLVq8mMn70MHmcXhjT hbvLMlJNkz5ryyqDkAo5AzDCbfpJYzHv6R89LvnO2YWxcobtwnZ9gzvR0rx//gSX sRvH3r2pwnIsJwbImX4PJAiemLCc3w== =CL48 -----END PGP SIGNATURE----- --==-=-=--