all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Martyn Jago <martyn.jago@btinternet.com>
To: emacs-orgmode@gnu.org
Subject: Re: [babel] Trying to add ERT test cases
Date: Wed, 21 Sep 2011 05:18:55 +0100	[thread overview]
Message-ID: <m2y5xiil3k.fsf@btinternet.com> (raw)
In-Reply-To: 87obyftf22.fsf@gmail.com

[-- Attachment #1: Type: text/plain, Size: 818 bytes --]

Hi Eric

Eric Schulte <schulte.eric@gmail.com> writes:

>>>
>>> Footnotes: [1] ,----
>>> | org-test-with-temp-text is a Lisp macro in `org-test.el'.
>>> | 
>>> | (org-test-with-temp-text TEXT &rest BODY)
>>> | 
>>> | Run body in a temporary buffer with Org-mode as the active
>>> | mode holding TEXT.  If the string "<point>" appears in TEXT
>>> | then remove it and place the point there before running BODY.
>>> `----
>>
>> This looks useful, however I hit problems when refactoring my tests to
>> use it. Would it be easy for your macro to accept string variables in
>> addition to strings? 
>>
>
> Hmm, that is weird.  I've just pushed up a fix so this should now be
> solved.
>
> Thanks for the catch -- Eric

Thanks, that works great. I've updated test-ob.el to use the macro and
include a patch.

Best, Martyn


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Refactor tests to use `org-test-with-temp-text' --]
[-- Type: text/x-patch, Size: 8802 bytes --]

From bb1680342b890dbe5562878a59655b5754ab5ef3 Mon Sep 17 00:00:00 2001
From: Martyn Jago <martyn.jago@btinternet.com>
Date: Wed, 21 Sep 2011 05:06:44 +0100
Subject: [PATCH] Refactor tests to use `org-test-with-temp-text'
 * testing/lisp/test-ob.el: refactor

---
 testing/lisp/test-ob.el |  125 ++++++++++++++++++++++-------------------------
 1 files changed, 58 insertions(+), 67 deletions(-)

diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el
index f78ca98..24a64c9 100644
--- a/testing/lisp/test-ob.el
+++ b/testing/lisp/test-ob.el
@@ -238,12 +238,10 @@
     )))
 
 (ert-deftest test-org-babel/inline-src_blk-default-results-replace-line-1 ()
-  (with-temp-buffer
-
+  (let ((test-line "src_sh{echo 1}"))
     ;; src_ at bol line 1...
-    (let ((test-line "src_sh{echo 1}"))
-      (insert test-line)
-      (should-error (org-ctrl-c-ctrl-c))
+    (org-test-with-temp-text
+	test-line
       (goto-char (point-min)) (org-ctrl-c-ctrl-c)
       (should (string=
        	       (concat test-line " =1=")
@@ -259,12 +257,10 @@
       (should (string=
        	       (concat test-line " =1= =1= =1=")
        	       (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
-
     ;; src_ follows space line 1...
     (let ((test-line " src_emacs-lisp{ 1 }"))
-      (beginning-of-line)
-      (insert (concat test-line "\n"))
-      (goto-char (point-min))
+    (org-test-with-temp-text
+	test-line
       (should-error (org-ctrl-c-ctrl-c))
       (forward-char) (org-ctrl-c-ctrl-c) 
       (should (string=
@@ -275,15 +271,13 @@
 	       (concat test-line " =1= =1=")
 	       (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
       (forward-char)
-      (should-error (org-ctrl-c-ctrl-c))
-      )))
+      (should-error (org-ctrl-c-ctrl-c)))))
 
 (ert-deftest test-org-babel/inline-src_blk-default-results-replace-line-2 ()
-  (with-temp-buffer
-
-    ;; src_ at bol line 2...
-    (let ((test-line " src_emacs-lisp{ \"x\" }"))
-      (insert (concat "\n" test-line))
+  ;; src_ at bol line 2...
+  (let ((test-line " src_emacs-lisp{ \"x\" }"))
+    (org-test-with-temp-text
+	(concat "\n" test-line)
       (should-error (org-ctrl-c-ctrl-c))
       (goto-char (point-min))
       (should-error (org-ctrl-c-ctrl-c))
@@ -292,9 +286,11 @@
       (forward-char) (org-ctrl-c-ctrl-c)
       (should (string=
 	       (concat test-line " =x=")
-	       (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
+	       (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
 
-    (let ((test-line "Some text prior to block src_emacs-lisp{ \"y\" }"))
+  (let ((test-line "Some text prior to block src_emacs-lisp{ \"y\" }"))
+    (org-test-with-temp-text
+	test-line
       (goto-char (point-max))
       (insert (concat "\n" test-line " end"))
       (re-search-backward "src") (org-ctrl-c-ctrl-c)
@@ -306,25 +302,25 @@
 	       (concat test-line " =y= =y= end")
        	       (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
       (forward-char)
-      (should-error (org-ctrl-c-ctrl-c))
-      )))
+      (should-error (org-ctrl-c-ctrl-c))))))
 
 (ert-deftest test-org-babel/inline-src_blk-manual-results-replace ()
-  (with-temp-buffer
-
-    (let ((test-line " src_emacs-lisp[:results replace]{ \"x\" }"))
-      (insert (concat "\n" test-line))
+  (let ((test-line " src_emacs-lisp[:results replace]{ \"x\" }"))
+    (org-test-with-temp-text
+	(concat "\n" test-line)
       (should-error (org-ctrl-c-ctrl-c))
-      (goto-char (point-min))
+      (goto-char (point-max))
       (should-error (org-ctrl-c-ctrl-c))
-      (forward-line)
+      (beginning-of-line)
       (should-error (org-ctrl-c-ctrl-c))
       (forward-char) (org-ctrl-c-ctrl-c)
       (should (string=
       	       (concat test-line " =x=")
-      	       (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
+      	       (buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
     
-    (let ((test-line " Some text prior to block src_emacs-lisp[:results replace]{ \"y\" }"))
+  (let ((test-line " Some text prior to block src_emacs-lisp[:results replace]{ \"y\" }"))
+    (org-test-with-temp-text
+	test-line
       (goto-char (point-max))
       (insert (concat "\n" test-line " end"))
       (re-search-backward "src") (org-ctrl-c-ctrl-c)
@@ -336,19 +332,20 @@
     	       (concat test-line " =y= =y= end")
     	       (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
       (forward-char)
-      (should-error (org-ctrl-c-ctrl-c)))
-    ))
+      (should-error (org-ctrl-c-ctrl-c)))))
 
 (ert-deftest test-org-babel/inline-src_blk-results-silent ()
-  (with-temp-buffer
-
-    (let ((test-line "src_emacs-lisp[ :results silent ]{ \"x\" }"))
-      (insert test-line)
-      (should-error (org-ctrl-c-ctrl-c))
-      (goto-char (point-min)) (org-ctrl-c-ctrl-c)
+  (let ((test-line "src_emacs-lisp[ :results silent ]{ \"x\" }"))
+    (org-test-with-temp-text
+	test-line
+      (org-ctrl-c-ctrl-c)
       (should (string= test-line
-		       (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
-    (let ((test-line " Some text prior to block src_emacs-lisp[ :results silent ]{ \"y\" }"))
+		       (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
+      (end-of-buffer)
+      (should-error (org-ctrl-c-ctrl-c))))
+  (let ((test-line " Some text prior to block src_emacs-lisp[ :results silent ]{ \"y\" }"))
+    (org-test-with-temp-text
+	test-line
       (goto-char (point-max))
       (insert (concat "\n" test-line " end"))
       (re-search-backward "src_") (org-ctrl-c-ctrl-c)
@@ -358,54 +355,48 @@
       (should (string= (concat test-line " end")
 		       (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
       (forward-char)
-      (should-error (org-ctrl-c-ctrl-c)))
-      ))
+      (should-error (org-ctrl-c-ctrl-c)))))
 
 (ert-deftest test-org-babel/inline-src_blk-results-raw ()
-  (with-temp-buffer
-
-    (let ((test-line "src_emacs-lisp[ :results raw ]{ \"x\" }"))
-      (insert test-line)
-      (goto-char (point-min)) (org-ctrl-c-ctrl-c)
+  (let ((test-line "src_emacs-lisp[ :results raw ]{ \"x\" }"))
+    (org-test-with-temp-text
+	test-line
+      (org-ctrl-c-ctrl-c)
       (should (string= (concat test-line " x")
-		       (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
-    (let ((test-line " Some text prior to block src_emacs-lisp[ :results raw ]{ \"the\" }"))
-      (goto-char (point-max))
-      (insert (concat "\n" test-line " end"))
-      (re-search-backward "src_") (org-ctrl-c-ctrl-c)
+		       (buffer-string)))))
+  (let ((test-line " Some text prior to block src_emacs-lisp[ :results raw ]{ \"the\" }"))
+    (org-test-with-temp-text
+	(concat test-line " end")
+      (re-search-forward "src_") (org-ctrl-c-ctrl-c)
       (should (string= (concat test-line " the end")
 		       (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
       (re-search-forward "\" ") (org-ctrl-c-ctrl-c)
       (should (string= (concat test-line " the the end")
 		       (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
       (forward-char)
-      (should-error (org-ctrl-c-ctrl-c)))
-      ))
+      (should-error (org-ctrl-c-ctrl-c)))))
 
 (ert-deftest test-org-babel/inline-src_blk-results-file ()
-  (with-temp-buffer
-
-    (let ((test-line "src_emacs-lisp[ :results file ]{ \"~/test-file\"  }"))
-      (insert test-line)
-      (goto-char (point-min)) (org-ctrl-c-ctrl-c)
+  (let ((test-line "src_emacs-lisp[ :results file ]{ \"~/test-file\"  }"))
+    (org-test-with-temp-text
+	test-line
+      (org-ctrl-c-ctrl-c)
       (should (string= (concat test-line " [[file:~/test-file]]")
 		       (buffer-substring-no-properties (point-min) (point-max)))))))
 
 (ert-deftest test-org-babel/inline-src_blk-results-scalar ()
-  (with-temp-buffer
-
-    (let ((test-line "src_emacs-lisp[ :results scalar ]{ \"x\"  }"))
-      (insert test-line)
-      (goto-char (point-min)) (org-ctrl-c-ctrl-c)
+  (let ((test-line "src_emacs-lisp[ :results scalar ]{ \"x\"  }"))
+    (org-test-with-temp-text
+	test-line
+      (org-ctrl-c-ctrl-c)
       (should (string= (concat test-line  " =\"x\"=")
 		       (buffer-substring-no-properties (point-min) (point-max)))))))
 
 (ert-deftest test-org-babel/inline-src_blk-results-verbatim ()
-  (with-temp-buffer
-
-    (let ((test-line "src_emacs-lisp[ :results verbatim ]{ \"x\"  }"))
-      (insert test-line)
-      (goto-char (point-min)) (org-ctrl-c-ctrl-c)
+  (let ((test-line "src_emacs-lisp[ :results verbatim ]{ \"x\"  }"))
+    (org-test-with-temp-text
+	test-line
+      (org-ctrl-c-ctrl-c)
       (should (string= (concat test-line " =\"x\"=")
 		       (buffer-substring-no-properties (point-min) (point-max)))))))
 
-- 
1.7.3.4


[-- Attachment #3: Type: text/plain, Size: 160 bytes --]

 
---
Org-mode version 7.7 (release_7.7.310.g4fbe)
GNU Emacs 24.0.50.1 (x86_64-apple-darwin, NS apple-appkit-1038.35)
 of 2011-08-21 on virtualmac.porkrind.org

  reply	other threads:[~2011-09-21  4:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-19 11:20 [babel] Trying to add ERT test cases Sebastien Vauban
2011-09-19 14:35 ` Eric Schulte
2011-09-19 19:35   ` Sebastien Vauban
2011-09-19 21:32     ` Eric Schulte
2011-09-20  7:22       ` Sebastien Vauban
2011-09-19 15:46 ` Martyn Jago
2011-09-19 16:04   ` Eric Schulte
2011-09-20  8:03     ` Martyn Jago
2011-09-20 15:01       ` Eric Schulte
2011-09-21  4:18         ` Martyn Jago [this message]
2011-09-21 12:20           ` Eric Schulte
2011-09-19 19:43   ` Sebastien Vauban

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=m2y5xiil3k.fsf@btinternet.com \
    --to=martyn.jago@btinternet.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.