all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [babel] Trying to add ERT test cases
@ 2011-09-19 11:20 Sebastien Vauban
  2011-09-19 14:35 ` Eric Schulte
  2011-09-19 15:46 ` Martyn Jago
  0 siblings, 2 replies; 12+ messages in thread
From: Sebastien Vauban @ 2011-09-19 11:20 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi,

I'd like to really contrib more on test cases, in particular every time I'd
see something problematic. My goal (SOMEDAY/MAYBE) would be to (be able to)
report any problem with an attached ERT test case...

Last experience: for some unknown reason (maybe a Lisp nesting exceeded,
though), it (rarely) happens that the speed commands don't work anymore. I'd
like to test (ultimately all speed commans) against such a behavior.

Hence:

* Speed command (this must be at level-1 headline)
  :PROPERTIES:
  :ID:       4ee368b8-cf7c-4269-98c0-b28dcf94ff2b
  :END:

Some text.

* Test

#+begin_src emacs-lisp
(ert-deftest ob-tangle/speed-command-r ()
  "Test that speed command `r' does demote the headline."
  (org-test-at-id "4ee368b8-cf7c-4269-98c0-b28dcf94ff2b"
    (goto-char (point-at-bol))
    (insert "r") ;; I don't want a self-insert of r, but the effect of typing it
    (goto-char (point-at-bol))
    (should (looking-at "\\*\\* Speed command"))
    (delete-char 1)))
#+end_src

Problems:

- I want to simulate the user pressing `r', but `insert' does insert a literal
  `r', instead of executing what's associated to it.

  Of course, I don't want to replace the key press on `r' but a call to
  `org-shiftright', that's the whole point of the test.

  So, how can I insert a `r' character to be contextually interpreted?

- when `should' is failing, the `delete-char' does not take place. This is
  still mysterious to me, at this point in time.

Any hints for me to go further?

Best regards,
  Seb

-- 
Sebastien Vauban

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [babel] Trying to add ERT test cases
  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 15:46 ` Martyn Jago
  1 sibling, 1 reply; 12+ messages in thread
From: Eric Schulte @ 2011-09-19 14:35 UTC (permalink / raw)
  To: Sebastien Vauban; +Cc: emacs-orgmode

"Sebastien Vauban" <wxhgmqzgwmuf@spammotel.com> writes:

> Hi,
>
> I'd like to really contrib more on test cases, in particular every time I'd
> see something problematic. My goal (SOMEDAY/MAYBE) would be to (be able to)
> report any problem with an attached ERT test case...
>

That would certainly be the ideal for a bug report.

>
> Last experience: for some unknown reason (maybe a Lisp nesting exceeded,
> though), it (rarely) happens that the speed commands don't work anymore. I'd
> like to test (ultimately all speed commans) against such a behavior.
>
> Hence:
>
> * Speed command (this must be at level-1 headline)
>   :PROPERTIES:
>   :ID:       4ee368b8-cf7c-4269-98c0-b28dcf94ff2b
>   :END:
>
> Some text.
>
> * Test
>
> #+begin_src emacs-lisp
> (ert-deftest ob-tangle/speed-command-r ()
>   "Test that speed command `r' does demote the headline."
>   (org-test-at-id "4ee368b8-cf7c-4269-98c0-b28dcf94ff2b"
>     (goto-char (point-at-bol))
>     (insert "r") ;; I don't want a self-insert of r, but the effect of typing it
>     (goto-char (point-at-bol))
>     (should (looking-at "\\*\\* Speed command"))
>     (delete-char 1)))
> #+end_src
>
> Problems:
>
> - I want to simulate the user pressing `r', but `insert' does insert a literal
>   `r', instead of executing what's associated to it.
>
>   Of course, I don't want to replace the key press on `r' but a call to
>   `org-shiftright', that's the whole point of the test.
>
>   So, how can I insert a `r' character to be contextually interpreted?
>

The best way to find out what is happening when you press a key (or key
chord) in Emacs is with the `describe-key-briefly' command bound to "C-h
c".  Using this in an Org-mode buffer I see that the key "r" is bound to
`org-self-insert-command'.

>
> - when `should' is failing, the `delete-char' does not take place. This is
>   still mysterious to me, at this point in time.
>

