reset test: modernize style

Avoid command substitution and pipes to ensure that the exit status
from each git command is tested (and in particular that any segfaults
are caught).

Maintain the test setup (no commits, one file named "a", another named
"b") even after the last test, to make it easier to rearrange tests or
add new tests after the last in the future.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jonathan Nieder 2013-08-24 13:34:14 -07:00 committed by Junio C Hamano
parent c742f870ce
commit 95728f74b1

View File

@ -11,7 +11,10 @@ test_expect_success 'setup' '
test_expect_success 'reset' ' test_expect_success 'reset' '
git add a b && git add a b &&
git reset && git reset &&
test "$(git ls-files)" = ""
>expect &&
git ls-files >actual &&
test_cmp expect actual
' '
test_expect_success 'reset HEAD' ' test_expect_success 'reset HEAD' '
@ -24,28 +27,42 @@ test_expect_success 'reset $file' '
rm .git/index && rm .git/index &&
git add a b && git add a b &&
git reset a && git reset a &&
test "$(git ls-files)" = "b"
echo b >expect &&
git ls-files >actual &&
test_cmp expect actual
' '
test_expect_success PERL 'reset -p' ' test_expect_success PERL 'reset -p' '
rm .git/index && rm .git/index &&
git add a && git add a &&
echo y | git reset -p && echo y >yes &&
test "$(git ls-files)" = "" git reset -p <yes &&
>expect &&
git ls-files >actual &&
test_cmp expect actual
' '
test_expect_success 'reset --soft is a no-op' ' test_expect_success 'reset --soft is a no-op' '
rm .git/index && rm .git/index &&
git add a && git add a &&
git reset --soft git reset --soft &&
test "$(git ls-files)" = "a"
echo a >expect &&
git ls-files >actual &&
test_cmp expect actual
' '
test_expect_success 'reset --hard' ' test_expect_success 'reset --hard' '
rm .git/index && rm .git/index &&
git add a && git add a &&
test_when_finished "echo a >a" &&
git reset --hard && git reset --hard &&
test "$(git ls-files)" = "" &&
>expect &&
git ls-files >actual &&
test_cmp expect actual &&
test_path_is_missing a test_path_is_missing a
' '