From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thibault Marin Subject: Re: ob-lua Date: Sat, 20 Aug 2016 23:47:16 -0500 Message-ID: <87eg5ik9t7.fsf@dell-desktop.WORKGROUP> References: <87bn0of273.fsf@dell-desktop.WORKGROUP> <87h9af1la2.fsf@saiph.selenimh> Reply-To: thibault.marin@gmx.com Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:41705) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bbKfN-0008HT-SQ for emacs-orgmode@gnu.org; Sun, 21 Aug 2016 00:47:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bbKfJ-0005P3-Qe for emacs-orgmode@gnu.org; Sun, 21 Aug 2016 00:47:24 -0400 Received: from mout.gmx.net ([212.227.15.18]:58464) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bbKfJ-0005Oz-Fn for emacs-orgmode@gnu.org; Sun, 21 Aug 2016 00:47:21 -0400 In-reply-to: <87h9af1la2.fsf@saiph.selenimh> 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" To: Nicolas Goaziou Cc: "emacs-orgmode@gnu.org" --=-=-= Content-Type: text/plain >> There may be a better way to do it, but it seems to work. > > In this case, `org-babel-get-header' should be replaced with > `org-babel--get-vars', per ORG-NEWS. Thanks, it is much better. >> So my question is: could this be considered for a merge? The code does >> not seem to support sessions, I am not sure if that should be >> a blocker. > > It isn't a blocker, indeed. Could you send an updated patch? A set of > tests would be nice, too. I have updated the patch to use `org-babel--get-vars' as suggested. I also have replaced `org-babel-trim' by `org-trim' (as advised in ORG-NEWS) and replaced the `case' statement by a `pcase' (I used ob-python.el for reference). Please let me know if these changes are acceptable and if other changes are required. About the test, I am attaching my first attempt at this, please let me know if you have some advice on how to improve it or if you had something else in mind. This is the first time I use ert or org-test, but these seem to pass and test the basic features. By the way, when trying to run the tests from emacs, I had an error message when doing a (require 'org-test): "let: Required feature `ert-x' was not provided". Am I doing something wrong? I worked around it by (1) installing the `ertx' package and (2) replacing (require 'ert-x) by (require 'ertx) in org-test.el (that's probably the wrong thing to do, but it allowed me to run my tests). Thanks for your help. thibault --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=test-ob-lua.el Content-Transfer-Encoding: quoted-printable ;;; test-ob-lua.el --- tests for ob-lua.el ;; Copyright (c) 2011-2014 Eric Schulte ;; Authors: Eric Schulte ;; This file is not part of GNU Emacs. ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Code: (unless (featurep 'ob-lua) (signal 'missing-test-dependency "Support for Lua code blocks")) (ert-deftest test-ob-lua/simple-value () (org-test-with-temp-text "#+name: eg | a | 1 | | b | 2 | #+header: :results value #+header: :var x =3D eg #+begin_src lua return x['b'] #+end_src" (org-babel-next-src-block) (should (equal 2 (org-babel-execute-src-block))))) (ert-deftest test-ob-lua/simple-output () (org-test-with-temp-text "#+name: eg | a | 1 | | b | 2 | #+header: :results output #+header: :var x =3D eg #+begin_src lua print('result: ' .. string.format('%d', x['a'])) #+end_src" (org-babel-next-src-block) (should (equal "result: 1\n" (org-babel-execute-src-block))))) (ert-deftest test-ob-lua/colnames-yes-header-argument () (org-test-with-temp-text "#+name: eg | col | |-----| | a | | b | #+header: :colnames yes #+header: :var x =3D eg #+begin_src lua return x[1] #+end_src" (org-babel-next-src-block) (should (equal "a" (org-babel-execute-src-block))))) (ert-deftest test-ob-lua/colnames-yes-header-argument-pp () (org-test-with-temp-text "#+name: eg | col | val | |-----+-----| | a | 12 | | b | 13 | #+header: :results value pp #+header: :colnames yes #+header: :var x =3D eg #+begin_src lua return x #+end_src" (org-babel-next-src-block) (should (equal "a =3D 12\nb =3D 13\n" (org-babel-execute-src-block))))) (ert-deftest test-ob-lua/colnames-nil-header-argument () (org-test-with-temp-text "#+name: eg | col | |-----| | a | | b | #+header: :colnames nil #+header: :var x =3D eg #+header: :results value pp #+begin_src lua return x #+end_src" (org-babel-next-src-block) (should (equal "1 =3D a\n2 =3D b\n" (org-babel-execute-src-block))))) (ert-deftest test-ob-lua/colnames-no-header-argument () (org-test-with-temp-text "#+name: eg | col | |-----| | a | | b | #+header: :colnames no #+header: :var x =3D eg #+header: :results value pp #+begin_src lua return x #+end_src" (org-babel-next-src-block) (should (equal "1 =3D col\n2 =3D a\n3 =3D b\n" (org-babel-execute-src-b= lock))))) (provide 'test-ob-lua) ;;; test-ob-lua.el ends here --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=ob-lua.el.patch 132c132 < (mapcar #'cdr (org-babel-get-header params :var)))) --- > (org-babel--get-vars params))) 292,312c292,312 < (case result-type < (output (org-babel-eval org-babel-lua-command < (concat (if preamble (concat preamble "\n")) < body))) < (value (let ((tmp-file (org-babel-temp-file "lua-"))) < (org-babel-eval < org-babel-lua-command < (concat < (if preamble (concat preamble "\n") "") < (format < (if (member "pp" result-params) < org-babel-lua-pp-wrapper-method < org-babel-lua-wrapper-method) < (mapconcat < (lambda (line) (format "\t%s" line)) < (split-string < (org-remove-indentation < (org-babel-trim body)) < "[\r\n]") "\n") < (org-babel-process-file-name tmp-file 'noquote)))) < (org-babel-eval-read-file tmp-file)))))) --- > (pcase result-type > (`output (org-babel-eval org-babel-lua-command > (concat (if preamble (concat preamble "\n")) > body))) > (`value (let ((tmp-file (org-babel-temp-file "lua-"))) > (org-babel-eval > org-babel-lua-command > (concat > (if preamble (concat preamble "\n") "") > (format > (if (member "pp" result-params) > org-babel-lua-pp-wrapper-method > org-babel-lua-wrapper-method) > (mapconcat > (lambda (line) (format "\t%s" line)) > (split-string > (org-remove-indentation > (org-trim body)) > "[\r\n]") "\n") > (org-babel-process-file-name tmp-file 'noquote)))) > (org-babel-eval-read-file tmp-file)))))) 315c315 < (org-babel-lua-table-or-string (org-babel-trim raw))))) --- > (org-babel-lua-table-or-string (org-trim raw))))) 369c369 < #'org-babel-trim --- > #'org-trim --=-=-=--