I suppose ERT aborts a test when the first should form fails.  Many
testing frameworks have a way of defining "fixtures" which serve as test
wrappers...

Hoping to find an ERT tutorial I googled "ert tutorial emacs test" and
the first page was [1], which we should probably update to reflect the
actual test framework.  The info page on ERT does look to be informative
and may specify how to ensure that "cleanup" code is run -- although in
general it may be a better idea to simply run tests in a temporary
buffer `with-temp-buffer' so no cleanup is required.

Hope this helps.  Best -- Eric

>
> Any hints for me to go further?
>
> Best regards,
>   Seb

Footnotes: 
[1]  http://orgmode.org/worg/org-tests/index.html

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [babel] Trying to add ERT test cases
  2011-09-19 11:20 [babel] Trying to add ERT test cases Sebastien Vauban
  2011-09-19 14:35 ` Eric Schulte
@ 2011-09-19 15:46 ` Martyn Jago
  2011-09-19 16:04   ` Eric Schulte
  2011-09-19 19:43   ` Sebastien Vauban
  1 sibling, 2 replies; 12+ messages in thread
From: Martyn Jago @ 2011-09-19 15:46 UTC (permalink / raw)
  To: emacs-orgmode

Hi Sebastien

"Sebastien Vauban"
<wxhgmqzgwmuf@spammotel.com> writes:

> Hi,
>
> I'd like to really contrib more on test cases, in particular every time I'd
> see something problematic. My goal (SOMEDAY/MAYBE) would be to (be able to)
> report any problem with an attached ERT test case...
>
> Last experience: for some unknown reason (maybe a Lisp nesting exceeded,
> though), it (rarely) happens that the speed commands don't work anymore. I'd
> like to test (ultimately all speed commans) against such a behavior.
>
> Hence:
>
> * Speed command (this must be at level-1 headline)
>   :PROPERTIES:
>   :ID:       4ee368b8-cf7c-4269-98c0-b28dcf94ff2b
>   :END:
>
> Some text.
>
> * Test
>
> #+begin_src emacs-lisp
> (ert-deftest ob-tangle/speed-command-r ()
>   "Test that speed command `r' does demote the headline."
>   (org-test-at-id "4ee368b8-cf7c-4269-98c0-b28dcf94ff2b"
>     (goto-char (point-at-bol))
>     (insert "r") ;; I don't want a self-insert of r, but the effect of typing it
>     (goto-char (point-at-bol))
>     (should (looking-at "\\*\\* Speed command"))
>     (delete-char 1)))
> #+end_src
>
> Problems:
>
> - I want to simulate the user pressing `r', but `insert' does insert a literal
>   `r', instead of executing what's associated to it.
>
>   Of course, I don't want to replace the key press on `r' but a call to
>   `org-shiftright', that's the whole point of the test.
>
>   So, how can I insert a `r' character to be contextually interpreted?
>
> - when `should' is failing, the `delete-char' does not take place. This is
>   still mysterious to me, at this point in time.
>
> Any hints for me to go further?
>
> Best regards,
>   Seb

My solution doesn't simulate pressing `r' as such (which looks like it
will require some substantial setup), so I approached the test slightly
differently...

 - 1) Ensure =org-speed-command-default-hook= returns t when valid
       (default) speed command and bol
 - 2) Ensure actual speed command promotes correctly
 - 3) Use a test-buffer (with org-mode enabled) to avoid messing with
       test example

There may be a better solution however.

Best, Martyn

--8<---------------cut here---------------start------------->8---
(ert-deftest ob-tangle/speed-command-r ()
  (let ((org-use-speed-commands t))
    (with-temp-buffer
      (org-mode)
      (insert "* Speed command")
      (goto-char (point-at-bol))
      ;; ensure default speed commands return t
      (should (org-speed-command-default-hook "r"))
      (should (org-speed-command-default-hook "n"))

      ;; ensure non-default speed commands return nil
      (should-not (org-speed-command-default-hook "z"))

      ;; ensure default speed commands return nil if not at bol
      (forward-char)
      (should-not (org-speed-command-default-hook "r"))

      ;; ensure org-metaright promotes heading
      (goto-char (point-at-bol))
      (org-metaright 1)
      (goto-char (point-at-bol))
      (should (equal "** Speed command" (buffer-string)))
      ;; ensure org-metaleft demotes heading
      (org-metaleft 1)
      (should (equal "* Speed command" (buffer-string))))))
