t3905: move all commands into test cases
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>
This commit is contained in:

committed by
Junio C Hamano

parent
32b7385e43
commit
bbaa45c3aa
@ -25,19 +25,20 @@ test_expect_success 'stash save --include-untracked some dirty working directory
|
|||||||
git diff-index --cached --quiet HEAD
|
git diff-index --cached --quiet HEAD
|
||||||
'
|
'
|
||||||
|
|
||||||
cat >expect <<EOF
|
test_expect_success 'stash save --include-untracked cleaned the untracked files' '
|
||||||
|
cat >expect <<-EOF &&
|
||||||
?? actual
|
?? actual
|
||||||
?? expect
|
?? expect
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
test_expect_success 'stash save --include-untracked cleaned the untracked files' '
|
|
||||||
git status --porcelain >actual &&
|
git status --porcelain >actual &&
|
||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
tracked=$(git rev-parse --short $(echo 1 | git hash-object --stdin))
|
test_expect_success 'stash save --include-untracked stashed the untracked files' '
|
||||||
untracked=$(git rev-parse --short $(echo untracked | git hash-object --stdin))
|
tracked=$(git rev-parse --short $(echo 1 | git hash-object --stdin)) &&
|
||||||
cat >expect.diff <<EOF
|
untracked=$(git rev-parse --short $(echo untracked | git hash-object --stdin)) &&
|
||||||
|
cat >expect.diff <<-EOF &&
|
||||||
diff --git a/HEAD b/HEAD
|
diff --git a/HEAD b/HEAD
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000..$tracked
|
index 0000000..$tracked
|
||||||
@ -60,13 +61,12 @@ index 0000000..$untracked
|
|||||||
@@ -0,0 +1 @@
|
@@ -0,0 +1 @@
|
||||||
+untracked
|
+untracked
|
||||||
EOF
|
EOF
|
||||||
cat >expect.lstree <<EOF
|
cat >expect.lstree <<-EOF &&
|
||||||
HEAD
|
HEAD
|
||||||
file2
|
file2
|
||||||
untracked
|
untracked
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
test_expect_success 'stash save --include-untracked stashed the untracked files' '
|
|
||||||
test_path_is_missing file2 &&
|
test_path_is_missing file2 &&
|
||||||
test_path_is_missing untracked &&
|
test_path_is_missing untracked &&
|
||||||
test_path_is_missing HEAD &&
|
test_path_is_missing HEAD &&
|
||||||
@ -83,9 +83,13 @@ test_expect_success 'stash save --patch --all fails' '
|
|||||||
test_must_fail git stash --patch --all
|
test_must_fail git stash --patch --all
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'clean up untracked/untracked file to prepare for next tests' '
|
||||||
git clean --force --quiet
|
git clean --force --quiet
|
||||||
|
|
||||||
cat >expect <<EOF
|
'
|
||||||
|
|
||||||
|
test_expect_success 'stash pop after save --include-untracked leaves files untracked again' '
|
||||||
|
cat >expect <<-EOF &&
|
||||||
M file
|
M file
|
||||||
?? HEAD
|
?? HEAD
|
||||||
?? actual
|
?? actual
|
||||||
@ -94,7 +98,6 @@ cat >expect <<EOF
|
|||||||
?? untracked/
|
?? untracked/
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
test_expect_success 'stash pop after save --include-untracked leaves files untracked again' '
|
|
||||||
git stash pop &&
|
git stash pop &&
|
||||||
git status --porcelain >actual &&
|
git status --porcelain >actual &&
|
||||||
test_cmp expect 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)"
|
test untracked = "$(cat untracked/untracked)"
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'clean up untracked/ directory to prepare for next tests' '
|
||||||
git clean --force --quiet -d
|
git clean --force --quiet -d
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'stash save -u dirty index' '
|
test_expect_success 'stash save -u dirty index' '
|
||||||
echo 4 >file3 &&
|
echo 4 >file3 &&
|
||||||
@ -111,8 +116,9 @@ test_expect_success 'stash save -u dirty index' '
|
|||||||
git stash -u
|
git stash -u
|
||||||
'
|
'
|
||||||
|
|
||||||
blob=$(git rev-parse --short $(echo 4 | git hash-object --stdin))
|
test_expect_success 'stash save --include-untracked dirty index got stashed' '
|
||||||
cat >expect <<EOF
|
blob=$(git rev-parse --short $(echo 4 | git hash-object --stdin)) &&
|
||||||
|
cat >expect <<-EOF &&
|
||||||
diff --git a/file3 b/file3
|
diff --git a/file3 b/file3
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000..$blob
|
index 0000000..$blob
|
||||||
@ -122,14 +128,12 @@ index 0000000..$blob
|
|||||||
+4
|
+4
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
test_expect_success 'stash save --include-untracked dirty index got stashed' '
|
|
||||||
git stash pop --index &&
|
git stash pop --index &&
|
||||||
|
test_when_finished "git reset" &&
|
||||||
git diff --cached >actual &&
|
git diff --cached >actual &&
|
||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
git reset >/dev/null
|
|
||||||
|
|
||||||
# Must direct output somewhere where it won't be considered an untracked file
|
# Must direct output somewhere where it won't be considered an untracked file
|
||||||
test_expect_success 'stash save --include-untracked -q is quiet' '
|
test_expect_success 'stash save --include-untracked -q is quiet' '
|
||||||
echo 1 >file5 &&
|
echo 1 >file5 &&
|
||||||
@ -142,23 +146,22 @@ test_expect_success 'stash save --include-untracked removed files' '
|
|||||||
rm -f file &&
|
rm -f file &&
|
||||||
git stash save --include-untracked &&
|
git stash save --include-untracked &&
|
||||||
echo 1 >expect &&
|
echo 1 >expect &&
|
||||||
|
test_when_finished "rm -f expect" &&
|
||||||
test_cmp expect file
|
test_cmp expect file
|
||||||
'
|
'
|
||||||
|
|
||||||
rm -f expect
|
|
||||||
|
|
||||||
test_expect_success 'stash save --include-untracked removed files got stashed' '
|
test_expect_success 'stash save --include-untracked removed files got stashed' '
|
||||||
git stash pop &&
|
git stash pop &&
|
||||||
test_path_is_missing file
|
test_path_is_missing file
|
||||||
'
|
'
|
||||||
|
|
||||||
cat >.gitignore <<EOF
|
test_expect_success 'stash save --include-untracked respects .gitignore' '
|
||||||
|
cat >.gitignore <<-EOF &&
|
||||||
.gitignore
|
.gitignore
|
||||||
ignored
|
ignored
|
||||||
ignored.d/
|
ignored.d/
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
test_expect_success 'stash save --include-untracked respects .gitignore' '
|
|
||||||
echo ignored >ignored &&
|
echo ignored >ignored &&
|
||||||
mkdir ignored.d &&
|
mkdir ignored.d &&
|
||||||
echo ignored >ignored.d/untracked &&
|
echo ignored >ignored.d/untracked &&
|
||||||
@ -214,12 +217,12 @@ test_expect_success 'stash push with $IFS character' '
|
|||||||
test_path_is_file bar
|
test_path_is_file bar
|
||||||
'
|
'
|
||||||
|
|
||||||
cat >.gitignore <<EOF
|
test_expect_success 'stash previously ignored file' '
|
||||||
|
cat >.gitignore <<-EOF &&
|
||||||
ignored
|
ignored
|
||||||
ignored.d/*
|
ignored.d/*
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
test_expect_success 'stash previously ignored file' '
|
|
||||||
git reset HEAD &&
|
git reset HEAD &&
|
||||||
git add .gitignore &&
|
git add .gitignore &&
|
||||||
git commit -m "Add .gitignore" &&
|
git commit -m "Add .gitignore" &&
|
||||||
|
Reference in New Issue
Block a user