reset test: modernize style
authorJonathan Nieder <jrnieder@gmail.com>
Sat, 24 Aug 2013 20:34:14 +0000 (13:34 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 25 Aug 2013 06:58:44 +0000 (23:58 -0700)
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>
t/t7106-reset-unborn-branch.sh
index 499cd88c8fb20516212193d8a4353991e2a1dbed..af00ab4d88cc75ec720e31da3a0d5d3a1ef8df40 100755 (executable)
@@ -11,7 +11,10 @@ test_expect_success 'setup' '
 test_expect_success 'reset' '
        git add a b &&
        git reset &&
-       test "$(git ls-files)" = ""
+
+       >expect &&
+       git ls-files >actual &&
+       test_cmp expect actual
 '
 
 test_expect_success 'reset HEAD' '
@@ -24,28 +27,42 @@ test_expect_success 'reset $file' '
        rm .git/index &&
        git add a b &&
        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' '
        rm .git/index &&
        git add a &&
-       echo y | git reset -p &&
-       test "$(git ls-files)" = ""
+       echo y >yes &&
+       git reset -p <yes &&
+
+       >expect &&
+       git ls-files >actual &&
+       test_cmp expect actual
 '
 
 test_expect_success 'reset --soft is a no-op' '
        rm .git/index &&
        git add a &&
-       git reset --soft
-       test "$(git ls-files)" = "a"
+       git reset --soft &&
+
+       echo a >expect &&
+       git ls-files >actual &&
+       test_cmp expect actual
 '
 
 test_expect_success 'reset --hard' '
        rm .git/index &&
        git add a &&
+       test_when_finished "echo a >a" &&
        git reset --hard &&
-       test "$(git ls-files)" = "" &&
+
+       >expect &&
+       git ls-files >actual &&
+       test_cmp expect actual &&
        test_path_is_missing a
 '