--8<---------------cut here---------------end--------------->8---

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [babel] Trying to add ERT test cases
  2011-09-19 15:46 ` Martyn Jago
@ 2011-09-19 16:04   ` Eric Schulte
  2011-09-20  8:03     ` Martyn Jago
  2011-09-19 19:43   ` Sebastien Vauban
  1 sibling, 1 reply; 12+ messages in thread
From: Eric Schulte @ 2011-09-19 16:04 UTC (permalink / raw)
  To: Martyn Jago; +Cc: emacs-orgmode

Martyn Jago <martyn.jago@btinternet.com> writes:
[...]
>
> (ert-deftest ob-tangle/speed-command-r ()
>   (let ((org-use-speed-commands t))
>     (with-temp-buffer
>       (org-mode)
>       (insert "* Speed command")
>       (goto-char (point-at-bol))
>       ;; ensure default speed commands return t
>       (should (org-speed-command-default-hook "r"))
>       (should (org-speed-command-default-hook "n"))
>
>       ;; ensure non-default speed commands return nil
>       (should-not (org-speed-command-default-hook "z"))
>
>       ;; ensure default speed commands return nil if not at bol
>       (forward-char)
>       (should-not (org-speed-command-default-hook "r"))
>
>       ;; ensure org-metaright promotes heading
>       (goto-char (point-at-bol))
>       (org-metaright 1)
>       (goto-char (point-at-bol))
>       (should (equal "** Speed command" (buffer-string)))
>       ;; ensure org-metaleft demotes heading
>       (org-metaleft 1)
>       (should (equal "* Speed command" (buffer-string))))))

As a minor note, I just added a simple convenience macro named
`org-test-with-temp-text' [1] which should somewhat simplify the process
of using temporary Org-mode buffers with initial text.  Using this the
above becomes

#+begin_src emacs-lisp
  (ert-deftest ob-tangle/speed-command-r ()
    (let ((org-use-speed-commands t))
      (org-test-with-temp-text "* Speed command"
        ;; ensure default speed commands return t
        (should (org-speed-command-default-hook "r"))
        (should (org-speed-command-default-hook "n"))
  
        ;; ensure non-default speed commands return nil
        (should-not (org-speed-command-default-hook "z"))
  
        ;; ensure default speed commands return nil if not at bol
        (forward-char)
        (should-not (org-speed-command-default-hook "r"))
  
        ;; ensure org-metaright promotes heading
        (goto-char (point-at-bol))
        (org-metaright 1)
        (goto-char (point-at-bol))
        (should (equal "** Speed command" (buffer-string)))
        ;; ensure org-metaleft demotes heading
        (org-metaleft 1)
        (should (equal "* Speed command" (buffer-string))))))
#+end_src

Cheers -- Eric


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.
`----


-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [babel] Trying to add ERT test cases
  2011-09-19 14:35 ` Eric Schulte
@ 2011-09-19 19:35   ` Sebastien Vauban
  2011-09-19 21:32     ` Eric Schulte
  0 siblings, 1 reply; 12+ messages in thread
From: Sebastien Vauban @ 2011-09-19 19:35 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Eric,

Eric Schulte wrote:
> "Sebastien Vauban" <wxhgmqzgwmuf-geNee64TY+gS+FvcfC7Uqw@public.gmane.org> writes:
>>
>> * Test
>>
>> #+begin_src emacs-lisp
>> (ert-deftest ob-tangle/speed-command-r ()
>>   "Test that speed command `r' does demote the headline."
>>   (org-test-at-id "4ee368b8-cf7c-4269-98c0-b28dcf94ff2b"
>>     (goto-char (point-at-bol))
>>     (insert "r") ;; I don't want a self-insert of r, but the effect of typing it
>>     (goto-char (point-at-bol))
>>     (should (looking-at "\\*\\* Speed command"))
>>     (delete-char 1)))
>> #+end_src
>>
>> Problems:
>>
>> - I want to simulate the user pressing `r', but `insert' does insert a literal
>>   `r', instead of executing what's associated to it.
>>
>>   Of course, I don't want to replace the key press on `r' but a call to
>>   `org-shiftright', that's the whole point of the test.
>>
>>   So, how can I insert a `r' character to be contextually interpreted?
>
> The best way to find out what is happening when you press a key (or key
> chord) in Emacs is with the `describe-key-briefly' command bound to "C-h
> c".  Using this in an Org-mode buffer I see that the key "r" is bound to
> `org-self-insert-command'.

