# Re: [PATCH] Fix expected values of setup tests on Windows

12 messages from 2010-12-31 to 2011-01-11. Participants: Nguyen Thai Ngoc Duy, Johannes Sixt, Jonathan Nieder, Junio C Hamano.
Thread: https://gitlist.dev/t/26167

## Nguyen Thai Ngoc Duy, 2010-12-31 13:00

Subject: Re: [PATCH] Fix expected values of setup tests on Windows
Message-ID: <AANLkTi=uCCfBFBpC=+V9RpaXRXiiPYp-tZXBxAVNB7+e@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTi%3DuCCfBFBpC%3D%2BV9RpaXRXiiPYp-tZXBxAVNB7%2Be%40mail.gmail.com
In-Reply-To: <201012302205.13728.j6t@kdbg.org>

```
2010/12/31 Johannes Sixt <j6t@kdbg.org>:
> On Windows, bash stores absolute path names in shell variables in POSIX
> format that begins with a slash, rather than in drive-letter format; such
> a value is converted to the latter format when it is passed to a non-MSYS
> program such as git.

Hmm.. from test-lib.sh:

TEST_DIRECTORY=$(pwd)
test="trash directory.$(basename "$0" .sh)"
TRASH_DIRECTORY="$TEST_DIRECTORY/$test"

I'm just curious how these lines make $TRASH_DIRECTORY in POSIX format, while

here=$(pwd)

in your patch does not. Does bash auto convert value in
TRASH_DIRECTORY="$TE..." line?
-- 
Duy

```

## Johannes Sixt, 2010-12-31 16:11

Subject: Re: [PATCH] Fix expected values of setup tests on Windows
Message-ID: <201012311711.06989.j6t@kdbg.org>
URL: https://gitlist.dev/e/201012311711.06989.j6t%40kdbg.org
In-Reply-To: <AANLkTi=uCCfBFBpC=+V9RpaXRXiiPYp-tZXBxAVNB7+e@mail.gmail.com>

```
On Freitag, 31. Dezember 2010, Nguyen Thai Ngoc Duy wrote:
> 2010/12/31 Johannes Sixt <j6t@kdbg.org>:
> > On Windows, bash stores absolute path names in shell variables in POSIX
> > format that begins with a slash, rather than in drive-letter format; such
> > a value is converted to the latter format when it is passed to a non-MSYS
> > program such as git.
>
> Hmm.. from test-lib.sh:
>
> TEST_DIRECTORY=$(pwd)
> test="trash directory.$(basename "$0" .sh)"
> TRASH_DIRECTORY="$TEST_DIRECTORY/$test"
>
> I'm just curious how these lines make $TRASH_DIRECTORY in POSIX format,
> while
>
> here=$(pwd)
>
> in your patch does not. Does bash auto convert value in
> TRASH_DIRECTORY="$TE..." line?

No. When this line is executed:

TEST_DIRECTORY=$(pwd)

$(pwd) still has its default behavior to return the POSIX style path. pwd is 
redefined to pwd -W only later.

I'm hesitant to redefine pwd earlier in test-lib.sh, though, because we would 
have to audit all uses of TEST_DIRECTORY for whether POSIX style paths or 
drive-letter paths are needed.

-- Hannes

```

## Jonathan Nieder, 2010-12-31 20:30

Subject: Re: [PATCH] Fix expected values of setup tests on Windows
Message-ID: <20101231203019.GC5898@burratino>
URL: https://gitlist.dev/e/20101231203019.GC5898%40burratino
In-Reply-To: <201012311711.06989.j6t@kdbg.org>

```
Johannes Sixt wrote:
> On Freitag, 31. Dezember 2010, Nguyen Thai Ngoc Duy wrote:

>> in your patch does not. Does bash auto convert value in
>> TRASH_DIRECTORY="$TE..." line?
>
> No. When this line is executed:
> 
> TEST_DIRECTORY=$(pwd)
> 
> $(pwd) still has its default behavior to return the POSIX style path. pwd is 
> redefined to pwd -W only later.

Would it make sense to change it to

 TEST_DIRECTORY=$PWD

for clarity and robustness against code movement, then?

```

