]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t3905: move all commands into test cases
authorDenton Liu <liu.denton@gmail.com>
Tue, 9 Feb 2021 07:28:49 +0000 (23:28 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 11 Feb 2021 21:34:58 +0000 (13:34 -0800)
In order to modernize the tests, move commands that currently run
outside of test cases into a test case. Where possible, clean up files
that are produced using test_when_finished() but in the case where files
persist over multiple test cases, create a new test case to perform
cleanup.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t3905-stash-include-untracked.sh

index 1d416944b778a28028425b4cabcb121556a698fe..892a2c805748f097f6c749ea86c7bbf022c05bf2 100755 (executable)
@@ -25,48 +25,48 @@ test_expect_success 'stash save --include-untracked some dirty working directory
        git diff-index --cached --quiet HEAD
 '
 
-cat >expect <<EOF
-?? actual
-?? expect
-EOF
-
 test_expect_success 'stash save --include-untracked cleaned the untracked files' '
+       cat >expect <<-EOF &&
+       ?? actual
+       ?? expect
+       EOF
+
        git status --porcelain >actual &&
        test_cmp expect actual
 '
 
-tracked=$(git rev-parse --short $(echo 1 | git hash-object --stdin))
-untracked=$(git rev-parse --short $(echo untracked | git hash-object --stdin))
-cat >expect.diff <<EOF
-diff --git a/HEAD b/HEAD
-new file mode 100644
-index 0000000..$tracked
---- /dev/null
-+++ b/HEAD
-@@ -0,0 +1 @@
-+1
-diff --git a/file2 b/file2
-new file mode 100644
-index 0000000..$tracked
---- /dev/null
-+++ b/file2
-@@ -0,0 +1 @@
-+1
-diff --git a/untracked/untracked b/untracked/untracked
-new file mode 100644
-index 0000000..$untracked
---- /dev/null
-+++ b/untracked/untracked
-@@ -0,0 +1 @@
-+untracked
-EOF
-cat >expect.lstree <<EOF
-HEAD
-file2
-untracked
-EOF
-
 test_expect_success 'stash save --include-untracked stashed the untracked files' '
+       tracked=$(git rev-parse --short $(echo 1 | git hash-object --stdin)) &&
+       untracked=$(git rev-parse --short $(echo untracked | git hash-object --stdin)) &&
+       cat >expect.diff <<-EOF &&
+       diff --git a/HEAD b/HEAD
+       new file mode 100644
+       index 0000000..$tracked
+       --- /dev/null
+       +++ b/HEAD
+       @@ -0,0 +1 @@
+       +1
+       diff --git a/file2 b/file2
+       new file mode 100644
+       index 0000000..$tracked
+       --- /dev/null
+       +++ b/file2
+       @@ -0,0 +1 @@
+       +1
+       diff --git a/untracked/untracked b/untracked/untracked
+       new file mode 100644
+       index 0000000..$untracked
+       --- /dev/null
+       +++ b/untracked/untracked
+       @@ -0,0 +1 @@
+       +untracked
+       EOF
+       cat >expect.lstree <<-EOF &&
+       HEAD
+       file2
+       untracked
+       EOF
+
        test_path_is_missing file2 &&
        test_path_is_missing untracked &&
        test_path_is_missing HEAD &&
@@ -83,18 +83,21 @@ test_expect_success 'stash save --patch --all fails' '
        test_must_fail git stash --patch --all
 '
 
-git clean --force --quiet
+test_expect_success 'clean up untracked/untracked file to prepare for next tests' '
+       git clean --force --quiet
 
-cat >expect <<EOF
- M file
-?? HEAD
-?? actual
-?? expect
-?? file2
-?? untracked/
-EOF
+'
 
 test_expect_success 'stash pop after save --include-untracked leaves files untracked again' '
+       cat >expect <<-EOF &&
+        M file
+       ?? HEAD
+       ?? actual
+       ?? expect
+       ?? file2
+       ?? untracked/
+       EOF
+
        git stash pop &&
        git status --porcelain >actual &&
        test_cmp expect actual &&
@@ -102,7 +105,9 @@ test_expect_success 'stash pop after save --include-untracked leaves files untra
        test untracked = "$(cat untracked/untracked)"
 '
 
-git clean --force --quiet -d
+test_expect_success 'clean up untracked/ directory to prepare for next tests' '
+       git clean --force --quiet -d
+'
 
 test_expect_success 'stash save -u dirty index' '
        echo 4 >file3 &&
@@ -111,25 +116,24 @@ test_expect_success 'stash save -u dirty index' '
        git stash -u
 '
 
-blob=$(git rev-parse --short $(echo 4 | git hash-object --stdin))
-cat >expect <<EOF
-diff --git a/file3 b/file3
-new file mode 100644
-index 0000000..$blob
---- /dev/null
-+++ b/file3
-@@ -0,0 +1 @@
-+4
-EOF
-
 test_expect_success 'stash save --include-untracked dirty index got stashed' '
+       blob=$(git rev-parse --short $(echo 4 | git hash-object --stdin)) &&
+       cat >expect <<-EOF &&
+       diff --git a/file3 b/file3
+       new file mode 100644
+       index 0000000..$blob
+       --- /dev/null
+       +++ b/file3
+       @@ -0,0 +1 @@
+       +4
+       EOF
+
        git stash pop --index &&
+       test_when_finished "git reset" &&
        git diff --cached >actual &&
        test_cmp expect actual
 '
 
-git reset >/dev/null
-
 # Must direct output somewhere where it won't be considered an untracked file
 test_expect_success 'stash save --include-untracked -q is quiet' '
        echo 1 >file5 &&
@@ -142,23 +146,22 @@ test_expect_success 'stash save --include-untracked removed files' '
        rm -f file &&
        git stash save --include-untracked &&
        echo 1 >expect &&
+       test_when_finished "rm -f expect" &&
        test_cmp expect file
 '
 
-rm -f expect
-
 test_expect_success 'stash save --include-untracked removed files got stashed' '
        git stash pop &&
        test_path_is_missing file
 '
 
-cat >.gitignore <<EOF
-.gitignore
-ignored
-ignored.d/
-EOF
-
 test_expect_success 'stash save --include-untracked respects .gitignore' '
+       cat >.gitignore <<-EOF &&
+       .gitignore
+       ignored
+       ignored.d/
+       EOF
+
        echo ignored >ignored &&
        mkdir ignored.d &&
        echo ignored >ignored.d/untracked &&
@@ -214,12 +217,12 @@ test_expect_success 'stash push with $IFS character' '
        test_path_is_file bar
 '
 
-cat >.gitignore <<EOF
-ignored
-ignored.d/*
-EOF
-
 test_expect_success 'stash previously ignored file' '
+       cat >.gitignore <<-EOF &&
+       ignored
+       ignored.d/*
+       EOF
+
        git reset HEAD &&
        git add .gitignore &&
        git commit -m "Add .gitignore" &&