Skip to content

Commit 95728f7

Browse files
jrngitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c742f87 commit 95728f7

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

t/t7106-reset-unborn-branch.sh

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ test_expect_success 'setup' '
1111
test_expect_success 'reset' '
1212
git add a b &&
1313
git reset &&
14-
test "$(git ls-files)" = ""
14+
15+
>expect &&
16+
git ls-files >actual &&
17+
test_cmp expect actual
1518
'
1619

1720
test_expect_success 'reset HEAD' '
@@ -24,28 +27,42 @@ test_expect_success 'reset $file' '
2427
rm .git/index &&
2528
git add a b &&
2629
git reset a &&
27-
test "$(git ls-files)" = "b"
30+
31+
echo b >expect &&
32+
git ls-files >actual &&
33+
test_cmp expect actual
2834
'
2935

3036
test_expect_success PERL 'reset -p' '
3137
rm .git/index &&
3238
git add a &&
33-
echo y | git reset -p &&
34-
test "$(git ls-files)" = ""
39+
echo y >yes &&
40+
git reset -p <yes &&
41+
42+
>expect &&
43+
git ls-files >actual &&
44+
test_cmp expect actual
3545
'
3646

3747
test_expect_success 'reset --soft is a no-op' '
3848
rm .git/index &&
3949
git add a &&
40-
git reset --soft
41-
test "$(git ls-files)" = "a"
50+
git reset --soft &&
51+
52+
echo a >expect &&
53+
git ls-files >actual &&
54+
test_cmp expect actual
4255
'
4356

4457
test_expect_success 'reset --hard' '
4558
rm .git/index &&
4659
git add a &&
60+
test_when_finished "echo a >a" &&
4761
git reset --hard &&
48-
test "$(git ls-files)" = "" &&
62+
63+
>expect &&
64+
git ls-files >actual &&
65+
test_cmp expect actual &&
4966
test_path_is_missing a
5067
'
5168

0 commit comments

Comments
 (0)