Skip to content

Commit 3fcb887

Browse files
drafnelgitster
authored andcommitted
t/t3903-stash: improve testing of git-stash show
Recently, the 'stash show' functionality was broken for the case when a stash-like argument was supplied. Since, commit 9bf09e, 'stash show' when supplied a stash-like argument prints nothing and still exists with a zero status. Unfortunately, the flaw slipped through the test suite cracks since the output of 'stash show' was not verified to be correct. Improve and expand on the existing tests so that this flaws is detected. Signed-off-by: Brandon Casey <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 87b5054 commit 3fcb887

File tree

1 file changed

+58
-4
lines changed

1 file changed

+58
-4
lines changed

t/t3903-stash.sh

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ test_expect_success 'stash branch - stashes on stack, stash-like argument' '
406406
test $(git ls-files --modified | wc -l) -eq 1
407407
'
408408

409-
test_expect_success 'stash show - stashes on stack, stash-like argument' '
409+
test_expect_failure 'stash show - stashes on stack, stash-like argument' '
410410
git stash clear &&
411411
test_when_finished "git reset --hard HEAD" &&
412412
git reset --hard &&
@@ -416,16 +416,70 @@ test_expect_success 'stash show - stashes on stack, stash-like argument' '
416416
echo bar >> file &&
417417
STASH_ID=$(git stash create) &&
418418
git reset --hard &&
419-
git stash show ${STASH_ID}
419+
cat >expected <<-EOF &&
420+
file | 1 +
421+
1 files changed, 1 insertions(+), 0 deletions(-)
422+
EOF
423+
git stash show ${STASH_ID} >actual &&
424+
test_cmp expected actual
420425
'
421-
test_expect_success 'stash show - no stashes on stack, stash-like argument' '
426+
427+
test_expect_failure 'stash show -p - stashes on stack, stash-like argument' '
428+
git stash clear &&
429+
test_when_finished "git reset --hard HEAD" &&
430+
git reset --hard &&
431+
echo foo >> file &&
432+
git stash &&
433+
test_when_finished "git stash drop" &&
434+
echo bar >> file &&
435+
STASH_ID=$(git stash create) &&
436+
git reset --hard &&
437+
cat >expected <<-EOF &&
438+
diff --git a/file b/file
439+
index 7601807..935fbd3 100644
440+
--- a/file
441+
+++ b/file
442+
@@ -1 +1,2 @@
443+
baz
444+
+bar
445+
EOF
446+
git stash show -p ${STASH_ID} >actual &&
447+
test_cmp expected actual
448+
'
449+
450+
test_expect_failure 'stash show - no stashes on stack, stash-like argument' '
451+
git stash clear &&
452+
test_when_finished "git reset --hard HEAD" &&
453+
git reset --hard &&
454+
echo foo >> file &&
455+
STASH_ID=$(git stash create) &&
456+
git reset --hard &&
457+
cat >expected <<-EOF &&
458+
file | 1 +
459+
1 files changed, 1 insertions(+), 0 deletions(-)
460+
EOF
461+
git stash show ${STASH_ID} >actual &&
462+
test_cmp expected actual
463+
'
464+
465+
test_expect_failure 'stash show -p - no stashes on stack, stash-like argument' '
422466
git stash clear &&
423467
test_when_finished "git reset --hard HEAD" &&
424468
git reset --hard &&
425469
echo foo >> file &&
426470
STASH_ID=$(git stash create) &&
427471
git reset --hard &&
428-
git stash show ${STASH_ID}
472+
cat >expected <<-EOF &&
473+
diff --git a/file b/file
474+
index 7601807..71b52c4 100644
475+
--- a/file
476+
+++ b/file
477+
@@ -1 +1,2 @@
478+
baz
479+
+foo
480+
EOF
481+
git stash show -p ${STASH_ID} >actual &&
482+
test_cmp expected actual
429483
'
430484

431485
test_expect_success 'stash drop - fail early if specified stash is not a stash reference' '

0 commit comments

Comments
 (0)