From: stardiviner <numbchild@gmail.com>
To: org-mode <emacs-orgmode@gnu.org>
Subject: Need help on my writing org-mode test.
Date: Sun, 08 Apr 2018 21:01:41 +0800 [thread overview]
Message-ID: <87in91c0ne.fsf@gmail.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 4260 bytes --]
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=
"hello\n"
(buffer-substring-no-properties (point-min) (point-max)))))
))
I run test with async shell command in Emacs:
make BTEST_RE="test-ob/result-file-link-type-header-argument" test-dirty
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 ‘"test-ob/result-file-link-type-header-argument"’)
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 "<point>" inside-text))
(unwind-protect (progn (org-mode) (let ((point (string-match "<point
(save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn
(let ((temp-buffer (generate-new-buffer " *temp*"))) (save-current-b
(let ((inside-text (if (stringp "\n#+begin_src sh :results link :fil
(lambda nil (let ((inside-text (if (stringp "\n#+begin_src sh :resul
ert--run-test-internal(#s(ert--test-execution-info :test #s(ert-test
ert-run-test(#s(ert-test :name test-ob/result-file-link-type-header-
ert-run-or-rerun-test(#s(ert--stats :selector "test-ob/result-file-l
ert-run-tests("test-ob/result-file-link-type-header-argument" #f(com
ert-run-tests-batch("test-ob/result-file-link-type-header-argument")
ert-run-tests-batch-and-exit("test-ob/result-file-link-type-header-a
(let ((org-id-track-globally t) (org-test-selector (if org-test-sele
org-test-run-batch-tests("test-ob/result-file-link-type-header-argum
eval((org-test-run-batch-tests org-test-select-re))
command-line-1(("--eval" "(setq vc-handled-backends nil org-startup-
command-line()
normal-top-level()
Test test-ob/result-file-link-type-header-argument condition:
(search-failed "[[file:test.txt]]")
FAILED 1/1 test-ob/result-file-link-type-header-argument (0.032747 sec)
Ran 1 tests, 0 results as expected, 1 unexpected (2018-04-08 20:52:42+0800, 0.877523 sec)
1 unexpected results:
FAILED test-ob/result-file-link-type-header-argument
make: *** [mk/targets.mk:105: test-dirty] Error 1
```
I tried many modification, I write this test based on existing test:
(ert-deftest test-ob/file-desc-header-argument ()
"Test that the :file-desc header argument is used."
(org-test-with-temp-text "#+begin_src emacs-lisp :results file :file-desc bar
\"foo\"
#+end_src
#+begin_src emacs-lisp :results file :file-desc
\"foo\"
#+end_src"
(org-babel-execute-src-block)
(org-babel-next-src-block 1)
(org-babel-execute-src-block)
(goto-char (point-min))
(should (search-forward "[[file:foo][bar]]" nil t))
(should (search-forward "[[file:foo][foo]]" nil t))))
Don't know why my test error. Can't find out what's wrong from truncated make test output.
I included my patch in attachment.
[-- Attachment #1.2: 0001-ob-core.el-add-results-link-type-result-for-babel.patch --]
[-- Type: text/x-patch, Size: 4080 bytes --]
From 51ed1e26852a0e7a0ef8fac4846c0f60ffcf4494 Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@gmail.com>
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".
---
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
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -113,6 +113,15 @@ now sort according to the locale’s collation rules instead of by
code-point.
** 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
--- 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)
- (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
- (let ((graphics?
- (member "graphics" (cdr (assq :result-params params)))))
- ;; Handle :results graphics :file case. Don't
- ;; write result to file if result is graphics.
- (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 :file.
+ (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
--- 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))))
+(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=
+ "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 "=%s="))
--
2.17.0
[-- Attachment #1.3: Type: text/plain, Size: 202 bytes --]
--
[ stardiviner ] don't need to convince with trends.
Blog: https://stardiviner.github.io/
IRC(freenode): stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]
next reply other threads:[~2018-04-08 13:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-08 13:01 stardiviner [this message]
2018-04-08 21:56 ` Need help on my writing org-mode test Nicolas Goaziou
2018-04-10 10:00 ` stardiviner
2018-04-23 10:29 ` Nicolas Goaziou
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=87in91c0ne.fsf@gmail.com \
--to=numbchild@gmail.com \
--cc=emacs-orgmode@gnu.org \
/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.