From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id fOshKE2lomPKGAAAbAwnHQ (envelope-from ) for ; Wed, 21 Dec 2022 07:18:53 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id vb1VJk2lomNqVQAAG6o9tA (envelope-from ) for ; Wed, 21 Dec 2022 07:18:53 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id D91CFB46B for ; Wed, 21 Dec 2022 07:18:52 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p7sQb-0007qw-02; Wed, 21 Dec 2022 01:18:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7sQX-0007qY-TP for emacs-orgmode@gnu.org; Wed, 21 Dec 2022 01:18:05 -0500 Received: from sender4-op-o13.zoho.com ([136.143.188.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p7sQV-0007OB-UP for emacs-orgmode@gnu.org; Wed, 21 Dec 2022 01:18:05 -0500 ARC-Seal: i=1; a=rsa-sha256; t=1671603472; cv=none; d=zohomail.com; s=zohoarc; b=dMkhxQ814b35+WKuTmqWM6COTnOiHgerpIh5wQOD4gsv3T8oeYRvz/dKCHinqo9W8/iKvalWLPN9TuX2ySRG3jQAhIL95EYhczxhgQhXw0P6UxyDZtXiV/zTytScA+xQboy/+Rj0Z83Hz2Dc0UfftQtINjCd66TrYmCf0uGbw88= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671603472; h=Content-Type:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=XkpAmhdyygKUJsKIgTRVaVCd8K7qh9twUrYiKL0KJqM=; b=NwYfLoa+GKCkUpDR81KQM+mSQvhgbbJ9TTn1+G4ttigeI8MNBRhuCyA4YKt8GoRuHmcVjrgXKkl5KSqFYLF7Rp+DtFvBmqwxfeRqwObFm0iu9Erevkqv0/TxtNI3K8vUqMWYBvLvhaaUBFfwGjK/kzOVweT1BVwyZiXXZrFSQpI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=excalamus.com; spf=pass smtp.mailfrom=matt@excalamus.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1671603472; s=zmail; d=excalamus.com; i=matt@excalamus.com; h=Date:Date:From:From:To:To:Cc:Cc:Message-Id:Message-Id:In-Reply-To:References:Subject:Subject:MIME-Version:Content-Type:Reply-To; bh=XkpAmhdyygKUJsKIgTRVaVCd8K7qh9twUrYiKL0KJqM=; b=BCe71NIfqBsYad7LjQCJ0FXdQBSIKQzbTY5MeZSbLLN+gTvPkfkXNty5F+EpBDAy SKPcZneQFZ53E1egR7UHrVkKv9U0SWMUHcQXwWgdLHs8Kse2kPtiyKBTrKGLJSvE2l5 O/VjOwN1GvtiMhjzSVoad9DOE9CvatrbvkLcrlsE= Received: from mail.zoho.com by mx.zohomail.com with SMTP id 1671603470045803.9765376124525; Tue, 20 Dec 2022 22:17:50 -0800 (PST) Date: Wed, 21 Dec 2022 01:17:50 -0500 From: Matt To: "Ihor Radchenko" Cc: =?UTF-8?Q?=22rudolf_adamkovi=C4=8D=22?= , "emacs-orgmode" Message-Id: <1853354beb4.fce54d8d902653.6359367327256505471@excalamus.com> In-Reply-To: <878rj7s0ti.fsf@localhost> References: <878rj7s0ti.fsf@localhost> Subject: ob-shell intentions and paperwork (was Bash results broken?) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_2868410_326926990.1671603470004" Importance: Medium User-Agent: Zoho Mail X-Mailer: Zoho Mail X-Zoho-Virus-Status: 1 Received-SPF: pass client-ip=136.143.188.13; envelope-from=matt@excalamus.com; helo=sender4-op-o13.zoho.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=pass header.d=excalamus.com header.s=zmail header.b=BCe71NIf; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=none; arc=pass ("zohomail.com:s=zohoarc:i=1") ARC-Seal: i=2; s=key1; d=yhetil.org; t=1671603533; a=rsa-sha256; cv=pass; b=GrxqqQ+kl+aZ8TeSW1+ZWnAraiOnrgJrI4WL8EaKIJbn78TTW2ZM48c+OfWKYrVaa7Pp3F vLltetiEvPwNswBJ7e1P6vY6AtEADhY7DsUh5XEoMvxMOTTkUrrWr9HGf6kAwZIv/sYcYh 8RHJZbbcov/dHdZZLX686StsrpbSJvTIjT3leKKIWBNxzo6/pmXrwpSI12M0mHK01sBxpI H86AhQptGTIi4Em+hU+rQ0n5ZKG86YnVlzRjuRvO2BBdO3IuEs3+gKH02HU5mjqIgwFObi m1rVp83ZoyWZfKIrw3gpX1ZOxA3V+L2EugfNmJ6liEJEIZEewTmkvsMnmTELww== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1671603533; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=XkpAmhdyygKUJsKIgTRVaVCd8K7qh9twUrYiKL0KJqM=; b=VCbNC5Tsyj8aEDOtFpdA0VwfbgkHQz/5w+Gks8x6OQENh/GEglOjtQL7CFVWWLP48Ln/Td cKTWVa7VGeMSJWmAWpZgsJfnUHOCPUGXvuD5jPGq7evci39LPer9TQ/rG8tub/WpTyl1Ec IQmtKkoRGrNNjwOE9MpY4ylqTk0bSV3q8a8Pdrr+BhhjLpsg/EZ8hZej0Y81RcIsGeW4eZ +SmbRuZsN7xexGcNU6MralFoSWYxA5ZollLhXElICExxX6nr8ghNcYvFgOICKgTR2ngnUR j6BpeggtO7RLwy7/wWUKMPfrRnTUvzx5QL6GNmteLoAnhCaKFket3gnIshh3Sg== X-Migadu-Scanner: scn0.migadu.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=excalamus.com header.s=zmail header.b=BCe71NIf; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=none; arc=pass ("zohomail.com:s=zohoarc:i=1") X-Migadu-Spam-Score: -6.48 X-Spam-Score: -6.48 X-Migadu-Queue-Id: D91CFB46B X-TUID: tQ9uj9V0Qp1w ------=_Part_2868410_326926990.1671603470004 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit ---- On Fri, 16 Dec 2022 12:41:45 -0500 Ihor Radchenko wrote --- > We really need more tests. I'm working on giving ob-shell a little bit of love. I wrote the worg documentation for it earlier this year. I tried to include examples of all coded functionality, including previously undocumented features. I think the examples would make for good tests since they document the present and expected behavior. Currently, though, I'm refactoring the ob-shell tests to remove dependency on ob-shell-test.org and to stop the suite from littering. After that, I intend to incorporate the worg examples as tests. I'd like to adopt ob-shell, life permitting. Sadly, I'm not confident I'm able to commit to that right now. So, if I can get the FSF paperwork cleared, hopefully, I can make little contributions here and there. I've included patches of what I've been doing. They're not ready for actual submission yet, both in quality and legality. However, I'm including them for feedback, to make sure I'm not getting way off base. Overall, I'd *really* like to implement async for ob-shell similar to ob-python. However, I feel like it'd be more responsible and respectful to clean up the tests and code a little first before proposing such a big change (looking at you, org-babel-shell-initialize). Can someone please assist me with the FSF paperwork off list? ------=_Part_2868410_326926990.1671603470004 Content-Type: application/octet-stream; name=0001-Remove-mixed-tabs-and-spaces.patch Content-Transfer-Encoding: 7bit X-ZM_AttachId: 138908962700060000 Content-Disposition: attachment; filename=0001-Remove-mixed-tabs-and-spaces.patch >From 2bc7b05bcd8a6e74fec18d070a92d8ebecde69e6 Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 20 Dec 2022 13:51:26 -0500 Subject: [PATCH 1/7] Remove mixed tabs and spaces Converted tabs to spaces on the premise that one or the other is better than both. --- testing/lisp/test-ob-shell.el | 58 +++++++++++++++++------------------ 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el index b0d9beff4..816e93ac5 100644 --- a/testing/lisp/test-ob-shell.el +++ b/testing/lisp/test-ob-shell.el @@ -32,9 +32,9 @@ "Expanded shell bodies should not start with a blank line unless the body of the tangled block does." (should-not (string-match "^[\n\r][\t ]*[\n\r]" - (org-babel-expand-body:generic "echo 2" '()))) + (org-babel-expand-body:generic "echo 2" '()))) (should (string-match "^[\n\r][\t ]*[\n\r]" - (org-babel-expand-body:generic "\n\necho 2" '())))) + (org-babel-expand-body:generic "\n\necho 2" '())))) (ert-deftest test-ob-shell/dont-error-on-empty-results () "Was throwing an elisp error when shell blocks threw errors and @@ -49,8 +49,8 @@ ob-comint.el, which was not previously tested." (should (listp res))) ;; Test multi-line input. (let ((result (org-babel-execute:sh - "if true \n then \n echo yes \n fi" - '((:session . "yes"))))) + "if true \n then \n echo yes \n fi" + '((:session . "yes"))))) (should result) (should (string= "yes" result)))) @@ -71,47 +71,47 @@ ob-comint.el, which was not previously tested." "No associative arrays for generic" (should (equal "first one second two third three" - (org-test-at-id - "bec1a5b0-4619-4450-a8c0-2a746b44bf8d" - (org-babel-next-src-block) - (org-trim (org-babel-execute-src-block))))) + (org-test-at-id + "bec1a5b0-4619-4450-a8c0-2a746b44bf8d" + (org-babel-next-src-block) + (org-trim (org-babel-execute-src-block))))) (should (equal "bread 2 kg spaghetti 20 cm milk 50 dl" - (org-test-at-id - "82320a48-3409-49d7-85c9-5de1c6d3ff87" - (org-babel-next-src-block) - (org-trim (org-babel-execute-src-block)))))) + (org-test-at-id + "82320a48-3409-49d7-85c9-5de1c6d3ff87" + (org-babel-next-src-block) + (org-trim (org-babel-execute-src-block)))))) (ert-deftest ob-shell/bash-uses-assoc-arrays () "Bash associative arrays" (should (equal "two" - (org-test-at-id - "bec1a5b0-4619-4450-a8c0-2a746b44bf8d" - (org-babel-next-src-block 2) - (org-trim (org-babel-execute-src-block))))) + (org-test-at-id + "bec1a5b0-4619-4450-a8c0-2a746b44bf8d" + (org-babel-next-src-block 2) + (org-trim (org-babel-execute-src-block))))) ;; Bash associative arrays as strings for the row. (should (equal "20 cm" - (org-test-at-id - "82320a48-3409-49d7-85c9-5de1c6d3ff87" - (org-babel-next-src-block 2) - (org-trim (org-babel-execute-src-block)))))) + (org-test-at-id + "82320a48-3409-49d7-85c9-5de1c6d3ff87" + (org-babel-next-src-block 2) + (org-trim (org-babel-execute-src-block)))))) (ert-deftest ob-shell/simple-list () "Test list variables in shell." ;; With bash, a list is turned into an array. (should (equal "2" - (org-test-with-temp-text - "#+BEGIN_SRC bash :results output :var l='(1 2)\necho ${l[1]}\n#+END_SRC" - (org-trim (org-babel-execute-src-block))))) + (org-test-with-temp-text + "#+BEGIN_SRC bash :results output :var l='(1 2)\necho ${l[1]}\n#+END_SRC" + (org-trim (org-babel-execute-src-block))))) ;; On sh, it is a string containing all values. (should (equal "1 2" - (org-test-with-temp-text - "#+BEGIN_SRC sh :results output :var l='(1 2)\necho ${l}\n#+END_SRC" - (org-trim (org-babel-execute-src-block)))))) + (org-test-with-temp-text + "#+BEGIN_SRC sh :results output :var l='(1 2)\necho ${l}\n#+END_SRC" + (org-trim (org-babel-execute-src-block)))))) (ert-deftest ob-shell/remote-with-stdin-or-cmdline () "Test :stdin and :cmdline with a remote directory." @@ -166,9 +166,9 @@ ob-comint.el, which was not previously tested." "Test :results table." (should (equal '(("I \"want\" it all")) - (org-test-with-temp-text - "#+BEGIN_SRC sh :results table\necho 'I \"want\" it all'\n#+END_SRC" - (org-babel-execute-src-block))))) + (org-test-with-temp-text + "#+BEGIN_SRC sh :results table\necho 'I \"want\" it all'\n#+END_SRC" + (org-babel-execute-src-block))))) (ert-deftest ob-shell/results-list () "Test :results list." -- 2.38.1 ------=_Part_2868410_326926990.1671603470004 Content-Type: application/octet-stream; name=0002-Split-test-ob-shell-dont-error-on-empty-results.patch Content-Transfer-Encoding: 7bit X-ZM_AttachId: 138908962700110000 Content-Disposition: attachment; filename=0002-Split-test-ob-shell-dont-error-on-empty-results.patch >From d7a0e0df2f3d217d081a1b7302b1cab49aa614d0 Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 20 Dec 2022 13:53:44 -0500 Subject: [PATCH 2/7] Split test-ob-shell/dont-error-on-empty-results Fixes ambiguity in test name, docstring, and function. The docstring said, "Was throwing an elisp error when shell blocks threw errors and returned empty results." The test checked two things: 1) whether `org-babel-execute:sh` could handle empty results and 2) whether it handled babel errors gracefully. These aren't necessarily the same thing. This change splits the test into the two conditions it was actually testing. It also cleans up buffers created during testing when successful. --- testing/lisp/test-ob-shell.el | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el index 816e93ac5..625dc64b9 100644 --- a/testing/lisp/test-ob-shell.el +++ b/testing/lisp/test-ob-shell.el @@ -37,9 +37,11 @@ unless the body of the tangled block does." (org-babel-expand-body:generic "\n\necho 2" '())))) (ert-deftest test-ob-shell/dont-error-on-empty-results () - "Was throwing an elisp error when shell blocks threw errors and -returned empty results." - (should (null (org-babel-execute:sh "ls NoSuchFileOrDirectory.txt" nil)))) + (should (null (org-babel-execute:sh nil nil)))) + +(ert-deftest test-ob-shell/dont-error-on-babel-error () + (if (should (null (org-babel-execute:sh "ls NoSuchFileOrDirectory.txt" nil))) + (kill-buffer "*Org-Babel Error Output*"))) (ert-deftest test-ob-shell/session () "This also tests `org-babel-comint-with-output' in -- 2.38.1 ------=_Part_2868410_326926990.1671603470004 Content-Type: application/octet-stream; name=0003-Refactor-test-ob-shell-session.patch Content-Transfer-Encoding: 7bit X-ZM_AttachId: 138908962700130000 Content-Disposition: attachment; filename=0003-Refactor-test-ob-shell-session.patch >From 1637ee73ed2ead8fac258996b9e05f18bfc33136 Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 20 Dec 2022 15:22:38 -0500 Subject: [PATCH 3/7] Refactor test-ob-shell/session - Rename test precisely - Rename comint from "yes" to test name* - Clean up on success Several notes have been placed indicating future refactoring. Namely, `org-babel-shell-initialize` should be a macro since it generates functions. * The session name should be refactored into a variable, e.g. `session-name`. However, when this is done, `org-babel-execute:sh` produces a type error. The `params` symbol in `org-babel-execute:sh` does not evaluate as a variable for some reason and, because of how `org-babel-execute:sh` is defined, it's difficult to debug why. --- lisp/ob-shell.el | 2 ++ testing/lisp/test-ob-shell.el | 26 ++++++++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lisp/ob-shell.el b/lisp/ob-shell.el index d38d2d335..8da9aa738 100644 --- a/lisp/ob-shell.el +++ b/lisp/ob-shell.el @@ -68,6 +68,8 @@ alist element.") (defvar org-babel-prompt-command) +;; TODO refactor into macro. Currently violates (elisp) Coding +;; Conventions and is hard to debug. (defun org-babel-shell-initialize () "Define execution functions associated to shell names. This function has to be called whenever `org-babel-shell-names' diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el index 625dc64b9..ecdc461d3 100644 --- a/testing/lisp/test-ob-shell.el +++ b/testing/lisp/test-ob-shell.el @@ -29,8 +29,8 @@ (signal 'missing-test-dependency "Support for Shell code blocks")) (ert-deftest test-ob-shell/dont-insert-spaces-on-expanded-bodies () - "Expanded shell bodies should not start with a blank line -unless the body of the tangled block does." + "Expanded shell bodies should not start with a blank line unless +the body of the tangled block does." (should-not (string-match "^[\n\r][\t ]*[\n\r]" (org-babel-expand-body:generic "echo 2" '()))) (should (string-match "^[\n\r][\t ]*[\n\r]" @@ -43,18 +43,24 @@ unless the body of the tangled block does." (if (should (null (org-babel-execute:sh "ls NoSuchFileOrDirectory.txt" nil))) (kill-buffer "*Org-Babel Error Output*"))) -(ert-deftest test-ob-shell/session () - "This also tests `org-babel-comint-with-output' in -ob-comint.el, which was not previously tested." - (let ((res (org-babel-execute:sh "echo 1; echo 2" '((:session . "yes"))))) +;; TODO refactor session name into variable after refactoring +;; org-babel-execute:sh. See comment there. +(ert-deftest test-ob-shell/session-parameter-results-in-list () + ;; single line input + (let ((res (org-babel-execute:sh "echo 1; echo 2" '((:session . "test-ob-shell/session-parameter-results-in-list"))))) (should res) (should (listp res))) - ;; Test multi-line input. + + ;; multi-line input (let ((result (org-babel-execute:sh - "if true \n then \n echo yes \n fi" - '((:session . "yes"))))) + "if true \n then \n echo test-ob-shell/session-parameter-results-in-list \n fi" + '((:session . "test-ob-shell/session-parameter-results-in-list"))))) (should result) - (should (string= "yes" result)))) + (should (string= "test-ob-shell/session-parameter-results-in-list" result))) + + ;; clean up + (let ((kill-buffer-query-functions nil)) + (kill-buffer "test-ob-shell/session-parameter-results-in-list"))) ; A list of tests using the samples in ob-shell-test.org (ert-deftest ob-shell/generic-uses-no-arrays () -- 2.38.1 ------=_Part_2868410_326926990.1671603470004 Content-Type: application/octet-stream; name=0004-Refactor-ob-shell-generic-uses-no-arrays.patch Content-Transfer-Encoding: base64 X-ZM_AttachId: 138908962700140050 Content-Disposition: attachment; filename=0004-Refactor-ob-shell-generic-uses-no-arrays.patch RnJvbSBlOGE3YTgyYWQxMDA3MzE3MmVlZjJlZjllMjE1ODYwYWY1NmZlYjgyIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBNYXR0IDxtYXR0QGV4Y2FsYW11cy5jb20+CkRhdGU6IFR1ZSwg MjAgRGVjIDIwMjIgMTg6MTA6NTIgLTA1MDAKU3ViamVjdDogW1BBVENIIDQvN10gUmVmYWN0b3Ig b2Itc2hlbGwvZ2VuZXJpYy11c2VzLW5vLWFycmF5cwoKLSBJbnRyb2R1Y2UgYG11bHRpbGluZS1z dHJpbmdgIG1hY3JvCi0gUmVuYW1lIGZyb20gIm9iLXNoZWxsIiB0byAidGVzdC1vYi1zaGVsbCIK LSBSZW1vdmUgZXh0ZXJuYWwgZmlsZSBkZXBlbmRlbmN5Ci0tLQogdGVzdGluZy9saXNwL3Rlc3Qt b2Itc2hlbGwuZWwgfCAyOSArKysrKysrKysrKysrKysrKysrKysrKystLS0tLQogMSBmaWxlIGNo YW5nZWQsIDI0IGluc2VydGlvbnMoKyksIDUgZGVsZXRpb25zKC0pCgpkaWZmIC0tZ2l0IGEvdGVz dGluZy9saXNwL3Rlc3Qtb2Itc2hlbGwuZWwgYi90ZXN0aW5nL2xpc3AvdGVzdC1vYi1zaGVsbC5l bAppbmRleCBlY2RjNDYxZDMuLjljODBhYTFhZiAxMDA2NDQKLS0tIGEvdGVzdGluZy9saXNwL3Rl c3Qtb2Itc2hlbGwuZWwKKysrIGIvdGVzdGluZy9saXNwL3Rlc3Qtb2Itc2hlbGwuZWwKQEAgLTIz LDYgKzIzLDE4IEBACiA7OyBUZW1wbGF0ZSB0ZXN0IGZpbGUgZm9yIE9yZyB0ZXN0cwogCiA7Ozsg Q29kZToKKyhkZWZtYWNybyBtdWx0aWxpbmUtc3RyaW5nICgmcmVzdCBib2R5KQorICAiSm9pbiBC T0RZIHdpdGggbmV3bGluZXMuCisKK0JPRFkgaXMgbWFkZSBvZiBzdWNjZXNzaXZlIHN0cmluZ3Mu CisKKyAgICAobXVsdGlsaW5lLXN0cmluZyBcImZpcnN0XCIgXCJzZWNvbmRcIiBcInRoaXJkXCIp CisgICAg4oeSIFwiZmlyc3RcXG5zZWNvbmRcXG50aGlyZFwiCisKK1woZm4gQk9EWSkiCisgIChk ZWNsYXJlIChpbmRlbnQgbmlsKSAoZGVidWcgdCkpCisgIGAoc3RyaW5nLWpvaW4gKHF1b3RlICxi b2R5KSAiXG4iKSkKKwogKG9yZy10ZXN0LWZvci1leGVjdXRhYmxlICJzaCIpCiAocmVxdWlyZSAn b2ItY29yZSkKICh1bmxlc3MgKGZlYXR1cmVwICdvYi1zaGVsbCkKQEAgLTYyLDExICs3NCwxOCBA QCB0aGUgYm9keSBvZiB0aGUgdGFuZ2xlZCBibG9jayBkb2VzLiIKICAgKGxldCAoKGtpbGwtYnVm ZmVyLXF1ZXJ5LWZ1bmN0aW9ucyBuaWwpKQogICAgIChraWxsLWJ1ZmZlciAidGVzdC1vYi1zaGVs bC9zZXNzaW9uLXBhcmFtZXRlci1yZXN1bHRzLWluLWxpc3QiKSkpCiAKLTsgQSBsaXN0IG9mIHRl c3RzIHVzaW5nIHRoZSBzYW1wbGVzIGluIG9iLXNoZWxsLXRlc3Qub3JnCi0oZXJ0LWRlZnRlc3Qg b2Itc2hlbGwvZ2VuZXJpYy11c2VzLW5vLWFycmF5cyAoKQotICAiTm8gYXJyYXlzIGZvciBnZW5l cmljIgotICAob3JnLXRlc3QtYXQtaWQgIjBiYTU2NjMyLThkYzEtNDA1Yy1hMDgzLWMyMDRiYWU0 NzdjZiIKLSAgICAob3JnLWJhYmVsLW5leHQtc3JjLWJsb2NrKQorKGVydC1kZWZ0ZXN0IHRlc3Qt b2Itc2hlbGwvZ2VuZXJpYy11c2VzLW5vLWFycmF5cyAoKQorICAob3JnLXRlc3Qtd2l0aC10ZW1w LXRleHQKKyAgICAgIChtdWx0aWxpbmUtc3RyaW5nCisgICAgICAgIiMrTkFNRTogc2FtcGxlX2Fy cmF5IgorICAgICAgICJ8IG9uZSAgIHwiCisgICAgICAgInwgdHdvICAgfCIKKyAgICAgICAifCB0 aHJlZSB8IgorICAgICAgICIiCisgICAgICAgIiMrYmVnaW5fc3JjIHNoIDpleHBvcnRzIHJlc3Vs dHMgOnJlc3VsdHMgb3V0cHV0IDp2YXIgYXJyYXk9c2FtcGxlX2FycmF5IgorICAgICAgICJlY2hv ICR7YXJyYXl9IgorICAgICAgICI8cG9pbnQ+IgorICAgICAgICIjK2VuZF9zcmMiKQogICAgIChz aG91bGQgKGVxdWFsICJvbmUgdHdvIHRocmVlIiAob3JnLXRyaW0gKG9yZy1iYWJlbC1leGVjdXRl LXNyYy1ibG9jaykpKSkpKQogCiAoZXJ0LWRlZnRlc3Qgb2Itc2hlbGwvYmFzaC11c2VzLWFycmF5 cyAoKQotLSAKMi4zOC4xCgo= ------=_Part_2868410_326926990.1671603470004 Content-Type: application/octet-stream; name=0005-Refactor-ob-shell-bash-uses-arrays.patch Content-Transfer-Encoding: 7bit X-ZM_AttachId: 138908962700160040 Content-Disposition: attachment; filename=0005-Refactor-ob-shell-bash-uses-arrays.patch >From a1782ab8b38850858c4502db8e0a4999845c13dd Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 20 Dec 2022 18:16:17 -0500 Subject: [PATCH 5/7] Refactor ob-shell/bash-uses-arrays - Rename "ob-shell" to "test-ob-shell" - Remove external file dependency --- testing/lisp/test-ob-shell.el | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el index 9c80aa1af..0328a0926 100644 --- a/testing/lisp/test-ob-shell.el +++ b/testing/lisp/test-ob-shell.el @@ -88,10 +88,22 @@ the body of the tangled block does." "#+end_src") (should (equal "one two three" (org-trim (org-babel-execute-src-block)))))) -(ert-deftest ob-shell/bash-uses-arrays () - "Bash arrays" - (org-test-at-id "0ba56632-8dc1-405c-a083-c204bae477cf" - (org-babel-next-src-block 2) +(ert-deftest test-ob-shell/bash-uses-arrays () + "Bash will see a simple indexed array. In this test, we check that the +returned value is indeed only the first item of the array, as opposed to +the generic serialiation that will return all elements of the array as +a single string." + (org-test-with-temp-text + (multiline-string + "#+NAME: sample_array" + "| one |" + "| two |" + "| three |" + "" + "#+begin_src bash :exports results :results output :var array=sample_array" + "echo ${array}" + "" + "#+end_src") (should (equal "one" (org-trim (org-babel-execute-src-block)))))) (ert-deftest ob-shell/generic-uses-no-assoc-arrays () -- 2.38.1 ------=_Part_2868410_326926990.1671603470004 Content-Type: application/octet-stream; name=0006-Refactor-ob-shell-generic-uses-no-assoc-arrays.patch Content-Transfer-Encoding: 7bit X-ZM_AttachId: 138908962700180000 Content-Disposition: attachment; filename=0006-Refactor-ob-shell-generic-uses-no-assoc-arrays.patch >From cd4143fe2399b1b45383bab267adad617612fd03 Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 20 Dec 2022 19:22:40 -0500 Subject: [PATCH 6/7] Refactor ob-shell/generic-uses-no-assoc-arrays - Split tests based on simple versus complex mapping - Remove external file dependency - Rename "ob-shell" to "test-ob-shell" - Move headlines and commentary to doc string --- testing/lisp/test-ob-shell.el | 53 ++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el index 0328a0926..ed73a1cd9 100644 --- a/testing/lisp/test-ob-shell.el +++ b/testing/lisp/test-ob-shell.el @@ -106,20 +106,45 @@ a single string." "#+end_src") (should (equal "one" (org-trim (org-babel-execute-src-block)))))) -(ert-deftest ob-shell/generic-uses-no-assoc-arrays () - "No associative arrays for generic" - (should - (equal "first one second two third three" - (org-test-at-id - "bec1a5b0-4619-4450-a8c0-2a746b44bf8d" - (org-babel-next-src-block) - (org-trim (org-babel-execute-src-block))))) - (should - (equal "bread 2 kg spaghetti 20 cm milk 50 dl" - (org-test-at-id - "82320a48-3409-49d7-85c9-5de1c6d3ff87" - (org-babel-next-src-block) - (org-trim (org-babel-execute-src-block)))))) +(ert-deftest test-ob-shell/generic-uses-no-assoc-arrays-simple-map () + "Generic shell: no special handing for key-value mapping table + +No associative arrays for generic. The shell will see all values +as a single string." + (org-test-with-temp-text + (multiline-string + "#+NAME: sample_mapping_table" + "| first | one |" + "| second | two |" + "| third | three |" + "" + "#+begin_src sh :exports results :results output :var table=sample_mapping_table" + "echo ${table}" + "" + "#+end_src") + (should + (equal "first one second two third three" + (org-trim (org-babel-execute-src-block)))))) + +(ert-deftest test-ob-shell/generic-uses-no-assoc-arrays-3-columns () + "Associative array tests (more than 2 columns) + +No associative arrays for generic. The shell will see all values +as a single string." + (org-test-with-temp-text + (multiline-string + "#+NAME: sample_big_table" + "| bread | 2 | kg |" + "| spaghetti | 20 | cm |" + "| milk | 50 | dl |" + "" + "#+begin_src sh :exports results :results output :var table=sample_big_table" + "echo ${table}" + "" + "#+end_src") + (should + (equal "bread 2 kg spaghetti 20 cm milk 50 dl" + (org-trim (org-babel-execute-src-block)))))) (ert-deftest ob-shell/bash-uses-assoc-arrays () "Bash associative arrays" -- 2.38.1 ------=_Part_2868410_326926990.1671603470004 Content-Type: application/octet-stream; name=0007-Refactor-ob-shell-bash-uses-assoc-arrays.patch Content-Transfer-Encoding: 7bit X-ZM_AttachId: 138908962700200070 Content-Disposition: attachment; filename=0007-Refactor-ob-shell-bash-uses-assoc-arrays.patch >From 42975ddf6e8bd3ba39328989e9baf016ab510077 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 21 Dec 2022 00:45:44 -0500 Subject: [PATCH 7/7] Refactor ob-shell/bash-uses-assoc-arrays - Split cases into separate tests - Rename "ob-shell" to "test-ob-shell" - Remove external file dependency --- testing/lisp/test-ob-shell.el | 51 ++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el index ed73a1cd9..1404647b9 100644 --- a/testing/lisp/test-ob-shell.el +++ b/testing/lisp/test-ob-shell.el @@ -146,21 +146,46 @@ as a single string." (equal "bread 2 kg spaghetti 20 cm milk 50 dl" (org-trim (org-babel-execute-src-block)))))) -(ert-deftest ob-shell/bash-uses-assoc-arrays () - "Bash associative arrays" - (should - (equal "two" - (org-test-at-id - "bec1a5b0-4619-4450-a8c0-2a746b44bf8d" - (org-babel-next-src-block 2) - (org-trim (org-babel-execute-src-block))))) - ;; Bash associative arrays as strings for the row. +(ert-deftest test-ob-shell/bash-uses-assoc-arrays () + "Bash shell: support for associative arrays + +Bash will see a table that contains the first column as the +'index' of the associative array, and the second column as the +value. " + (org-test-with-temp-text + (multiline-string + "#+NAME: sample_mapping_table" + "| first | one |" + "| second | two |" + "| third | three |" + "" + "#+begin_src bash :exports :results output results :var table=sample_mapping_table" + "echo ${table[second]}" + "" + "#+end_src") + (should + (equal "two" + (org-trim (org-babel-execute-src-block)))))) + +(ert-deftest test-ob-shell/bash-uses-assoc-arrays-with-lists () + "Bash shell: support for associative arrays with lists + +Bash will see an associative array that contains each row as a single +string. Bash cannot handle lists in associative arrays." + (org-test-with-temp-text + (multiline-string + "#+NAME: sample_big_table" + "| bread | 2 | kg |" + "| spaghetti | 20 | cm |" + "| milk | 50 | dl |" + "" + "#+begin_src bash :exports results :results output :var table=sample_big_table" + "echo ${table[spaghetti]}" + "" + "#+end_src") (should (equal "20 cm" - (org-test-at-id - "82320a48-3409-49d7-85c9-5de1c6d3ff87" - (org-babel-next-src-block 2) - (org-trim (org-babel-execute-src-block)))))) + (org-trim (org-babel-execute-src-block)))))) (ert-deftest ob-shell/simple-list () "Test list variables in shell." -- 2.38.1 ------=_Part_2868410_326926990.1671603470004--