emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Pascal Fleury <fleury@google.com>
To: Alan Schmitt <alan.schmitt@polytechnique.org>
Cc: Achim Gratz <Stromeko@nexgo.de>, emacs-org list <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] ob-shell
Date: Fri, 22 Aug 2014 15:08:35 +0200	[thread overview]
Message-ID: <CACc7+8bZkBCdWOfxLSbJ0fyxMkDaPChpLZ-9YdOchyoBPCKaTA@mail.gmail.com> (raw)
In-Reply-To: <CACc7+8aMk2a5RpA3qvEeBXR8OVjMrbthJLA3OpxKKKvt38aDFg@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 1729 bytes --]

Me again,

Please forget about the previous patch I submitted, I have a new one that
should work now on all platforms.
Let me know if it should be formatted differently.

I will also add some more tests to check that such arrays in bash are
handled properly when the input contains whitespace, quotes, commas and
other chars that one may have to deal with.

--paf



On Fri, Aug 22, 2014 at 10:52 AM, Pascal Fleury <fleury@google.com> wrote:

> Hello,
>
> I have a little patch (attached) that does check the version of bash, and
> uses associative arrays (or doesn't) depending on that version.
>
> The problem now is that the test suite will only work on one platform t a
> time, i.e. if there is a bash4 there, it will pass, but if it has bash3, it
> will work as intended, but return a different value set. Is there a way to
> have platform-dependent tests ?
>
> --Pascal
>
>
>
> On Wed, Aug 13, 2014 at 3:29 PM, Alan Schmitt <
> alan.schmitt@polytechnique.org> wrote:
>
>> On 2014-08-13 15:20, Pascal Fleury <fleury@google.com> writes:
>>
>> > Yes, sorry for late reaction (it's holiday season here :-).
>>
>> Funny, it's holiday season here as well (in Bretagne) ;-)
>>
>> > This is an issue I introduced with the assoc. arrays, which does not
>> > verify if the installed version of bash handles them (from bash4 on).
>> > It needs a modification in the setup code that checks the version and
>> > only issues assoc. array code when bash supports it. And it so happens
>> > that Macs have bash3 installed. Will try to find such a machine and
>> > add the test.
>>
>> Thanks a lot. If I can help, please let me know.
>>
>> Best,
>>
>> Alan
>>
>> --
>> OpenPGP Key ID : 040D0A3B4ED2E5C7
>>
>
>
>
> --
> --paf
>



-- 
--paf

[-- Attachment #1.2: Type: text/html, Size: 2858 bytes --]

[-- Attachment #2: 0001-ob-shell.el-now-emits-associative-array-code-only-wh.patch --]
[-- Type: application/octet-stream, Size: 3093 bytes --]

From 251566b07d75e0254f5044b3807cb9d0ea9ff749 Mon Sep 17 00:00:00 2001
From: Pascal Fleury <fleury@google.com>
Date: Fri, 22 Aug 2014 15:04:00 +0200
Subject: [PATCH] ob-shell.el now emits associative array code only when the
 installed version of bash supports them. This takes care of differences in
 platforms that ship with bash v4+, that can deal with them, and those (e.g.
 MacOSX) that ship with bash v3.x that does not support such arrays.

---
 lisp/ob-shell.el                   | 12 +++++++++---
 testing/examples/ob-shell-test.org |  8 +++++++-
 testing/lisp/test-ob-shell.el      |  2 +-
 3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/lisp/ob-shell.el b/lisp/ob-shell.el
index 8c58dfd..e6b6429 100644
--- a/lisp/ob-shell.el
+++ b/lisp/ob-shell.el
@@ -121,12 +121,18 @@ This function is called by `org-babel-execute-src-block'."
      values
      "\n")))
 
+(defun bash-supports-assoc-arrays ()
+  "Returns if the current bash running on the system supports associative arrays."
+  (let ((bash_version (org-babel-execute:shell "echo ${BASH_VERSINFO[0]}" nil)))
+       (> 3 bash_version)))
+
 (defun org-babel-variable-assignments:bash (varname values &optional sep hline)
   "Represents the parameters as useful Bash shell variables."
-  (if (listp values)
-      (if (and (listp (car values)) (= 1 (length (car values))))
+   (if (listp values)
+      (if (or (not (bash-supports-assoc-arrays))
+	      (and (listp (car values)) (= 1 (length (car values)))))
 	  (org-babel-variable-assignments:bash_array varname values sep hline)
-	(org-babel-variable-assignments:bash_assoc varname values sep hline))
+	  (org-babel-variable-assignments:bash_assoc varname values sep hline))
     (org-babel-variable-assignments:sh-generic varname values sep hline)))
 
 (defun org-babel-variable-assignments:sh (params)
diff --git a/testing/examples/ob-shell-test.org b/testing/examples/ob-shell-test.org
index a54e5c0..cc3031d 100644
--- a/testing/examples/ob-shell-test.org
+++ b/testing/examples/ob-shell-test.org
@@ -80,7 +80,13 @@ echo ${table}
 Bash will see an associative array that contains each row as a single
 string. Bash cannot handle lists in associative arrays.
 #+begin_src bash :exports results :var table=sample_big_table
-echo ${table[spaghetti]}
+if (( ${BASH_VERSINFO[0]} > 3 )); then
+  # understands associative arrays
+  echo spaghetti ${table[spaghetti]}
+else
+  # Default V3.x behavior, has one array item contains the key and values.
+  echo ${table[1]}
+fi
 #+end_src
 
 #+RESULTS:
diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el
index 58a7859..9aa7f35 100644
--- a/testing/lisp/test-ob-shell.el
+++ b/testing/lisp/test-ob-shell.el
@@ -84,7 +84,7 @@ ob-comint.el, which was not previously tested."
   "Bash associative arrays as strings for the row"
   (org-test-at-id "82320a48-3409-49d7-85c9-5de1c6d3ff87"
     (org-babel-next-src-block 2)
-    (should (equal "20 cm" (org-babel-execute-src-block)))))
+    (should (equal "spaghetti 20 cm" (org-babel-execute-src-block)))))
 
 
 (provide 'test-ob-shell)
-- 
1.9.3


  reply	other threads:[~2014-08-22 13:09 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-22 10:03 2 Org tests failing Sebastien Vauban
2014-05-22 10:48 ` Bastien
     [not found]   ` <87tx8iks22.fsf-E3UqQZAQFPqWIDz0JBNUog@public.gmane.org>
2014-06-18 14:55     ` Sebastien Vauban
2014-06-18 21:49       ` Achim Gratz
2014-06-19  8:36         ` Sebastien Vauban
2014-06-19  9:04           ` Sebastien Vauban
2014-06-19  9:08             ` Sebastien Vauban
2014-06-19 20:05           ` Achim Gratz
2014-06-22  8:35             ` [PATCH] ob-shell (was: 2 Org tests failing) Achim Gratz
2014-06-22 12:50               ` [PATCH] ob-shell Eric Schulte
2014-06-23  6:26                 ` Pascal Fleury
2014-06-23 17:20                   ` Achim Gratz
2014-06-23 20:02                 ` Achim Gratz
2014-07-24  7:38                 ` Alan Schmitt
2014-08-04 11:56                   ` Eric Schulte
2014-08-04 19:48                   ` Achim Gratz
2014-08-13 13:12                     ` Alan Schmitt
2014-08-13 13:20                       ` Pascal Fleury
2014-08-13 13:29                         ` Alan Schmitt
2014-08-22  8:52                           ` Pascal Fleury
2014-08-22 13:08                             ` Pascal Fleury [this message]
2014-08-22 18:16                               ` Achim Gratz
2015-01-21 22:58                                 ` Pascal Fleury
2015-01-25 11:41                                   ` Achim Gratz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CACc7+8bZkBCdWOfxLSbJ0fyxMkDaPChpLZ-9YdOchyoBPCKaTA@mail.gmail.com \
    --to=fleury@google.com \
    --cc=Stromeko@nexgo.de \
    --cc=alan.schmitt@polytechnique.org \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).