From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.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 YNIOKCUyr2Pr0wAAbAwnHQ (envelope-from ) for ; Fri, 30 Dec 2022 19:47:01 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id SDfqJyUyr2NEUAAAauVa8A (envelope-from ) for ; Fri, 30 Dec 2022 19:47:01 +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 9B7F4FBB7 for ; Fri, 30 Dec 2022 19:47:00 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pBKOZ-0000WF-6c; Fri, 30 Dec 2022 13:46:21 -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 1pBKOR-0000W1-Pa for emacs-orgmode@gnu.org; Fri, 30 Dec 2022 13:46:12 -0500 Received: from sender4-op-o12.zoho.com ([136.143.188.12]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pBKON-00010s-Kn for emacs-orgmode@gnu.org; Fri, 30 Dec 2022 13:46:10 -0500 ARC-Seal: i=1; a=rsa-sha256; t=1672425963; cv=none; d=zohomail.com; s=zohoarc; b=EmGvDOd5vDuvw8DY78aAOSpR6LVKbRKjj1uY5eaLDqdEy8tSq2BBfcnqz0Ps6djQdOXBAl/hgvI883JyTp5FJW+qzos1IFT7WY5ZFtp/LDVfsjF/ni/ZqV9ClgNwtL/vZXftepXiZbtmjbieAnFT7rGaW1J3/nx2K8prktxu+HA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1672425963; h=Content-Type:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=3epwCN/s21Z5wcseQu+woSrYdXIsdtFGzkufYlt9KsE=; b=etBfhvhKd/cUkVDFThHUy30/9U/+uDFN6s/7zIRbGs3a+Mp27d984Zi5oIqxQpO6yX0zAyYWjbYfuKKmAirEN+HN5d9ssWi4bQ6WVlVZGfyNosIsHIW6IMPvSH2QwTbhXyD+SiDw8d3dJQUkBYnBCeOb/aNIs3OYWODx2Bsobgk= 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=1672425963; 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=3epwCN/s21Z5wcseQu+woSrYdXIsdtFGzkufYlt9KsE=; b=f6zACTJ02Zo7YwpH0sES6EUGR8sq3MHcy83aQPKQoA5LWq8hu90wxYCPznKn5zDK pWfjz6xisRU+tWDRB7I0wfj2KhNcqia1L3oGqsnCP3Xm/NxhT8qJZaN4LGMHYmNwwne zmhafk4QhwpvgSXZj8PaWfGnCxXhXIEBm4GTg9k4= Received: from mail.zoho.com by mx.zohomail.com with SMTP id 1672425960117188.75352069593998; Fri, 30 Dec 2022 10:46:00 -0800 (PST) Date: Fri, 30 Dec 2022 13:46:00 -0500 From: Matt To: "ihor radchenko" Cc: "emacs-orgmode" Message-Id: <185645af285.f16730c9981316.8238066002530458068@excalamus.com> In-Reply-To: <18561866f8c.f22a62b3866025.8634474263936272339@excalamus.com> References: <878rj7s0ti.fsf@localhost> <1853354beb4.fce54d8d902653.6359367327256505471@excalamus.com> <18555580d75.d7b471f9370716.1497263973038999899@excalamus.com> <87edsiv54k.fsf@localhost> <18561866f8c.f22a62b3866025.8634474263936272339@excalamus.com> Subject: Re: ob-shell intentions and paperwork (was Bash results broken?) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_3118441_1342913871.1672425960069" Importance: Medium User-Agent: Zoho Mail X-Mailer: Zoho Mail X-Zoho-Virus-Status: 1 Received-SPF: pass client-ip=136.143.188.12; envelope-from=matt@excalamus.com; helo=sender4-op-o12.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-Seal: i=2; s=key1; d=yhetil.org; t=1672426021; a=rsa-sha256; cv=pass; b=QKKIM80XfxG3dsJP+rGK/Vi92psW8NE4dydFPQs80S5Carn8PHuFPJuG7jzfJko+259Law MXDv+nzzmWlSAp4lRSvSPs/O0TUNQDu11rm6A/7vNvEpWVzrXtX/Ns9ebLWBbyeomEv8Ec zHZZPU00/esnFKf6VgJCQu/PQYjHAySOUPISTU/9lP+M0hL1eMqu2FnHN3TZjW6BlY2Ux4 YyzJOhXl1JmKYoEHJ45gdsFmPqUBHY0/qtcoC+LkjP/EWK4ntp/NxRcWaSFBPx0FX+RntU ol43Z/3hQZKXMizhaLG6KBo9sn2S3GO9Zgvg2X5S5aQfY7M2UqbymIZnOgdujw== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=pass header.d=excalamus.com header.s=zmail header.b=f6zACTJ0; 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-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1672426021; 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=3epwCN/s21Z5wcseQu+woSrYdXIsdtFGzkufYlt9KsE=; b=pnBhe9EZP20Y2BOr3YqrxdgMrIGZN7T7rAZMwskjcyiJMC0IIO8mCYtVm4pL6uhsDboiKO PydKvHaG8U80V79CyRG3haK1HSgGotw1T3XxVZtGIGEorbarIor4xzSX/cGqu6avE4aRuN mo0mkLqdWQQ0LY1R7UQ+mmEVVHpGEYG+Qcoz438lIyUT/kXVScvXmMia8JO5JfOBUiEGvc VzrhoBbzksWnF0h1NYFkA3b8jDibEEqv3A5vgA88eQHUXrj3ly+EU89WgVCHOvuFketO8A qwFDGHWttn7z3j3UtICgYDZYF8wT1yVVKPiPSPYT97Oz/fpWQo0epRYjYLnoXQ== X-Spam-Score: -10.01 X-Migadu-Queue-Id: 9B7F4FBB7 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=excalamus.com header.s=zmail header.b=f6zACTJ0; 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-Scanner: scn0.migadu.com X-Migadu-Spam-Score: -10.01 X-TUID: BwFMXT10Dawf ------=_Part_3118441_1342913871.1672425960069 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit ---- On Fri, 30 Dec 2022 00:34:38 -0500 Matt wrote --- > > ---- On Thu, 29 Dec 2022 06:08:59 -0500 Ihor Radchenko wrote --- > > > From: Matt Trzcinski matt@excalamus.com> > > > +(require 'org-test (expand-file-name "../org-test.el")) > > > > I am unsure here. What will happen if you run this file from > > default-directory not the same with file location? I was mistaken. Loading a new Emacs instance and running `(load "/path/to/test-ob-shell.el")' fails with file-missing error. I'm content to leave that alone for now. I've backed out the `require' change and adjusted everything else based on your feedback. There is a separate patch for each refactor that created a new test. The remaining refactors are in a single patch. I was also able to resolve the issue I had with inserting the test name for the session (the "yes" string in `test-ob-shell/session'). The issue with `org-babel-shell-initialize' still stands but is outside the scope of these patches and isn't dealt with here. ------=_Part_3118441_1342913871.1672425960069 Content-Type: application/octet-stream; name=0001-test-ob-shell.el-Split-test-ob-shell-dont-error-on-e.patch Content-Transfer-Encoding: 7bit X-ZM_AttachId: 138917187600700560 Content-Disposition: attachment; filename=0001-test-ob-shell.el-Split-test-ob-shell-dont-error-on-e.patch >From e204c3a6ccdaf1770db5e931f1116235597a8c0b Mon Sep 17 00:00:00 2001 From: Matt Trzcinski Date: Fri, 30 Dec 2022 11:18:15 -0500 Subject: [PATCH 1/7] test-ob-shell.el: Split test-ob-shell/dont-error-on-empty-results * testing/lisp/test-ob-shell.el (test-ob-shell/dont-error-on-empty-results): Explicitly test handling of empty results. (test-ob-shell/dont-error-on-babel-error): Explicitly test handling of Babel errors. On pass, remove buffers created during test. Original test conflated empty results (a valid Babel return) and Babel errors. --- testing/lisp/test-ob-shell.el | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el index b0d9beff4..fc3ecd3c8 100644 --- a/testing/lisp/test-ob-shell.el +++ b/testing/lisp/test-ob-shell.el @@ -34,12 +34,16 @@ 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]" - (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 -returned empty results." - (should (null (org-babel-execute:sh "ls NoSuchFileOrDirectory.txt" nil)))) + "Empty results should not cause a Lisp error." + (should (null (org-babel-execute:sh "" nil)))) + +(ert-deftest test-ob-shell/dont-error-on-babel-error () + "Errors within Babel execution should not cause Lisp errors." + (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_3118441_1342913871.1672425960069 Content-Type: application/octet-stream; name=0002-test-ob-shell.el-Refactor-test-ob-shell-session.patch Content-Transfer-Encoding: 7bit X-ZM_AttachId: 138917187600760030 Content-Disposition: attachment; filename=0002-test-ob-shell.el-Refactor-test-ob-shell-session.patch >From 6e0012867d8594913cf4783d7afdc109b8307de3 Mon Sep 17 00:00:00 2001 From: Matt Trzcinski Date: Fri, 30 Dec 2022 11:35:10 -0500 Subject: [PATCH 2/7] test-ob-shell.el: Refactor test-ob-shell/session * testing/lisp/test-ob-shell.el (ob-shell/session): Split `ob-shell/session' into `test-ob-shell/session-single-return-returns-string' and `test-ob-shell/session-multiple-returns-returns-list'. (ob-shell/session): Rename comint from to test name. On pass, kill process and remove process buffer. --- testing/lisp/test-ob-shell.el | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el index fc3ecd3c8..b08bf8413 100644 --- a/testing/lisp/test-ob-shell.el +++ b/testing/lisp/test-ob-shell.el @@ -45,18 +45,28 @@ 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"))))) - (should res) - (should (listp res))) - ;; Test multi-line input. - (let ((result (org-babel-execute:sh - "if true \n then \n echo yes \n fi" - '((:session . "yes"))))) +(ert-deftest test-ob-shell/session-single-return-returns-string () + "Sessions with a single result should return a string." + (let* ((session-name "test-ob-shell/session-evaluation-single-return-returns-string") + (kill-buffer-query-functions nil) + (result (org-babel-execute:sh + (format "echo %s" session-name) + `((:session . ,session-name))))) (should result) - (should (string= "yes" result)))) + (if (should (string= session-name result)) + (kill-buffer session-name)))) + +(ert-deftest test-ob-shell/session-multiple-returns-returns-list () + "Sessions with multiple results should return a list." + (let* ((session-name "test-ob-shell/session-multiple-returns-returns-list") + (kill-buffer-query-functions nil) + (result (org-babel-execute:sh + "echo 1; echo 2" + `((:session . ,session-name))))) + (should result) + (should (listp result)) + (if (should (equal '((1) (2)) result)) + (kill-buffer session-name)))) ; A list of tests using the samples in ob-shell-test.org (ert-deftest ob-shell/generic-uses-no-arrays () -- 2.38.1 ------=_Part_3118441_1342913871.1672425960069 Content-Type: application/octet-stream; name=0003-test-ob-shell.el-Refactor-ob-shell-generic-uses-no-a.patch Content-Transfer-Encoding: 7bit X-ZM_AttachId: 138917187600780010 Content-Disposition: attachment; filename=0003-test-ob-shell.el-Refactor-ob-shell-generic-uses-no-a.patch >From d44204d940b81c284102981291433180ca9a438f Mon Sep 17 00:00:00 2001 From: Matt Trzcinski Date: Fri, 30 Dec 2022 11:39:35 -0500 Subject: [PATCH 3/7] test-ob-shell.el: Refactor ob-shell/generic-uses-no-assoc-arrays * test-ob-shell.el (ob-shell/generic-uses-no-assoc-arrays): Split test based on simple versus complex mapping cases, `test-ob-shell/generic-uses-no-assoc-arrays-simple-map' and `test-ob-shell/generic-uses-no-assoc-arrays-3-columns'. Rename prefix from "ob-shell" to "test-ob-shell". (ob-shell/generic-uses-no-assoc-arrays): Move headlines and commentary from `testing/examples/ob-shell-test.org' to docstring. (ob-shell/generic-uses-no-assoc-arrays): Remove dependency on testing/examples/ob-shell-test.org. --- testing/lisp/test-ob-shell.el | 56 +++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el index b08bf8413..57347229e 100644 --- a/testing/lisp/test-ob-shell.el +++ b/testing/lisp/test-ob-shell.el @@ -68,7 +68,6 @@ unless the body of the tangled block does." (if (should (equal '((1) (2)) result)) (kill-buffer session-name)))) -; A list of tests using the samples in ob-shell-test.org (ert-deftest ob-shell/generic-uses-no-arrays () "No arrays for generic" (org-test-at-id "0ba56632-8dc1-405c-a083-c204bae477cf" @@ -81,20 +80,47 @@ unless the body of the tangled block does." (org-babel-next-src-block 2) (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 + (string-join + '("#+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") + "\n") + (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 + (string-join + '("#+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") + "\n") + (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_3118441_1342913871.1672425960069 Content-Type: application/octet-stream; name=0004-Refactor-ob-shell-bash-uses-assoc-arrays.patch Content-Transfer-Encoding: 7bit X-ZM_AttachId: 138917187600790150 Content-Disposition: attachment; filename=0004-Refactor-ob-shell-bash-uses-assoc-arrays.patch >From 8a9f5b29ec6bf09f63bc41dab09781b3456ff2aa Mon Sep 17 00:00:00 2001 From: Matt Trzcinski Date: Fri, 30 Dec 2022 12:36:41 -0500 Subject: [PATCH 4/7] Refactor ob-shell/bash-uses-assoc-arrays * testing/lisp/test-ob-shell.el (ob-shell/bash-uses-assoc-arrays): Split test cases into separate tests, `test-ob-shell/bash-uses-assoc-arrays' and `test-ob-shell/bash-uses-assoc-arrays-with-lists'. Rename prefix from "ob-shell" to "test-ob-shell". (ob-shell/bash-uses-assoc-arrays): Move comments from testing/examples/ob-shell-test.org to docstrings. (ob-shell/bash-uses-assoc-arrays): Remove dependency on testing/examples/ob-shell-test.org. --- testing/lisp/test-ob-shell.el | 61 +++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el index 57347229e..1e4bd6729 100644 --- a/testing/lisp/test-ob-shell.el +++ b/testing/lisp/test-ob-shell.el @@ -119,24 +119,51 @@ as a single string." "#+end_src") "\n") (should - (equal "bread 2 kg spaghetti 20 cm milk 50 dl" - (org-trim (org-babel-execute-src-block)))))) + (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. - (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)))))) +(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 + (string-join + '("#+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") + "\n") + (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 + (string-join + '("#+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") + "\n") + (should + (equal "20 cm" + (org-trim (org-babel-execute-src-block)))))) (ert-deftest ob-shell/simple-list () "Test list variables in shell." -- 2.38.1 ------=_Part_3118441_1342913871.1672425960069 Content-Type: application/octet-stream; name=0005-test-ob-shell.el-Refactor-test-names-and-kill-test-b.patch Content-Transfer-Encoding: 7bit X-ZM_AttachId: 138917187600810140 Content-Disposition: attachment; filename=0005-test-ob-shell.el-Refactor-test-names-and-kill-test-b.patch >From fbdb368efdbedc5b8f5ed6b27f74be060a4c4cb8 Mon Sep 17 00:00:00 2001 From: Matt Trzcinski Date: Fri, 30 Dec 2022 12:39:47 -0500 Subject: [PATCH 5/7] test-ob-shell.el: Refactor test names and kill test buffers * testing/lisp/test-ob-shell.el: (ob-shell/generic-uses-no-arrays): Rename test from `ob-shell/generic-uses-no-arrays' to `test-ob-shell/generic-uses-no-arrays'. (ob-shell/generic-uses-no-arrays): Move comments from testing/examples/ob-shell-test.org to docstring. (ob-shell/generic-uses-no-arrays): Remove dependency on testing/examples/ob-shell-test.org. (ob-shell/bash-uses-arrays): Rename `ob-shell/bash-uses-arrays' to `test-ob-shell/bash-uses-arrays'. (ob-shell/bash-uses-arrays): Move comments from testing/examples/ob-shell-test.org to docstring. (ob-shell/bash-uses-arrays): Remove dependency on testing/examples/ob-shell-test.org. (ob-shell/simple-list): Change test name from `ob-shell/simple-list' to `test-ob-shell/simple-list'. (ob-shell/remote-with-stdin-or-cmdline): Change test name from `ob-shell/remote-with-stdin-or-cmdline' to `test-ob-shell/remote-with-stdin-or-cmdline'. (ob-shell/remote-with-stdin-or-cmdline): On pass, kill buffer created by test. (ob-shell/results-table): Rename `ob-shell/results-table' to `test-ob-shell/results-table'. (ob-shell/results-list): Rename `ob-shell/results-list' to `test-ob-shell/results-list'. (ob-shell/standard-output-after-success): Rename `ob-shell/standard-output-after-success' to `test-ob-shell/standard-output-after-success'. (ob-shell/standard-output-after-failure): Rename `ob-shell/standard-output-after-failure' to `test-ob-shell/standard-output-after-failure'. (ob-shell/standard-output-after-failure): On pass, kill buffer created during test. (ob-shell/error-output-after-success): Rename `ob-shell/error-output-after-success' to `test-ob-shell/error-output-after-success'. (ob-shell/error-output-after-success): On pass, kill buffer created by test. (ob-shell/error-output-after-failure): Rename `ob-shell/error-output-after-failure' to `test-ob-shell/error-output-after-failure'. (ob-shell/error-output-after-failure): On pass, kill buffer created by test. (ob-shell/error-output-after-failure-multiple): Rename `ob-shell/error-output-after-failure-multiple' to `test-ob-shell/error-output-after-failure-multiple'. (ob-shell/error-output-after-failure-multiple): On pass, kill buffer created by test. (ob-shell/exit-code): Rename `ob-shell/exit-code' to `test-ob-shell/exit-code'. (ob-shell/exit-code): On pass, kill buffer created by test. (ob-shell/exit-code-multiple): Rename `ob-shell/exit-code-multiple' to `test-ob-shell/exit-code-multiple'. (ob-shell/exit-code-multiple): On pass, kill buffer created by test. --- testing/lisp/test-ob-shell.el | 234 +++++++++++++++++++++------------- 1 file changed, 146 insertions(+), 88 deletions(-) diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el index 1e4bd6729..2c4491ffa 100644 --- a/testing/lisp/test-ob-shell.el +++ b/testing/lisp/test-ob-shell.el @@ -18,21 +18,23 @@ ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . -;;; Comment: -;; Template test file for Org tests +;;; Comment: -;;; Code: +;;; Requirements: (org-test-for-executable "sh") + (require 'ob-core) + (unless (featurep 'ob-shell) (signal 'missing-test-dependency "Support for Shell code blocks")) +;;; Code: (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" '()))) + (org-babel-expand-body:generic "echo 2" '()))) (should (string-match "^[\n\r][\t ]*[\n\r]" (org-babel-expand-body:generic "\n\necho 2" '())))) @@ -68,16 +70,40 @@ unless the body of the tangled block does." (if (should (equal '((1) (2)) result)) (kill-buffer session-name)))) -(ert-deftest ob-shell/generic-uses-no-arrays () - "No arrays for generic" - (org-test-at-id "0ba56632-8dc1-405c-a083-c204bae477cf" - (org-babel-next-src-block) +(ert-deftest test-ob-shell/generic-uses-no-arrays () + "Test generic serialization of array into a single string." + (org-test-with-temp-text + (string-join + '("#+NAME: sample_array" + "| one |" + "| two |" + "| three |" + "" + "#+begin_src sh :exports results :results output :var array=sample_array" + "echo ${array}" + "" + "#+end_src") + "\n") (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 sees named array as 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 + (string-join + '("#+NAME: sample_array" + "| one |" + "| two |" + "| three |" + "" + "#+begin_src bash :exports results :results output :var array=sample_array" + "echo ${array}" + "" + "#+end_src") + "\n") (should (equal "one" (org-trim (org-babel-execute-src-block)))))) (ert-deftest test-ob-shell/generic-uses-no-assoc-arrays-simple-map () @@ -165,22 +191,31 @@ string. Bash cannot handle lists in associative arrays." (equal "20 cm" (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. +(ert-deftest test-ob-shell/simple-list () + "Test list variables." + ;; 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))))) - ;; On sh, it is a string containing all values. + (org-test-with-temp-text + (string-join + '("#+BEGIN_SRC bash :results output :var l='(1 2)" + "echo ${l[1]}" + "#+END_SRC") + "\n") + (org-trim (org-babel-execute-src-block))))) + + ;; sh: a list 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 + (string-join + '("#+BEGIN_SRC sh :results output :var l='(1 2)" + "echo ${l}" + "#+END_SRC") + "\n") + (org-trim (org-babel-execute-src-block)))))) -(ert-deftest ob-shell/remote-with-stdin-or-cmdline () +(ert-deftest test-ob-shell/remote-with-stdin-or-cmdline () "Test :stdin and :cmdline with a remote directory." ;; We assume `default-directory' is a local directory. (skip-unless (not (memq system-type '(ms-dos windows-nt)))) @@ -227,20 +262,31 @@ string. Bash cannot handle lists in associative arrays." (org-trim (org-babel-execute-src-block)))) (expected (concat "ARGS: --verbose 23 71" "\nhello tramp from " (file-local-name default-directory)))) - (should (equal result expected))))))) + (if (should (equal result expected)) + (kill-matching-buffers (format "\\*tramp/mock\\s-%s\\*" system-name) t t))))))) -(ert-deftest ob-shell/results-table () +(ert-deftest test-ob-shell/results-table () "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))))) - -(ert-deftest ob-shell/results-list () + (org-test-with-temp-text + (string-join + '("#+BEGIN_SRC sh :results table" + "echo 'I \"want\" it all'" + "#+END_SRC") + "\n") + (org-babel-execute-src-block))))) + +(ert-deftest test-ob-shell/results-list () "Test :results list." (org-test-with-temp-text - "#+BEGIN_SRC sh :results list\necho 1\necho 2\necho 3\n#+END_SRC" + (string-join + '("#+BEGIN_SRC sh :results list" + "echo 1" + "echo 2" + "echo 3" + "#+END_SRC") + "\n") (should (equal '((1) (2) (3)) (org-babel-execute-src-block))) @@ -253,86 +299,98 @@ string. Bash cannot handle lists in associative arrays." ;;; Standard output -(ert-deftest ob-shell/standard-output-after-success () +(ert-deftest test-ob-shell/standard-output-after-success () "Test standard output after exiting with a zero code." (should (= 1 (org-babel-execute:sh "echo 1" nil)))) -(ert-deftest ob-shell/standard-output-after-failure () +(ert-deftest test-ob-shell/standard-output-after-failure () "Test standard output after exiting with a non-zero code." - (should (= 1 - (org-babel-execute:sh - "echo 1; exit 2" nil)))) + (if + (should (= 1 + (org-babel-execute:sh + "echo 1; exit 2" nil))) + (kill-buffer "*Org-Babel Error Output*"))) ;;; Standard error -(ert-deftest ob-shell/error-output-after-success () - "Test that standard error shows in the error buffer, alongside the -exit code, after exiting with a zero code." - (should - (string= "1 +(ert-deftest test-ob-shell/error-output-after-success () + "Test that standard error shows in the error buffer, alongside +the exit code, after exiting with a zero code." + (if + (should + (string= "1 [ Babel evaluation exited with code 0 ]" - (progn (org-babel-eval-wipe-error-buffer) - (org-babel-execute:sh - "echo 1 >&2" nil) - (with-current-buffer org-babel-error-buffer-name - (buffer-string)))))) - -(ert-deftest ob-shell/error-output-after-failure () - "Test that standard error shows in the error buffer, alongside the -exit code, after exiting with a non-zero code." - (should - (string= "1 + (progn (org-babel-eval-wipe-error-buffer) + (org-babel-execute:sh + "echo 1 >&2" nil) + (with-current-buffer org-babel-error-buffer-name + (buffer-string))))) + (kill-buffer "*Org-Babel Error Output*"))) + +(ert-deftest test-ob-shell/error-output-after-failure () + "Test that standard error shows in the error buffer, alongside +the exit code, after exiting with a non-zero code." + (if + (should + (string= "1 [ Babel evaluation exited with code 2 ]" - (progn (org-babel-eval-wipe-error-buffer) - (org-babel-execute:sh - "echo 1 >&2; exit 2" nil) - (with-current-buffer org-babel-error-buffer-name - (buffer-string)))))) + (progn (org-babel-eval-wipe-error-buffer) + (org-babel-execute:sh + "echo 1 >&2; exit 2" nil) + (with-current-buffer org-babel-error-buffer-name + (buffer-string))))) + (kill-buffer "*Org-Babel Error Output*"))) -(ert-deftest ob-shell/error-output-after-failure-multiple () +(ert-deftest test-ob-shell/error-output-after-failure-multiple () "Test that multiple standard error strings show in the error buffer, alongside multiple exit codes." - (should - (string= "1 + (if + (should + (string= "1 [ Babel evaluation exited with code 2 ] 3 [ Babel evaluation exited with code 4 ]" - (progn (org-babel-eval-wipe-error-buffer) - (org-babel-execute:sh - "echo 1 >&2; exit 2" nil) - (org-babel-execute:sh - "echo 3 >&2; exit 4" nil) - (with-current-buffer org-babel-error-buffer-name - (buffer-string)))))) + (progn (org-babel-eval-wipe-error-buffer) + (org-babel-execute:sh + "echo 1 >&2; exit 2" nil) + (org-babel-execute:sh + "echo 3 >&2; exit 4" nil) + (with-current-buffer org-babel-error-buffer-name + (buffer-string))))) + (kill-buffer "*Org-Babel Error Output*"))) ;;; Exit codes -(ert-deftest ob-shell/exit-code () +(ert-deftest test-ob-shell/exit-code () "Test that the exit code shows in the error buffer after exiting with a non-zero return code." - (should - (string= "[ Babel evaluation exited with code 1 ]" - (progn (org-babel-eval-wipe-error-buffer) - (org-babel-execute:sh - "exit 1" nil) - (with-current-buffer org-babel-error-buffer-name - (buffer-string)))))) - -(ert-deftest ob-shell/exit-code-multiple () + (if + (should + (string= "[ Babel evaluation exited with code 1 ]" + (progn (org-babel-eval-wipe-error-buffer) + (org-babel-execute:sh + "exit 1" nil) + (with-current-buffer org-babel-error-buffer-name + (buffer-string))))) + (kill-buffer "*Org-Babel Error Output*"))) + +(ert-deftest test-ob-shell/exit-code-multiple () "Test that multiple exit codes show in the error buffer after exiting with a non-zero return code multiple times." - (should - (string= "[ Babel evaluation exited with code 1 ] + (if + (should + (string= "[ Babel evaluation exited with code 1 ] [ Babel evaluation exited with code 2 ]" - (progn (org-babel-eval-wipe-error-buffer) - (org-babel-execute:sh - "exit 1" nil) - (org-babel-execute:sh - "exit 2" nil) - (with-current-buffer org-babel-error-buffer-name - (buffer-string)))))) + (progn (org-babel-eval-wipe-error-buffer) + (org-babel-execute:sh + "exit 1" nil) + (org-babel-execute:sh + "exit 2" nil) + (with-current-buffer org-babel-error-buffer-name + (buffer-string))))) + (kill-buffer "*Org-Babel Error Output*"))) (provide 'test-ob-shell) -- 2.38.1 ------=_Part_3118441_1342913871.1672425960069 Content-Type: application/octet-stream; name=0006-ob-shell-test.org-Remove-ob-shell-test.org.patch Content-Transfer-Encoding: 7bit X-ZM_AttachId: 138917187600840260 Content-Disposition: attachment; filename=0006-ob-shell-test.org-Remove-ob-shell-test.org.patch >From ec1653eed46254fba0596d494da9142fcea6da13 Mon Sep 17 00:00:00 2001 From: Matt Trzcinski Date: Sat, 24 Dec 2022 11:29:06 -0500 Subject: [PATCH 6/7] ob-shell-test.org: Remove ob-shell-test.org * testing/examples/ob-shell-test.org: Delete file File was used by test-ob-shell.el to test ob-shell.el. Tests have been updated to use temporary buffers, rendering ob-shell-test.org unnecessary. --- testing/examples/ob-shell-test.org | 88 ------------------------------ 1 file changed, 88 deletions(-) delete mode 100644 testing/examples/ob-shell-test.org diff --git a/testing/examples/ob-shell-test.org b/testing/examples/ob-shell-test.org deleted file mode 100644 index 2510f4f96..000000000 --- a/testing/examples/ob-shell-test.org +++ /dev/null @@ -1,88 +0,0 @@ -#+Title: a collection of examples for ob-shell tests -#+OPTIONS: ^:nil - -* Sample data structures -#+NAME: sample_array -| one | -| two | -| three | - -#+NAME: sample_mapping_table -| first | one | -| second | two | -| third | three | - -#+NAME: sample_big_table -| bread | 2 | kg | -| spaghetti | 20 | cm | -| milk | 50 | dl | - -* Array tests - :PROPERTIES: - :ID: 0ba56632-8dc1-405c-a083-c204bae477cf - :END: -** Generic shell: no arrays -#+begin_src sh :exports results :results output :var array=sample_array -echo ${array} -#+end_src - -#+RESULTS: -: one two three - -** Bash shell: support for 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. -#+begin_src bash :exports results :results output :var array=sample_array -echo ${array} -#+end_src - -#+RESULTS: -: one - -* Associative array tests (simple map) - :PROPERTIES: - :ID: bec1a5b0-4619-4450-a8c0-2a746b44bf8d - :END: -** Generic shell: no special handing -The shell will see all values as a single string. -#+begin_src sh :exports results :results output :var table=sample_mapping_table -echo ${table} -#+end_src - -#+RESULTS: -: first one second two third three - -** 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. -#+begin_src bash :exports :results output results :var table=sample_mapping_table -echo ${table[second]} -#+end_src - -#+RESULTS: -: two - -* Associative array tests (more than 2 columns) - :PROPERTIES: - :ID: 82320a48-3409-49d7-85c9-5de1c6d3ff87 - :END: -** Generic shell: no special handing -#+begin_src sh :exports results :results output :var table=sample_big_table -echo ${table} -#+end_src - -#+RESULTS: -: bread 2 kg spaghetti 20 cm milk 50 dl - -** 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. -#+begin_src bash :exports results :results output :var table=sample_big_table -echo ${table[spaghetti]} -#+end_src - -#+RESULTS: -: 20 cm - -- 2.38.1 ------=_Part_3118441_1342913871.1672425960069 Content-Type: application/octet-stream; name=0007-test-ob-shell.el-Organize-tests.patch Content-Transfer-Encoding: base64 X-ZM_AttachId: 138917187600870090 Content-Disposition: attachment; filename=0007-test-ob-shell.el-Organize-tests.patch RnJvbSBkNTBmOTQwNzk5ZmI1ZDZmMmRhNTcxMmE2NDIzZTQ5OGRiM2M1MzBkIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBNYXR0IFRyemNpbnNraSA8bWF0dEBleGNhbGFtdXMuY29tPgpE YXRlOiBGcmksIDMwIERlYyAyMDIyIDEzOjAzOjU5IC0wNTAwClN1YmplY3Q6IFtQQVRDSCA3Lzdd IHRlc3Qtb2Itc2hlbGwuZWw6IE9yZ2FuaXplIHRlc3RzCgoqIHRlc3RpbmcvbGlzcC90ZXN0LW9i LXNoZWxsLmVsOgogIC0gR2l2ZSBpbnN0cnVjdGlvbnMgb24gaG93IHRvIHJ1biB0ZXN0cwogIC0g UmVxdWlyZSBgb3JnLXRlc3QnIGV4cGxpY2l0bHkKICAtIEdyb3VwIHRlc3RzIGludG8gc2VjdGlv bnMKICAtIEluc2VydCBgcGFnZS1kZWxpbWl0ZXIncyBiZXR3ZWVuIHNlY3Rpb25zCi0tLQogdGVz dGluZy9saXNwL3Rlc3Qtb2Itc2hlbGwuZWwgfCAxMiArKysrKysrKysrLS0KIDEgZmlsZSBjaGFu Z2VkLCAxMCBpbnNlcnRpb25zKCspLCAyIGRlbGV0aW9ucygtKQoKZGlmZiAtLWdpdCBhL3Rlc3Rp bmcvbGlzcC90ZXN0LW9iLXNoZWxsLmVsIGIvdGVzdGluZy9saXNwL3Rlc3Qtb2Itc2hlbGwuZWwK aW5kZXggMmM0NDkxZmZhLi5kMTI0NGM5ZTQgMTAwNjQ0Ci0tLSBhL3Rlc3RpbmcvbGlzcC90ZXN0 LW9iLXNoZWxsLmVsCisrKyBiL3Rlc3RpbmcvbGlzcC90ZXN0LW9iLXNoZWxsLmVsCkBAIC0xOCwx NyArMTgsMjIgQEAKIDs7IFlvdSBzaG91bGQgaGF2ZSByZWNlaXZlZCBhIGNvcHkgb2YgdGhlIEdO VSBHZW5lcmFsIFB1YmxpYyBMaWNlbnNlCiA7OyBhbG9uZyB3aXRoIHRoaXMgcHJvZ3JhbS4gIElm IG5vdCwgc2VlIDxodHRwczovL3d3dy5nbnUub3JnL2xpY2Vuc2VzLz4uCiAKLQorDAogOzs7IENv bW1lbnQ6CiAKKzs7IFNlZSB0ZXN0aW5nL1JFQURNRSBmb3IgaG93IHRvIHJ1biB0ZXN0cy4KKwor DAogOzs7IFJlcXVpcmVtZW50czoKLShvcmctdGVzdC1mb3ItZXhlY3V0YWJsZSAic2giKQogCiAo cmVxdWlyZSAnb2ItY29yZSkKIAogKHVubGVzcyAoZmVhdHVyZXAgJ29iLXNoZWxsKQogICAoc2ln bmFsICdtaXNzaW5nLXRlc3QtZGVwZW5kZW5jeSAiU3VwcG9ydCBmb3IgU2hlbGwgY29kZSBibG9j a3MiKSkKIAorKG9yZy10ZXN0LWZvci1leGVjdXRhYmxlICJzaCIpCisKKwwKIDs7OyBDb2RlOgog KGVydC1kZWZ0ZXN0IHRlc3Qtb2Itc2hlbGwvZG9udC1pbnNlcnQtc3BhY2VzLW9uLWV4cGFuZGVk LWJvZGllcyAoKQogICAiRXhwYW5kZWQgc2hlbGwgYm9kaWVzIHNob3VsZCBub3Qgc3RhcnQgd2l0 aCBhIGJsYW5rIGxpbmUgdW5sZXNzCkBAIC0yOTcsNiArMzAyLDcgQEAgc3RyaW5nLiBCYXNoIGNh bm5vdCBoYW5kbGUgbGlzdHMgaW4gYXNzb2NpYXRpdmUgYXJyYXlzLiIKICAgICAgICItIDFcbi0g MlxuLSAzXG4iCiAgICAgICAoYnVmZmVyLXN1YnN0cmluZy1uby1wcm9wZXJ0aWVzIChwb2ludCkg KHBvaW50LW1heCkpKSkpKQogCisMCiA7OzsgU3RhbmRhcmQgb3V0cHV0CiAKIChlcnQtZGVmdGVz dCB0ZXN0LW9iLXNoZWxsL3N0YW5kYXJkLW91dHB1dC1hZnRlci1zdWNjZXNzICgpCkBAIC0zMTMs NiArMzE5LDcgQEAgc3RyaW5nLiBCYXNoIGNhbm5vdCBoYW5kbGUgbGlzdHMgaW4gYXNzb2NpYXRp dmUgYXJyYXlzLiIKICAgICAgICAgICAgICAgICAgICJlY2hvIDE7IGV4aXQgMiIgbmlsKSkpCiAg ICAgICAoa2lsbC1idWZmZXIgIipPcmctQmFiZWwgRXJyb3IgT3V0cHV0KiIpKSkKIAorDAogOzs7 IFN0YW5kYXJkIGVycm9yCiAKIChlcnQtZGVmdGVzdCB0ZXN0LW9iLXNoZWxsL2Vycm9yLW91dHB1 dC1hZnRlci1zdWNjZXNzICgpCkBAIC0zNjEsNiArMzY4LDcgQEAgYnVmZmVyLCBhbG9uZ3NpZGUg bXVsdGlwbGUgZXhpdCBjb2Rlcy4iCiAgICAgICAgICAgICAgICAgICAgICAgICAgKGJ1ZmZlci1z dHJpbmcpKSkpKQogICAgICAgKGtpbGwtYnVmZmVyICIqT3JnLUJhYmVsIEVycm9yIE91dHB1dCoi KSkpCiAKKwwKIDs7OyBFeGl0IGNvZGVzCiAKIChlcnQtZGVmdGVzdCB0ZXN0LW9iLXNoZWxsL2V4 aXQtY29kZSAoKQotLSAKMi4zOC4xCgo= ------=_Part_3118441_1342913871.1672425960069--