emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] [babel] Trying to add ERT test cases


From: Sebastien Vauban
Subject: Re: [O] [babel] Trying to add ERT test cases
Date: Mon, 19 Sep 2011 21:35:11 +0200
User-agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.50 (windows-nt)

Hi Eric,

Eric Schulte wrote:
> "Sebastien Vauban" <address@hidden> 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]