Re: [PATCH v2 08/10] replace: add tests for --edit
- From
Jeff King <peff@peff.net>
- Date
- May 17, 2014, 07:14 UTC
- Message-ID
- <20140517071410.GE13003@sigill.intra.peff.net>
- In-Reply-To
- <20140517064133.18932.74476.chriscool@tuxfamily.org>
On Sat, May 17, 2014 at 08:41:30AM +0200, Christian Couder wrote:
> Signed-off-by: Christian Couder <chriscool@tuxfamily.org> > --- > t/t6050-replace.sh | 29 +++++++++++++++++++++++++++++ > 1 file changed, 29 insertions(+)
Yay, tests.
Show 8 quoted lines
> +test_expect_success 'setup a fake editor' ' > + cat >fakeeditor <<-\EOF && > + #!/bin/sh > + sed -e "s/A U Thor/A fake Thor/" "$1" >"$1.new" > + mv "$1.new" "$1" > + EOF > + chmod +x fakeeditor > +'
Please use write_script, like:
test_expect_success 'setup a fake editor' ' write_script fakeeditor <<-\EOF sed -e "s/A U Thor/A fake Thor/" "$1" >"$1.new" mv "$1.new" "$1" EOF '
which will use the $(SHELL_PATH) shebang. It doesn't matter for such a simple script here (which even a broken #!/bin/sh could manage), but in general, I think we're trying to set it consistently.
You could also &&-chain the commands in your fakeeditor script, though I find it unlikely that sed will fail.
> +test_expect_success '--edit with and without already replaced object' ' > + GIT_EDITOR=./fakeeditor test_must_fail git replace --edit "$PARA3" &&
Unfortunately it's not portable to do a one-shot environment variable on a shell function like this; some shells leave the variable set after the function returns. We've been using:
test_must_fail env GIT_EDITOR=./fakeeditor git ...
The regular
GIT_EDITOR=./fakeeditor git ...
ones are OK.
-Peff