OK, so I just rewrote my test file like this:

--8<---------------cut here---------------start------------->8---
* Speed command (this must be at level-1 headline)
  :PROPERTIES:
  :ID:       4ee368b8-cf7c-4269-98c0-b28dcf94ff2b
  :END:

Some text.

* Test

#+begin_src emacs-lisp
(ert-deftest ob-tangle/speed-command-r ()
  "Test that speed command `r' does demote the headline."
  (org-test-at-id "4ee368b8-cf7c-4269-98c0-b28dcf94ff2b"
    (goto-char (point-at-bol))
    (org-self-insert-command ?r)
    (goto-char (point-at-bol))
    (should (looking-at "\\*\\* Speed command"))
    (delete-char 1)))
#+end_src
--8<---------------cut here---------------end--------------->8---

When running the test _once_, I get my level-1 headline preceded by 114
occurrences of ^M (yes, 114 for 1 test run!):

^M^M^M...^M^M^M* Speed command (this must be at level-1 headline)

and no demotion of my headline.

Do you understand such?  The above should have been working, if I read you
correctly.


>> - when `should' is failing, the `delete-char' does not take place. This is
>>   still mysterious to me, at this point in time.
>
> I suppose ERT aborts a test when the first should form fails.

I now do think you're right: an error is an error, hence the test is aborting.
My cleanup is then useless in such a case.

> Many testing frameworks have a way of defining "fixtures" which serve as
> test wrappers...
>
> Hoping to find an ERT tutorial I googled "ert tutorial emacs test" and
> the first page was [1], which we should probably update to reflect the
> actual test framework.  The info page on ERT does look to be informative
> and may specify how to ensure that "cleanup" code is run -- although in
> general it may be a better idea to simply run tests in a temporary
> buffer `with-temp-buffer' so no cleanup is required.

... which means, I indeed should use a temp buffer. Thanks for the hint.

I read thru the page you link to. Just a minor thing: link to "See
ert-publish-test.el for the implementation" is broken.

Do you have a solution for checking against internal broken links?  I still
have my idea of letting DOT draw an graph of the interconnection between
pages, so that we see missing pages, and unreachable ones (files on the file
system, but never linked). I should (find the time to) extend it enough to
serve that purpose.

Best regards,
  Seb

-- 
Sebastien Vauban

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [babel] Trying to add ERT test cases
  2011-09-19 15:46 ` Martyn Jago
  2011-09-19 16:04   ` Eric Schulte
@ 2011-09-19 19:43   ` Sebastien Vauban
  1 sibling, 0 replies; 12+ messages in thread
From: Sebastien Vauban @ 2011-09-19 19:43 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Martyn,