## Johannes Sixt, 2010-12-31 22:21

Subject: Re: [PATCH] Fix expected values of setup tests on Windows
Message-ID: <201012312321.31294.j6t@kdbg.org>
URL: https://gitlist.dev/e/201012312321.31294.j6t%40kdbg.org
In-Reply-To: <20101231203019.GC5898@burratino>

```
On Freitag, 31. Dezember 2010, Jonathan Nieder wrote:
> Johannes Sixt wrote:
> > On Freitag, 31. Dezember 2010, Nguyen Thai Ngoc Duy wrote:
> >> in your patch does not. Does bash auto convert value in
> >> TRASH_DIRECTORY="$TE..." line?
> >
> > No. When this line is executed:
> >
> > TEST_DIRECTORY=$(pwd)
> >
> > $(pwd) still has its default behavior to return the POSIX style path. pwd
> > is redefined to pwd -W only later.
>
> Would it make sense to change it to
>
>  TEST_DIRECTORY=$PWD
>
> for clarity and robustness against code movement, then?

Yes, that would make sense.

-- Hannes

```

## Nguyen Thai Ngoc Duy, 2011-01-01 03:46

Subject: Re: [PATCH] Fix expected values of setup tests on Windows
Message-ID: <AANLkTinWdGDtxPk24OBQnJP8fdHW9gYNDn46YKRGTWoB@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTinWdGDtxPk24OBQnJP8fdHW9gYNDn46YKRGTWoB%40mail.gmail.com
In-Reply-To: <201012311711.06989.j6t@kdbg.org>

```
On Fri, Dec 31, 2010 at 11:11 PM, Johannes Sixt <j6t@kdbg.org> wrote:
>> in your patch does not. Does bash auto convert value in
>> TRASH_DIRECTORY="$TE..." line?
>
> No. When this line is executed:
>
> TEST_DIRECTORY=$(pwd)
>
> $(pwd) still has its default behavior to return the POSIX style path. pwd is
> redefined to pwd -W only later.
>
> I'm hesitant to redefine pwd earlier in test-lib.sh, though, because we would
> have to audit all uses of TEST_DIRECTORY for whether POSIX style paths or
> drive-letter paths are needed.

Ah I missed that. Thanks. Ack from me.
-- 
Duy

```

## Junio C Hamano, 2011-01-02 01:31

Subject: Re: [PATCH] Fix expected values of setup tests on Windows
Message-ID: <7v62u8hz01.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v62u8hz01.fsf%40alter.siamese.dyndns.org
In-Reply-To: <201012312321.31294.j6t@kdbg.org>

```
Johannes Sixt <j6t@kdbg.org> writes:

> On Freitag, 31. Dezember 2010, Jonathan Nieder wrote:
>> Johannes Sixt wrote:
>> > On Freitag, 31. Dezember 2010, Nguyen Thai Ngoc Duy wrote:
>> >> in your patch does not. Does bash auto convert value in
>> >> TRASH_DIRECTORY="$TE..." line?
>> >
>> > No. When this line is executed:
>> >
>> > TEST_DIRECTORY=$(pwd)
>> >
>> > $(pwd) still has its default behavior to return the POSIX style path. pwd
>> > is redefined to pwd -W only later.
>>
>> Would it make sense to change it to
>>
>>  TEST_DIRECTORY=$PWD
>>
>> for clarity and robustness against code movement, then?
>
> Yes, that would make sense.

It will be very much appreciated to add a few sentences to clarify this to
"Do's and don'ts" section of t/README if you are re-rolling this.  Thanks.

```

## Johannes Sixt, 2011-01-11 07:44

Subject: [PATCH 2/2] t/README: hint about using $(pwd) rather than $PWD in tests
Message-ID: <4D2C0A5E.7090708@viscovery.net>
URL: https://gitlist.dev/e/4D2C0A5E.7090708%40viscovery.net
In-Reply-To: <4D2C09D7.3070700@viscovery.net>

```
From: Johannes Sixt <j6t@kdbg.org>

This adds just a "do it this way" instruction without a lot of explanation,
because the details are too complex to be explained at this point.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
---
 t/README |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/t/README b/t/README
index 90718b4..f98ebb3 100644
--- a/t/README
+++ b/t/README
@@ -283,6 +283,12 @@ Do:
    Tests that are likely to smoke out future regressions are better
    than tests that just inflate the coverage metrics.
 
+ - When a test checks for an absolute path that a git command generated,
+   construct the expected value using $(pwd) rather than $PWD,
+   $TEST_DIRECTORY, or $TRASH_DIRECTORY. It makes a difference on
+   Windows, where the shell (MSYS bash) mangles absolute path names.
+   For details, see the commit message of 4114156ae9.
+
 Don't:
 
  - exit() within a <script> part.
-- 
1.7.4.rc1.1258.g84aa

```

## Jonathan Nieder, 2011-01-11 07:54

Subject: Re: [PATCH 2/2] t/README: hint about using $(pwd) rather than $PWD in tests
Message-ID: <20110111075441.GB9445@burratino>
URL: https://gitlist.dev/e/20110111075441.GB9445%40burratino
In-Reply-To: <4D2C0A5E.7090708@viscovery.net>

```
Johannes Sixt wrote:

> This adds just a "do it this way" instruction without a lot of explanation,
> because the details are too complex to be explained at this point.

Thanks, looks very useful.

> --- a/t/README
> +++ b/t/README
> @@ -283,6 +283,12 @@ Do:
>     Tests that are likely to smoke out future regressions are better
>     than tests that just inflate the coverage metrics.
>  
> + - When a test checks for an absolute path that a git command generated,
> +   construct the expected value using $(pwd) rather than $PWD,
> +   $TEST_DIRECTORY, or $TRASH_DIRECTORY. It makes a difference on
> +   Windows, where the shell (MSYS bash) mangles absolute path names.
> +   For details, see the commit message of 4114156ae9.
> +

Perhaps it is also worth explaining the cases where $PWD is needed?

	By contrast, when a passing a path to git or constructing a URL,
	use $PWD.  It makes a difference on Windows, where

	 - $(pwd) is a Windows-style path such as git might output, and
	 - $PWD is a Unix-style path that the shell (MSYS bash) will
	   mangle before passing to native apps like git.

```

## Johannes Sixt, 2011-01-11 08:15

Subject: Re: [PATCH 2/2] t/README: hint about using $(pwd) rather than $PWD in tests
Message-ID: <4D2C11A5.4050709@viscovery.net>
URL: https://gitlist.dev/e/4D2C11A5.4050709%40viscovery.net
In-Reply-To: <20110111075441.GB9445@burratino>

```
Am 1/11/2011 8:54, schrieb Jonathan Nieder:
> Perhaps it is also worth explaining the cases where $PWD is needed?
>
> 	By contrast, when a passing a path to git or constructing a URL,
> 	use $PWD.

The first part of the "or" is not true: you can pass the result of $(pwd)
to a command, and it means the same as $PWD; I would even recommend
against $PWD so that a reader does not have to wonder "why pass $PWD, but
check for $(pwd)?"

The second part I don't know whether it is true: I haven't noticed a
pattern where people did it the wrong way, therefore, I'don't even know
whether $PWD is really *always* required. Do *you* know?

>       It makes a difference on Windows, where
> 
> 	 - $(pwd) is a Windows-style path such as git might output, and
> 	 - $PWD is a Unix-style path that the shell (MSYS bash) will
> 	   mangle before passing to native apps like git.

This information is already included by reference to 4114156ae9.

-- Hannes

```

## Jonathan Nieder, 2011-01-11 08:37

Subject: Re: [PATCH 2/2] t/README: hint about using $(pwd) rather than $PWD in tests
Message-ID: <20110111083729.GD9445@burratino>
URL: https://gitlist.dev/e/20110111083729.GD9445%40burratino
In-Reply-To: <4D2C11A5.4050709@viscovery.net>

```
Johannes Sixt wrote:
> Am 1/11/2011 8:54, schrieb Jonathan Nieder:

>> Perhaps it is also worth explaining the cases where $PWD is needed?
>>
>> 	By contrast, when a passing a path to git or constructing a URL,
>> 	use $PWD.
>
> The first part of the "or" is not true: you can pass the result of $(pwd)
> to a command, and it means the same as $PWD; I would even recommend
> against $PWD so that a reader does not have to wonder "why pass $PWD, but
> check for $(pwd)?"

I _think_ that passing $PWD always gives the right result.  By
contrast, constructions like

	PATH=$(pwd)/bin:$PATH

break iirc.

I suspect that the reader will end up wondering "why does this have to
be so complicated" no matter what.

> The second part I don't know whether it is true: I haven't noticed a
> pattern where people did it the wrong way, therefore, I'don't even know
> whether $PWD is really *always* required. Do *you* know?

24f1136 is one example.  I don't know of any utility that treats

	file://c:/foo/bar/baz

as a URL representing a resource on localhost (and msys bash has no
rewriting rule for it), so in that particular case
(file://$directory), $PWD really does seem to be always required.

>>       It makes a difference on Windows, where
>>
>> 	 - $(pwd) is a Windows-style path such as git might output, and
>> 	 - $PWD is a Unix-style path that the shell (MSYS bash) will
>> 	   mangle before passing to native apps like git.
>
> This information is already included by reference to 4114156ae9.

... but if we can summarize it nicely, we can save the reader a
step, no?

Anyway, what you have already written is useful; clearing up these
details would just be icing on the top.

```

## Johannes Sixt, 2011-01-11 08:54

Subject: Re: [PATCH 2/2] t/README: hint about using $(pwd) rather than $PWD in tests
Message-ID: <4D2C1AAE.1040002@viscovery.net>
URL: https://gitlist.dev/e/4D2C1AAE.1040002%40viscovery.net
In-Reply-To: <20110111083729.GD9445@burratino>

```
Am 1/11/2011 9:37, schrieb Jonathan Nieder:
> I suspect that the reader will end up wondering "why does this have to
> be so complicated" no matter what.

Unfortunately, yes. Therefore, I'd like to keep the paragraph minimal,
focused on how expected values should be constructed, which is where
errors will happen primarily.

>>>       It makes a difference on Windows, where
>>>
>>> 	 - $(pwd) is a Windows-style path such as git might output, and
>>> 	 - $PWD is a Unix-style path that the shell (MSYS bash) will
>>> 	   mangle before passing to native apps like git.
>>
>> This information is already included by reference to 4114156ae9.
> 
> ... but if we can summarize it nicely, we can save the reader a
> step, no?

I don't think so: it's not complete enough. Readers will ask: "So what?"
Digging archives or a three paragraph follow-up explanation on the ML will
be required anyway.

> Anyway, what you have already written is useful; clearing up these
> details would just be icing on the top.

OK, thanks for a review.

-- Hannes

```

## Junio C Hamano, 2011-01-11 17:47

Subject: Re: [PATCH 2/2] t/README: hint about using $(pwd) rather than $PWD in tests
Message-ID: <7vmxn749k5.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vmxn749k5.fsf%40alter.siamese.dyndns.org
In-Reply-To: <4D2C1AAE.1040002@viscovery.net>

```
Johannes Sixt <j.sixt@viscovery.net> writes:

> Am 1/11/2011 9:37, schrieb Jonathan Nieder:
>> I suspect that the reader will end up wondering "why does this have to
>> be so complicated" no matter what.
>
> Unfortunately, yes. Therefore, I'd like to keep the paragraph minimal,
> focused on how expected values should be constructed, which is where
> errors will happen primarily.

I really was hoping for something simple like "never use $PWD" myself,
though X-<.

Anyway, will queue for 1.7.4.  Thanks.

```
