From mboxrd@z Thu Jan 1 00:00:00 1970 From: Martyn Jago Subject: [patch][babel] `org-babel-result-end' bug fix and regression tests Date: Fri, 06 Jan 2012 17:31:58 +0000 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([140.186.70.92]:47383) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RjDeM-0005w3-SJ for emacs-orgmode@gnu.org; Fri, 06 Jan 2012 12:32:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RjDeL-0008Eh-B2 for emacs-orgmode@gnu.org; Fri, 06 Jan 2012 12:32:18 -0500 Received: from lo.gmane.org ([80.91.229.12]:34769) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RjDeK-0008ET-PR for emacs-orgmode@gnu.org; Fri, 06 Jan 2012 12:32:17 -0500 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1RjDeI-0007vp-DR for emacs-orgmode@gnu.org; Fri, 06 Jan 2012 18:32:14 +0100 Received: from 88-96-171-138.dsl.zen.co.uk ([88.96.171.138]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 06 Jan 2012 18:32:14 +0100 Received: from martyn.jago by 88-96-171-138.dsl.zen.co.uk with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 06 Jan 2012 18:32:14 +0100 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-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain `org-babel-result-end' bug fix and `org-babel-remove-result' regression tests. * lisp/ob.el: The code block below will currently act as though :results prepend is set. This is due to `org-babel-result-end' being unable to find the correct end of a raw result. This patch fixes that. #+begin_src emacs-lisp :results raw "a line" #+end_src #+results: a line a line * testing/lisp/test-ob.el: Several regression tests that test the correct (multiple) execution of code blocks in the various results formats. The tests also test that 'org-babel-remove-result' correctly removes the result. Best, Martyn --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-org-babel-result-end-bug-fix-and-org-babel-remove-re.patch Content-Description: org-babel-result-end-fix >From 5a3148fb1e3de288e5e3534ceb06eb64c20697aa Mon Sep 17 00:00:00 2001 From: Martyn Jago Date: Fri, 6 Jan 2012 17:10:00 +0000 Subject: [PATCH] `org-babel-result-end' bug fix and `org-babel-remove-result' regression tests. * lisp/ob.el: The code block below will currently act as though :results prepend is set. This is due to `org-babel-result-end' being unable to find the correct end of a raw result. This patch fixes that. "a line" * testing/lisp/test-ob.el: Several regression tests that test the correct (multiple) execution of code blocks in the various results formats. The tests also test that 'org-babel-remove-result' correctly removes the result. --- lisp/ob.el | 2 +- testing/lisp/test-ob.el | 218 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 212 insertions(+), 8 deletions(-) diff --git a/lisp/ob.el b/lisp/ob.el index 0288eb3..26792ea 100644 --- a/lisp/ob.el +++ b/lisp/ob.el @@ -1810,7 +1810,7 @@ code ---- the results are extracted in the syntax of the source (if (looking-at (concat "[ \t]*#\\+begin_" blocks-re)) (progn (re-search-forward (concat "[ \t]*#\\+end_" blocks-re) nil t) (forward-char 1)) - (while (looking-at "[ \t]*\\(: \\|\\[\\[\\)") + (while (not (looking-at "^\s*$")) (forward-line 1)))) (point))))) diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index dac6866..f616776 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -137,13 +137,7 @@ #+name: i-have-a-name #+begin_src emacs-lisp 42 -#+end_src - -#+name: -: 42 - -#+name: i-have-a-name -: 42" +#+end_src" (progn (org-babel-next-src-block 1) @@ -671,6 +665,216 @@ on two lines (org-babel-balanced-split ":a 1 :b [2 3] :c (4 :d (5 6))" '((32 9) . 58))))) +(ert-deftest test-ob/commented-last-block-line-no-var () + (org-test-with-temp-text-in-file " +#+begin_src emacs-lisp +;; +#+end_src" + (progn + (org-babel-next-src-block) + (org-ctrl-c-ctrl-c) + (should (re-search-forward "\\#\\+results:" nil t)) + (forward-line) + (should + (string= + "" + (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))) + (org-test-with-temp-text-in-file " +#+begin_src emacs-lisp +\"some text\";; +#+end_src" + + (progn + (org-babel-next-src-block) + (org-ctrl-c-ctrl-c) + (should (re-search-forward "\\#\\+results:" nil t)) + (forward-line) + (should + (string= + ": some text" + (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))) + +(ert-deftest test-ob/commented-last-block-line-with-var () + (org-test-with-temp-text-in-file " +#+begin_src emacs-lisp :var a=1 +;; +#+end_src" + (progn + (org-babel-next-src-block) + (org-ctrl-c-ctrl-c) + (re-search-forward "\\#\\+results:" nil t) + (forward-line) + (should (string= + "" + (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))) + (org-test-with-temp-text-in-file " +#+begin_src emacs-lisp :var a=2 +2;; +#+end_src" + (progn + (org-babel-next-src-block) + (org-ctrl-c-ctrl-c) + (re-search-forward "\\#\\+results:" nil t) + (forward-line) + (should (string= + ": 2" + (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))) + +(defun test-ob-verify-result-and-removed-result (result buffer-text) + "Test helper function to test `org-babel-remove-result'. +A temp buffer is populated with BUFFER-TEXT, the first block is executed, +and the result of execution is verified against RESULT. + +The block is actually executed /twice/ to ensure result +replacement happens correctly." + (org-test-with-temp-text + buffer-text + (progn + (org-babel-next-src-block) (org-ctrl-c-ctrl-c) (org-ctrl-c-ctrl-c) + (should (re-search-forward "\\#\\+results:" nil t)) + (forward-line) + (should (string= result + (buffer-substring-no-properties + (point-at-bol) + (- (point-max) 16)))) + (org-babel-previous-src-block) (org-babel-remove-result) + (should (string= buffer-text + (buffer-substring-no-properties + (point-min) (point-max))))))) + +(ert-deftest test-ob/org-babel-remove-result--results-default () + "Test `org-babel-remove-result' with default :results." + (mapcar (lambda (language) + (test-ob-verify-result-and-removed-result + "\n" + (concat +"* org-babel-remove-result +#+begin_src " language " +#+end_src + +* next heading"))) + '("sh" "emacs-lisp"))) + +(ert-deftest test-ob/org-babel-remove-result--results-raw () + "Test `org-babel-remove-result' with :results raw." + (test-ob-verify-result-and-removed-result + "Hello +There!" + +"* org-babel-remove-result +#+begin_src emacs-lisp :results raw +(concat \"Hello +\"\"There!\") +#+end_src + +* next heading")) + +(ert-deftest test-ob/org-babel-remove-result--results-list () + "Test `org-babel-remove-result' with :results list." + (test-ob-verify-result-and-removed-result + "- 1 +- 2 +- 3 +- (quote (4 5))" + +"* org-babel-remove-result +#+begin_src emacs-lisp :results list +'(1 2 3 '(4 5)) +#+end_src + +* next heading")) + +;; TODO FIXME "wrap is inserting an extra newline following its result +;; (ert-deftest test-ob/org-babel-remove-result--results-wrap () +;; (test-ob-verify-result-and-removed-result +;; ":RESULTS:\nhello there\n:END:" +;; +;; "* org-babel-remove-result +;; +;; #+begin_src emacs-lisp :results wrap +;; \"hello there\" +;; #+end_src +;; +;; * next heading")) + +(ert-deftest test-ob/org-babel-remove-result--results-org () + "Test `org-babel-remove-result' with :results org." + (test-ob-verify-result-and-removed-result + "#+BEGIN_ORG +* heading +** subheading +content +#+END_ORG" + +"* org-babel-remove-result +#+begin_src emacs-lisp :results org +\"* heading +** subheading +content\" +#+end_src + +* next heading")) + +(ert-deftest test-ob/org-babel-remove-result--results-html () + "Test `org-babel-remove-result' with :results html." + (test-ob-verify-result-and-removed-result + "#+BEGIN_HTML + +#+END_HTML" + +"* org-babel-remove-result +#+begin_src emacs-lisp :results html +\"\" +#+end_src + +* next heading")) + +(ert-deftest test-ob/org-babel-remove-result--results-latex () + "Test `org-babel-remove-result' with :results latex." + (test-ob-verify-result-and-removed-result + "#+BEGIN_LaTeX +Line 1 +Line 2 +Line 3 +#+END_LaTeX" + +"* org-babel-remove-result +#+begin_src emacs-lisp :results latex +\"Line 1 +Line 2 +Line 3\" +#+end_src + +* next heading")) + +(ert-deftest test-ob/org-babel-remove-result--results-code () + "Test `org-babel-remove-result' with :results code." + + (test-ob-verify-result-and-removed-result + "#+BEGIN_SRC emacs-lisp +\"I am working!\" +#+END_SRC" + +"* org-babel-remove-result +#+begin_src emacs-lisp :results code +(message \"I am working!\") +#+end_src + +* next heading")) + +;; TODO Check pp works with emacs-lisp - according to the manual it does +(ert-deftest test-ob/org-babel-remove-result--results-pp () + "Test `org-babel-remove-result' with :results pp." + (test-ob-verify-result-and-removed-result + ": \"I /am/ working!\"" + +"* org-babel-remove-result +#+begin_src emacs-lisp :results pp +\"I /am/ working!\") +#+end_src + +* next heading")) + (provide 'test-ob) ;;; test-ob ends here -- 1.7.3.4 --=-=-=--