diff mbox series

[1/2] test-lib-functions: use user's SHELL, HOME and TERM for 'test_pause'

Message ID bf916ad98ccc1526f5298d1c3e1740cabad093af.1629393395.git.gitgitgadget@gmail.com (mailing list archive)
State Superseded
Headers show
Series test-lib-functions.sh: keep user's HOME, TERM and SHELL for 'test_pause' and 'debug' | expand

Commit Message

Philippe Blain Aug. 19, 2021, 5:16 p.m. UTC
From: Philippe Blain <levraiphilippeblain@gmail.com>

The 'test_pause' function, which is designed to help interactive
debugging and exploration of tests, currently inherits the value of HOME
and TERM set by 'test-lib.sh': HOME="$TRASH_DIRECTORY" and TERM=dumb. It
also invokes the shell defined by SHELL_PATH, which defaults to /bin/sh.

Changing the value of HOME means that any customization configured in a
developers' shell startup files and any Git aliases defined in their
global Git configuration file are not available in the shell invoked by
'test_pause'.

Changing the value of TERM to 'dumb' means that colored output
is disabled for all commands in that shell.

Using /bin/sh as the shell invoked by 'test_pause' is not ideal since
some platforms (i.e. Debian and derivatives) use Dash as /bin/sh, and
this shell is usually compiled without readline support, which makes for
a poor interactive command line experience.

To make the interactive command line experience in the shell invoked by
'test_pause' more pleasant, save the values of HOME and TERM in
USER_HOME and USER_TERM before changing them in test-lib.sh, and use
these variables to invoke the shell in 'test_pause'. Also, invoke SHELL
instead of SHELL_PATH, so that developer's interactive shell is used.

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
---
 t/test-lib-functions.sh | 2 +-
 t/test-lib.sh           | 6 ++++--
 2 files changed, 5 insertions(+), 3 deletions(-)

Comments

Carlo Marcelo Arenas Belón Aug. 20, 2021, 3:08 a.m. UTC | #1
On Thu, Aug 19, 2021 at 10:17 AM Philippe Blain via GitGitGadget
<gitgitgadget@gmail.com> wrote:
>
> From: Philippe Blain <levraiphilippeblain@gmail.com>
>
> The 'test_pause' function, which is designed to help interactive
> debugging and exploration of tests, currently inherits the value of HOME
> and TERM set by 'test-lib.sh': HOME="$TRASH_DIRECTORY" and TERM=dumb. It
> also invokes the shell defined by SHELL_PATH, which defaults to /bin/sh.

that is a bug, it should have been TEST_SHELL_PATH instead.

goes without saying, that if you don't really need that shell for your
interactive session, nothing prevents you from calling bash and
resetting TERM or even HOME as needed

Carlo
Philippe Blain Aug. 20, 2021, 12:14 p.m. UTC | #2
Hi Carlo,

Le 2021-08-19 à 23:08, Carlo Arenas a écrit :
> On Thu, Aug 19, 2021 at 10:17 AM Philippe Blain via GitGitGadget
> <gitgitgadget@gmail.com> wrote:
>>
>> From: Philippe Blain <levraiphilippeblain@gmail.com>
>>
>> The 'test_pause' function, which is designed to help interactive
>> debugging and exploration of tests, currently inherits the value of HOME
>> and TERM set by 'test-lib.sh': HOME="$TRASH_DIRECTORY" and TERM=dumb. It
>> also invokes the shell defined by SHELL_PATH, which defaults to /bin/sh.
> 
> that is a bug, it should have been TEST_SHELL_PATH instead.

Right. I'll make that change unconditionnally as a preparatory step.

> 
> goes without saying, that if you don't really need that shell for your
> interactive session, nothing prevents you from calling bash and
> resetting TERM or even HOME as needed

Yes. I'm just trying to streamline to experience :)
diff mbox series

Patch

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index e28411bb75a..662cfc4c3e0 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -139,7 +139,7 @@  test_tick () {
 # Be sure to remove all invocations of this command before submitting.
 
 test_pause () {
-	"$SHELL_PATH" <&6 >&5 2>&7
+	TERM="$USER_TERM" HOME="$USER_HOME" "$SHELL" <&6 >&5 2>&7
 }
 
 # Wrap git with a debugger. Adding this to a command can make it easier
diff --git a/t/test-lib.sh b/t/test-lib.sh
index abcfbed6d61..132618991e2 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -585,8 +585,9 @@  else
 	}
 fi
 
+USER_TERM="$TERM"
 TERM=dumb
-export TERM
+export TERM USER_TERM
 
 error () {
 	say_color error "error: $*"
@@ -1380,9 +1381,10 @@  then
 fi
 
 # Last-minute variable setup
+USER_HOME="$HOME"
 HOME="$TRASH_DIRECTORY"
 GNUPGHOME="$HOME/gnupg-home-not-used"
-export HOME GNUPGHOME
+export HOME GNUPGHOME USER_HOME
 
 # Test repository
 rm -fr "$TRASH_DIRECTORY" || {