Martyn Jago wrote:
> "Sebastien Vauban"
> <wxhgmqzgwmuf-geNee64TY+gS+FvcfC7Uqw@public.gmane.org> writes:
>
>> * Test
>>
>> #+begin_src emacs-lisp
>> (ert-deftest ob-tangle/speed-command-r ()
>>   "Test that speed command `r' does demote the headline."
>>   (org-test-at-id "4ee368b8-cf7c-4269-98c0-b28dcf94ff2b"
>>     (goto-char (point-at-bol))
>>     (insert "r") ;; I don't want a self-insert of r, but the effect of typing it
>>     (goto-char (point-at-bol))
>>     (should (looking-at "\\*\\* Speed command"))
>>     (delete-char 1)))
>> #+end_src
>>
>> Problems:
>>
>> - I want to simulate the user pressing `r', but `insert' does insert a literal
>>   `r', instead of executing what's associated to it.
>>
>>   Of course, I don't want to replace the key press on `r' but a call to
>>   `org-shiftright', that's the whole point of the test.
>>
>>   So, how can I insert a `r' character to be contextually interpreted?
>>
>> - when `should' is failing, the `delete-char' does not take place. This is
>>   still mysterious to me, at this point in time.
>>
>> Any hints for me to go further?
>
> My solution doesn't simulate pressing `r' as such (which looks like it
> will require some substantial setup), so I approached the test slightly
> differently...
>
>  - 1) Ensure =org-speed-command-default-hook= returns t when valid
>        (default) speed command and bol
>  - 2) Ensure actual speed command promotes correctly
>  - 3) Use a test-buffer (with org-mode enabled) to avoid messing with
>        test example
>
> There may be a better solution however.
>
> Best, Martyn
>
> (ert-deftest ob-tangle/speed-command-r ()
>   (let ((org-use-speed-commands t))
>     (with-temp-buffer
>       (org-mode)
>       (insert "* Speed command")
>       (goto-char (point-at-bol))
>       ;; ensure default speed commands return t
>       (should (org-speed-command-default-hook "r"))
>       (should (org-speed-command-default-hook "n"))
>
>       ;; ensure non-default speed commands return nil
>       (should-not (org-speed-command-default-hook "z"))
>
>       ;; ensure default speed commands return nil if not at bol
>       (forward-char)
>       (should-not (org-speed-command-default-hook "r"))
>
>       ;; ensure org-metaright promotes heading
>       (goto-char (point-at-bol))
>       (org-metaright 1)
>       (goto-char (point-at-bol))
>       (should (equal "** Speed command" (buffer-string)))
>       ;; ensure org-metaleft demotes heading
>       (org-metaleft 1)
>       (should (equal "* Speed command" (buffer-string))))))

Thanks a lot for teaching me such tricks.

However, I have the impression it's not entirely what I'd like to test for:
that the user pressing `r' makes the headline being demoted.

Here, if I understand you and the code correctly, you test that:

- `r', in the valid context, is a key bound to some speed command, but not
  especially the headline demotion;

- ...

- demotion and promotion do work, when called via their well-known command.

Of course, as you say, what I'm asking for is maybe just to complex to test.

And it does not remove anything from the need for the above test you just
wrote. Thanks a lot.

Best regards,
  Seb

-- 
Sebastien Vauban

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [babel] Trying to add ERT test cases
  2011-09-19 19:35   ` Sebastien Vauban
@ 2011-09-19 21:32     ` Eric Schulte
  2011-09-20  7:22       ` Sebastien Vauban
  0 siblings, 1 reply; 12+ messages in thread
From: Eric Schulte @ 2011-09-19 21:32 UTC (permalink / raw)
  To: Sebastien Vauban; +Cc: emacs-orgmode

> * Test
>
> #+begin_src emacs-lisp
> (ert-deftest ob-tangle/speed-command-r ()
>   "Test that speed command `r' does demote the headline."
>   (org-test-at-id "4ee368b8-cf7c-4269-98c0-b28dcf94ff2b"
>     (goto-char (point-at-bol))
>     (org-self-insert-command ?r)
>     (goto-char (point-at-bol))
>     (should (looking-at "\\*\\* Speed command"))
>     (delete-char 1)))
> #+end_src
>
> When running the test _once_, I get my level-1 headline preceded by 114
> occurrences of ^M (yes, 114 for 1 test run!):
>
> ^M^M^M...^M^M^M* Speed command (this must be at level-1 headline)
>
> and no demotion of my headline.
>
> Do you understand such?  The above should have been working, if I read you
> correctly.
>

So it looks like these self-insert-command functions are special cases.
They don't look to their arguments to see what key-press invoked them,
but rather they call the `this-command-keys' function for this purpose.
We can force the behavior we want by overriding the definition of this
function locally, taking this approach the following test case worked
for me

#+begin_src emacs-lisp
  (ert-deftest ob-tangle/speed-command-r ()
    "Test that speed command `r' does demote the headline."
    (org-test-with-temp-text "* Speed command"
      (flet ((this-command-keys () "r")) (org-self-insert-command ?r))
      (goto-char (point-min))
      (should (looking-at "\\*\\* Speed command"))))
#+end_src

