From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Davison Subject: Re: [babel] Babel as a test harness? Date: Fri, 19 Mar 2010 20:45:02 -0400 Message-ID: <874okblt2p.fsf@stats.ox.ac.uk> References: <211769421003191643l2d00b8cai63028b369408552f@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NsmoX-0007ad-7b for emacs-orgmode@gnu.org; Fri, 19 Mar 2010 20:45:17 -0400 Received: from [140.186.70.92] (port=50390 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NsmoV-0007Zc-9D for emacs-orgmode@gnu.org; Fri, 19 Mar 2010 20:45:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NsmoR-00085D-PB for emacs-orgmode@gnu.org; Fri, 19 Mar 2010 20:45:13 -0400 Received: from markov.stats.ox.ac.uk ([163.1.210.1]:50169) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NsmoQ-000851-Qq for emacs-orgmode@gnu.org; Fri, 19 Mar 2010 20:45:11 -0400 In-Reply-To: <211769421003191643l2d00b8cai63028b369408552f@mail.gmail.com> (Nathan Neff's message of "Fri, 19 Mar 2010 18:43:35 -0500") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Nathan Neff Cc: emacs-orgmode@gnu.org Nathan Neff writes: > I think it would be cool to use Org-babel as a simple test harness. > > I'd like to have an org file, with various sections that demonstrate how = to do > something in Groovy.=C2=A0 I'd like to be able to run all the code in the= org file > and make sure > they all run successfully (return code 0). > > In Groovy, the "assert" function will exit with a non-zero code if it fai= ls.=C2=A0 > How > would I use org-babel to generate a "summary" table with the name of > each patch of code and whether or not it succeeded? Like below? This is all Eric's doing. For quite a while now org-babel has used a table like this to validate itself. It took me a while to understand it, but basically Eric designed a special function (actually, a macro) called sbe (source block evaluate) to be used in table formulas to call org-babel source blocks. Use C-u C-c C-c to update the table. * Tests | functionality | block | arg | expected | results | p= ass | |----------------+--------------+-----+----------+----------------------+--= ------------------------------------------| | simple regexp | simple_regex | | | | p= ass | | regexp with or | regex_or | | | A pretend problem... | e= xpected "" but was "A pretend problem..." | #+TBLFM: $5=3D'(if (=3D (length $3) 1) (sbe $2 (n $3)) (sbe $2)) :: $6=3D'(= if (string=3D $4 $5) "pass" (format "expected %S but was %S" $4 $5)) * Code blocks for tests ** Here's how to match "foo" #+source: simple_regex #+begin_src groovy assert "foo" =3D~ /foo/ #+end_src ** Here's how to match "bar" or "baz" #+source: regex_or #+begin_src groovy assert "bar" =3D~ "ba(z|r)" println "A pretend problem" #+end_src You can put any arguments to your source blocks in the arg column. See http://orgmode.org/worg/org-contrib/babel/intro.php#spreadsheet (It often makes most sense to clone Worg and view the org files themseleves) And for a more complex example, including how to pass arguments to source blocks to sbe, see our full test suite in the file development.org in the devel repo http://github.com/eschulte/babel-dev/ Dan p.s. groovy seems to be funny about hyphens in the input file name. I think you want to apply this: diff --git a/contrib/babel/lisp/langs/org-babel-groovy.el b/contrib/babel/l= isp/langs/org-babel-groovy.el index 02b3272..d6a28a7 100644 --- a/contrib/babel/lisp/langs/org-babel-groovy.el +++ b/contrib/babel/lisp/langs/org-babel-groovy.el @@ -88,7 +88,7 @@ print o join(\"\\n\", @r), \"\\n\"") (defun org-babel-groovy-evaluate (session body &optional result-type) "Evaluate Groovy code in BODY" ;; external process evaluation - (let ((infile (make-temp-file "org_babel_groovy_input_"))) + (let ((infile (replace-regexp-in-string "-" "_" (make-temp-file "org_bab= el_groovy_input_")))) (save-excursion (with-temp-buffer (with-temp-file infile (insert body)) > > Something like this would be cool: > > * Regular Expressions > ** Here's how to match "foo" > > #+source simple_regex > #+begin_src groovy > assert "foo" =3D~ /foo/ > #+end_src > > ** Here's how to match "bar" or "baz" > #+source regex_or > #+begin_src groovy > assert "bar" =3D~ "ba(z|r)" > #+end_src > > * Results: > | simple_regex | success | > | regex_or=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | success | > > _______________________________________________ > Emacs-orgmode mailing list > Please use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode