Skip to contentSkip to conversation

Fix expected values of setup tests on Windows

PATCH In review Johannes Sixt 5 participants 12 messages Jun 15, 2016 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

2010/12/31 Johannes Sixt <[email protected]>:

Quoted 4 lines

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?

Signature · 1 line
Duy
#2 lore raw
Quoted 12 lines · Nguyen Thai Ngoc Duy

2010/12/31 Johannes Sixt <[email protected]>:

Quoted 4 lines

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"

Quoted 7 lines

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

#3 lore raw
Quoted 11 lines · Johannes Sixt
Quoted 2 lines · Nguyen Thai Ngoc Duy

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?

#4 lore raw
Quoted 9 lines · Jonathan Nieder
Quoted 8 lines · Johannes Sixt
Quoted 2 lines · Nguyen Thai Ngoc Duy

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

No. When this line is executed:

TEST_DIRECTORY=$(pwd)

Quoted 8 lines
Quoted 2 lines

$(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

#5 lore raw
Quoted 13 lines · Johannes Sixt
Quoted 12 lines · Jonathan Nieder
Quoted 10 lines · Johannes Sixt
Quoted 2 lines · Nguyen Thai Ngoc Duy

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.

Quoted 7 lines
Quoted 5 lines

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.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw

PATCH 2/2 t/README: hint about using $(pwd) rather than $PWD in tests

From: Johannes Sixt <[email protected]>

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.

---
 t/README |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
t/README +6 -0
index 90718b4..f98ebb3 100644
@@ -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.
Signature · 1 line
1.7.4.rc1.1258.g84aa
#8 lore raw

Re: [PATCH 2/2] t/README: hint about using $(pwd) rather than $PWD in tests

Quoted 2 lines · Johannes Sixt

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.

t/README Do: · line 291

Quoted 12 lines
t/README +6 -0
@@ -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.

#9 lore raw

Re: [PATCH 2/2] t/README: hint about using $(pwd) rather than $PWD in tests

Am 1/11/2011 8:54, schrieb Jonathan Nieder:

Quoted 4 lines

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?

Quoted 5 lines

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

#10 lore raw

Re: [PATCH 2/2] t/README: hint about using $(pwd) rather than $PWD in tests

Quoted 11 lines · Johannes Sixt

Am 1/11/2011 8:54, schrieb Jonathan Nieder:

Quoted 4 lines

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.

Quoted 3 lines

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.

Quoted 7 lines
Quoted 5 lines

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.

#11 lore raw

Re: [PATCH 2/2] t/README: hint about using $(pwd) rather than $PWD in tests

Am 1/11/2011 9:37, schrieb Jonathan Nieder:

Quoted 2 lines

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.

Quoted 10 lines
Quoted 7 lines
Quoted 5 lines

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.

Quoted 2 lines

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

#12 lore raw

Re: [PATCH 2/2] t/README: hint about using $(pwd) rather than $PWD in tests

Quoted 7 lines · Johannes Sixt

Am 1/11/2011 9:37, schrieb Jonathan Nieder:

Quoted 2 lines

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.

#13 lore raw
In reply to Johannes Sixt
Quoted 5 lines · Johannes Sixt
Quoted 2 lines

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

No. When this line is executed:

Quoted 8 lines

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.

Signature · 1 line
Duy