Re: [PATCH] t7502-commit.sh: test_must_fail doesn't work with inline environment variables
- From
Brandon Casey <casey@nrlssc.navy.mil>
- Date
- Jun 19, 2008, 18:07 UTC
- Message-ID
- <frLVfPcFTL8gWg3cEzx3q-MMBWxW3Ts2EnBH2U39k5_QFQTfThtN-A@cipher.nrlssc.navy.mil>
- In-Reply-To
- <20080619175639.GA1604@glandium.org>
Mike Hommey wrote:
Show 12 quoted lines
> On Thu, Jun 19, 2008 at 12:44:23PM -0500, Brandon Casey wrote: >> Mike Hommey wrote: >>> On Thu, Jun 19, 2008 at 12:32:02PM -0500, Brandon Casey wrote: >>>> - test_must_fail GIT_EDITOR="$(pwd)/.git/FAKE_EDITOR" git commit && >>>> + # We intentionally do not use test_must_fail on the next line since the >>>> + # mechanism does not work when setting environment variables inline >>>> + ! GIT_EDITOR="$(pwd)/.git/FAKE_EDITOR" git commit && >>> Doesn't GIT_EDITOR="$(pwd)/.git/FAKE_EDITOR" test_must_fail git commit >>> work ? >> That leaves GIT_EDITOR set to the new value after the command completes. > > It really shouldn't.
The change you suggested is also what I tried first. Looks like it depends on the shell. On my system /bin/sh is a symlink to /bin/bash and that is the behavior I observed. On other shells the assignment is not passed to the environment of the called procedure at all.
Here is an example script:
#!/bin/sh
test_must_fail () {
"$@"
test $? -gt 0 -a $? -le 129
}
foo='wo adrian'
foo='yo adrian' test_must_fail sh -c 'echo foo: $foo'
echo "foo: $foo"When /bin/sh is a symlink to bash, I get:
foo: yo adrian foo: yo adrian
If I change #!/bin/sh to #!/bin/bash I get what is expected:
foo: yo adrian foo: wo adrian
#!/bin/ksh foo: foo: yo adrian
#!/bin/dash
foo: foo: yo adrian
-brandon