emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: stardiviner <numbchild@gmail.com>
Cc: org-mode <emacs-orgmode@gnu.org>
Subject: Re: Need help on my writing org-mode test.
Date: Sun, 08 Apr 2018 23:56:44 +0200	[thread overview]
Message-ID: <87bmetz7j7.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <87in91c0ne.fsf@gmail.com> (stardiviner's message of "Sun, 08 Apr 2018 21:01:41 +0800")

Hello,

stardiviner <numbchild@gmail.com> writes:

> 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 would check the result of

    (let ((output-file (make-temp-file "org-test")))
        (org-test-with-temp-text
            (format "
    #+begin_src emacs-lisp :results link :file %S<point>
      (with-temp-file %S (insert \"foo\"))
    #+end_src"
                    output-file
                    output-file)
          (org-babel-execute-src-block)
          (goto-char (point-max))
          (buffer-substring-no-properties
           (line-beginning-position 0)
           (line-end-position 0))))

Regards,

-- 
Nicolas Goaziou

  reply	other threads:[~2018-04-08 21:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-08 13:01 Need help on my writing org-mode test stardiviner
2018-04-08 21:56 ` Nicolas Goaziou [this message]
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

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bmetz7j7.fsf@nicolasgoaziou.fr \
    --to=mail@nicolasgoaziou.fr \
    --cc=emacs-orgmode@gnu.org \
    --cc=numbchild@gmail.com \
    /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 public 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).