>
>
>>> - when `should' is failing, the `delete-char' does not take place. This is
>>>   still mysterious to me, at this point in time.
>>
>> I suppose ERT aborts a test when the first should form fails.
>
> I now do think you're right: an error is an error, hence the test is aborting.
> My cleanup is then useless in such a case.
>
>> Many testing frameworks have a way of defining "fixtures" which serve as
>> test wrappers...
>>
>> Hoping to find an ERT tutorial I googled "ert tutorial emacs test" and
>> the first page was [1], which we should probably update to reflect the
>> actual test framework.  The info page on ERT does look to be informative
>> and may specify how to ensure that "cleanup" code is run -- although in
>> general it may be a better idea to simply run tests in a temporary
>> buffer `with-temp-buffer' so no cleanup is required.
>
> ... which means, I indeed should use a temp buffer. Thanks for the hint.
>
> I read thru the page you link to. Just a minor thing: link to "See
> ert-publish-test.el for the implementation" is broken.
>
> Do you have a solution for checking against internal broken links?

Nothing comes immediately to mind.

> I still have my idea of letting DOT draw an graph of the
> interconnection between pages, so that we see missing pages, and
> unreachable ones (files on the file system, but never linked). I
> should (find the time to) extend it enough to serve that purpose.
>

This could be useful, like a site map for worg.  As an intermediate step
I could see it being useful to simply print out all internal links whose
target does not exist on the file system.

Best -- Eric

>
> Best regards,
>   Seb

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [babel] Trying to add ERT test cases
  2011-09-19 21:32     ` Eric Schulte
@ 2011-09-20  7:22       ` Sebastien Vauban
  0 siblings, 0 replies; 12+ messages in thread
From: Sebastien Vauban @ 2011-09-20  7:22 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Eric,

Eric Schulte wrote:
>> * Test
>>
>> #+begin_src emacs-lisp
>> (ert-deftest ob-tangle/speed-command-r ()
>>   "Test that speed command `r' does demote the headline."
>>   (org-test-at-id "4ee368b8-cf7c-4269-98c0-b28dcf94ff2b"
>>     (goto-char (point-at-bol))
>>     (org-self-insert-command ?r)
>>     (goto-char (point-at-bol))
>>     (should (looking-at "\\*\\* Speed command"))
>>     (delete-char 1)))
>> #+end_src
>>
>> When running the test _once_, I get my level-1 headline preceded by 114
>> occurrences of ^M (yes, 114 for 1 test run!):
>>
>> ^M^M^M...^M^M^M* Speed command (this must be at level-1 headline)
>>
>> and no demotion of my headline.
>>
>> Do you understand such?
>
> So it looks like these self-insert-command functions are special cases.
> They don't look to their arguments to see what key-press invoked them,
> but rather they call the `this-command-keys' function for this purpose.
> We can force the behavior we want by overriding the definition of this
> function locally, taking this approach the following test case worked
> for me
>
> #+begin_src emacs-lisp
>   (ert-deftest ob-tangle/speed-command-r ()
>     "Test that speed command `r' does demote the headline."
>     (org-test-with-temp-text "* Speed command"
>       (flet ((this-command-keys () "r")) (org-self-insert-command ?r))
>       (goto-char (point-min))
>       (should (looking-at "\\*\\* Speed command"))))
> #+end_src

It passes!  So does:

#+begin_src emacs-lisp
  (ert-deftest ob-tangle/speed-command-r ()
    "Test that speed command `r' does demote the headline."
    (org-test-with-temp-text "* Speed command"
      (flet ((this-command-keys () "r")) (org-self-insert-command ?a))
      (goto-char (point-min))
      (should (looking-at "\\*\\* Speed command"))))
#+end_src

where the argument of `org-self-insert-command' is `a' (could be anything, it
seems). Very weird.

I just understood as well why I got 114 ^M: 114 is the ASCII code for `r', and
`\r' is as well ^M -- though `r' is not...

>> [...] I read thru the page you link to. Just a minor thing: link to "See
>> ert-publish-test.el for the implementation" is broken.
>>
>> Do you have a solution for checking against internal broken links?
>
> Nothing comes immediately to mind.
>
>> I still have my idea of letting DOT draw an graph of the
>> interconnection between pages, so that we see missing pages, and
>> unreachable ones (files on the file system, but never linked). I
>> should (find the time to) extend it enough to serve that purpose.
>
> This could be useful, like a site map for worg.  As an intermediate step
> I could see it being useful to simply print out all internal links whose
> target does not exist on the file system.

I'll try to come up with something (in Babel) soon.

Best regards,
  Seb

