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 15:32:07 -0600 Message-ID: <87litkte08.fsf@gmail.com> References: <80sjnswzh5.fsf@somewhere.org> <87ty88vad1.fsf@gmail.com> <80ehzcwck0.fsf@somewhere.org> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([140.186.70.92]:38739) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R5lRo-0000EV-2G for emacs-orgmode@gnu.org; Mon, 19 Sep 2011 17:32:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R5lRm-0003pq-Ih for emacs-orgmode@gnu.org; Mon, 19 Sep 2011 17:32:16 -0400 Received: from mail-gw0-f48.google.com ([74.125.83.48]:61289) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R5lRm-0003pm-BF for emacs-orgmode@gnu.org; Mon, 19 Sep 2011 17:32:14 -0400 Received: by gwj22 with SMTP id 22so5779010gwj.35 for ; Mon, 19 Sep 2011 14:32:13 -0700 (PDT) In-Reply-To: <80ehzcwck0.fsf@somewhere.org> (Sebastien Vauban's message of "Mon, 19 Sep 2011 21:35:11 +0200") 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 > * 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/