From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: [babel] Trying to add ERT test cases Date: Mon, 19 Sep 2011 08:35:51 -0600 Message-ID: <87ty88vad1.fsf@gmail.com> References: <80sjnswzh5.fsf@somewhere.org> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([140.186.70.92]:59704) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R5fS4-0003UK-Ez for emacs-orgmode@gnu.org; Mon, 19 Sep 2011 11:08:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R5fRy-0000eF-Ex for emacs-orgmode@gnu.org; Mon, 19 Sep 2011 11:08:08 -0400 Received: from mail-gx0-f169.google.com ([209.85.161.169]:36090) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R5fRy-0000e9-94 for emacs-orgmode@gnu.org; Mon, 19 Sep 2011 11:08:02 -0400 Received: by gxk2 with SMTP id 2so693693gxk.0 for ; Mon, 19 Sep 2011 08:08:01 -0700 (PDT) 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: Sebastien Vauban Cc: emacs-orgmode@gnu.org "Sebastien Vauban" 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/