-- 
Sebastien Vauban

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [babel] Trying to add ERT test cases
  2011-09-19 16:04   ` Eric Schulte
@ 2011-09-20  8:03     ` Martyn Jago
  2011-09-20 15:01       ` Eric Schulte
  0 siblings, 1 reply; 12+ messages in thread
From: Martyn Jago @ 2011-09-20  8:03 UTC (permalink / raw)
  To: emacs-orgmode

Hi Eric 

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

> Martyn Jago <martyn.jago@btinternet.com> writes:
> [...]
>>
>> (ert-deftest ob-tangle/speed-command-r ()
>>   (let ((org-use-speed-commands t))
>>     (with-temp-buffer
>>       (org-mode)
>>       (insert "* Speed command")
>>       (goto-char (point-at-bol))
>>       ;; ensure default speed commands return t
>>       (should (org-speed-command-default-hook "r"))
>>       (should (org-speed-command-default-hook "n"))
>>
>>       ;; ensure non-default speed commands return nil
>>       (should-not (org-speed-command-default-hook "z"))
>>
>>       ;; ensure default speed commands return nil if not at bol
>>       (forward-char)
>>       (should-not (org-speed-command-default-hook "r"))
>>
>>       ;; ensure org-metaright promotes heading
>>       (goto-char (point-at-bol))
>>       (org-metaright 1)
>>       (goto-char (point-at-bol))
>>       (should (equal "** Speed command" (buffer-string)))
>>       ;; ensure org-metaleft demotes heading
>>       (org-metaleft 1)
>>       (should (equal "* Speed command" (buffer-string))))))
>
> As a minor note, I just added a simple convenience macro named
> `org-test-with-temp-text' [1] which should somewhat simplify the process
> of using temporary Org-mode buffers with initial text.  Using this the
> above becomes
>
> #+begin_src emacs-lisp
>   (ert-deftest ob-tangle/speed-command-r ()
>     (let ((org-use-speed-commands t))
>       (org-test-with-temp-text "* Speed command"
>         ;; ensure default speed commands return t
>         (should (org-speed-command-default-hook "r"))
>         (should (org-speed-command-default-hook "n"))
>   
>         ;; ensure non-default speed commands return nil
>         (should-not (org-speed-command-default-hook "z"))
>   
>         ;; ensure default speed commands return nil if not at bol
>         (forward-char)
>         (should-not (org-speed-command-default-hook "r"))
>   
>         ;; ensure org-metaright promotes heading
>         (goto-char (point-at-bol))
>         (org-metaright 1)
>         (goto-char (point-at-bol))
>         (should (equal "** Speed command" (buffer-string)))
>         ;; ensure org-metaleft demotes heading
>         (org-metaleft 1)
>         (should (equal "* Speed command" (buffer-string))))))
> #+end_src
>
> Cheers -- Eric
>
>
> 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? 

Regards

Martyn

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [babel] Trying to add ERT test cases
  2011-09-20  8:03     ` Martyn Jago
@ 2011-09-20 15:01       ` Eric Schulte
  2011-09-21  4:18         ` Martyn Jago
  0 siblings, 1 reply; 12+ messages in thread
From: Eric Schulte @ 2011-09-20 15:01 UTC (permalink / raw)
  To: Martyn Jago; +Cc: emacs-orgmode

>>
>> 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

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [babel] Trying to add ERT test cases
  2011-09-20 15:01       ` Eric Schulte
@ 2011-09-21  4:18         ` Martyn Jago
  2011-09-21 12:20           ` Eric Schulte
  0 siblings, 1 reply; 12+ messages in thread
From: Martyn Jago @ 2011-09-21  4:18 UTC (permalink / raw)
  To: emacs-orgmode

[-- 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

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [babel] Trying to add ERT test cases
  2011-09-21  4:18         ` Martyn Jago
@ 2011-09-21 12:20           ` Eric Schulte
  0 siblings, 0 replies; 12+ messages in thread
From: Eric Schulte @ 2011-09-21 12:20 UTC (permalink / raw)
  To: Martyn Jago; +Cc: emacs-orgmode

Martyn Jago <martyn.jago@btinternet.com> writes:

> 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.
>

Applied, Much Thanks -- Eric

>
> Best, Martyn
>
> 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)))))))

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2011-09-21 15:12 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2011-09-21 12:20           ` Eric Schulte
2011-09-19 19:43   ` Sebastien Vauban

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.