From: Denton Liu <liu.denton@gmail.com>
To: Git Mailing List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>,
Eric Sunshine <sunshine@sunshineco.com>
Subject: [PATCH v2 3/9] t3905: move all commands into test cases
Date: Mon, 8 Feb 2021 23:28:49 -0800 [thread overview]
Message-ID: <5bda09b4bd55168f6e69f20026d0112b1a43f45f.1612855690.git.liu.denton@gmail.com> (raw)
In-Reply-To: <cover.1612855690.git.liu.denton@gmail.com>
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>
---
t/t3905-stash-include-untracked.sh | 147 +++++++++++++++--------------
1 file changed, 75 insertions(+), 72 deletions(-)
diff --git a/t/t3905-stash-include-untracked.sh b/t/t3905-stash-include-untracked.sh
index 1d416944b7..892a2c8057 100755
--- a/t/t3905-stash-include-untracked.sh
+++ b/t/t3905-stash-include-untracked.sh
@@ -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" &&
--
2.30.0.478.g8a0d178c01
next prev parent reply other threads:[~2021-02-09 7:30 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-02 9:31 [PATCH 0/9] stash show: learn --include-untracked and --only-untracked Denton Liu
2021-02-02 9:33 ` [PATCH 1/9] git-stash.txt: be explicit about subcommand options Denton Liu
2021-02-02 17:37 ` Eric Sunshine
2021-02-02 9:33 ` [PATCH 2/9] t3905: remove spaces after redirect operators Denton Liu
2021-02-02 9:33 ` [PATCH 3/9] t3905: move all commands into test cases Denton Liu
2021-02-02 21:41 ` Junio C Hamano
2021-02-02 9:33 ` [PATCH 4/9] t3905: remove nested git in command substitution Denton Liu
2021-02-02 9:33 ` [PATCH 5/9] t3905: replace test -s with test_file_not_empty Denton Liu
2021-02-02 9:33 ` [PATCH 6/9] t3905: use test_cmp() to check file contents Denton Liu
2021-02-02 9:33 ` [PATCH 7/9] stash: declare ref_stash as an array Denton Liu
2021-02-02 21:46 ` Junio C Hamano
2021-02-02 9:33 ` [PATCH 8/9] stash show: teach --include-tracked and --only-untracked Denton Liu
2021-02-02 21:56 ` Junio C Hamano
2021-02-02 9:33 ` [PATCH 9/9] stash show: learn stash.showIncludeUntracked Denton Liu
2021-02-09 7:28 ` [PATCH v2 0/9] stash show: learn --include-untracked and --only-untracked Denton Liu
2021-02-09 7:28 ` [PATCH v2 1/9] git-stash.txt: be explicit about subcommand options Denton Liu
2021-02-10 7:17 ` Junio C Hamano
2021-02-11 19:07 ` [PATCH] fixup! " Denton Liu
2021-02-09 7:28 ` [PATCH v2 2/9] t3905: remove spaces after redirect operators Denton Liu
2021-02-10 7:18 ` Junio C Hamano
2021-02-09 7:28 ` Denton Liu [this message]
2021-02-09 7:28 ` [PATCH v2 4/9] t3905: remove nested git in command substitution Denton Liu
2021-02-10 7:24 ` Junio C Hamano
2021-02-09 7:28 ` [PATCH v2 5/9] t3905: replace test -s with test_file_not_empty Denton Liu
2021-02-09 7:28 ` [PATCH v2 6/9] t3905: use test_cmp() to check file contents Denton Liu
2021-02-09 7:28 ` [PATCH v2 7/9] stash: declare ref_stash as an array Denton Liu
2021-02-10 7:28 ` Junio C Hamano
2021-02-09 7:28 ` [PATCH v2 8/9] stash show: teach --include-untracked and --only-untracked Denton Liu
2021-02-10 7:53 ` Junio C Hamano
2021-02-16 3:15 ` Denton Liu
2021-02-16 6:42 ` Junio C Hamano
2021-02-09 7:28 ` [PATCH v2 9/9] stash show: learn stash.showIncludeUntracked Denton Liu
2021-02-16 7:11 ` [PATCH v3 0/2] stash show: learn --include-untracked and --only-untracked Denton Liu
2021-02-16 7:11 ` [PATCH v3 1/2] stash show: teach " Denton Liu
2021-02-16 20:22 ` Junio C Hamano
2021-02-17 11:18 ` Denton Liu
2021-02-17 17:50 ` Junio C Hamano
2021-02-17 2:31 ` Junio C Hamano
2021-02-16 7:11 ` [PATCH v3 2/2] stash show: learn stash.showIncludeUntracked Denton Liu
2021-03-03 11:16 ` [PATCH v4 0/2] stash show: learn --include-untracked and --only-untracked Denton Liu
2021-03-03 11:16 ` [PATCH v4 1/2] stash show: teach " Denton Liu
2021-03-03 11:16 ` [PATCH v4 2/2] stash show: learn stash.showIncludeUntracked Denton Liu
2021-03-04 0:38 ` [PATCH v4 0/2] stash show: learn --include-untracked and --only-untracked Junio C Hamano
2021-03-04 1:33 ` Denton Liu
2021-03-04 1:42 ` Denton Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5bda09b4bd55168f6e69f20026d0112b1a43f45f.1612855690.git.liu.denton@gmail.com \
--to=liu.denton@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).