From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: Need help on my writing org-mode test. Date: Sun, 08 Apr 2018 23:56:44 +0200 Message-ID: <87bmetz7j7.fsf@nicolasgoaziou.fr> References: <87in91c0ne.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:52783) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f5IIt-00010d-15 for emacs-orgmode@gnu.org; Sun, 08 Apr 2018 17:56:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f5IIp-0007kr-VW for emacs-orgmode@gnu.org; Sun, 08 Apr 2018 17:56:51 -0400 Received: from relay9-d.mail.gandi.net ([217.70.183.199]:46905) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f5IIp-0007kR-OM for emacs-orgmode@gnu.org; Sun, 08 Apr 2018 17:56:47 -0400 In-Reply-To: <87in91c0ne.fsf@gmail.com> (stardiviner's message of "Sun, 08 Apr 2018 21:01:41 +0800") 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: stardiviner Cc: org-mode Hello, stardiviner 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 (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