stash: improve option parsing test coverage
In preparation for converting the stash command incrementally to a builtin command, this patch improves test coverage of the option parsing. Both for having too many parameters, or too few. Signed-off-by: Joel Teichroeb <joel@teichroeb.net> Signed-off-by: Paul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com> Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Joel Teichroeb committed
Feb 25, 2019 at 23:16 UTC
93415f58e052e56a2298fcfa76af2c4a3831e757
1 file changed
+35
t/t3903-stash.sh
+35
@@ -444,6 +444,36 @@ test_expect_failure 'stash file to directory' '
444
test foo = "$(cat file/file)"
445
'
446
447
+test_expect_success 'giving too many ref arguments does not modify files' '
448
+ git stash clear &&
449
+ test_when_finished "git reset --hard HEAD" &&
450
+ echo foo >file2 &&
451
+ git stash &&
452
+ echo bar >file2 &&
453
+ git stash &&
454
+ test-tool chmtime =123456789 file2 &&
455
+ for type in apply pop "branch stash-branch"
456
+ do
457
+ test_must_fail git stash $type stash@{0} stash@{1} 2>err &&
458
+ test_i18ngrep "Too many revisions" err &&
459
+ test 123456789 = $(test-tool chmtime -g file2) || return 1
460
+ done
461
+'
462
+
463
+test_expect_success 'drop: too many arguments errors out (does nothing)' '
464
+ git stash list >expect &&
465
+ test_must_fail git stash drop stash@{0} stash@{1} 2>err &&
466
+ test_i18ngrep "Too many revisions" err &&
467
+ git stash list >actual &&
468
+ test_cmp expect actual
469
+'
470
+
471
+test_expect_success 'show: too many arguments errors out (does nothing)' '
472
+ test_must_fail git stash show stash@{0} stash@{1} 2>err 1>out &&
473
+ test_i18ngrep "Too many revisions" err &&
474
+ test_must_be_empty out
475
+'
476
+
477
test_expect_success 'stash create - no changes' '
478
git stash clear &&
479
test_when_finished "git reset --hard HEAD" &&
@@ -479,6 +509,11 @@ test_expect_success 'stash branch - stashes on stack, stash-like argument' '
509
test $(git ls-files --modified | wc -l) -eq 1
510
'
511
512
+test_expect_success 'stash branch complains with no arguments' '
513
+ test_must_fail git stash branch 2>err &&
514
+ test_i18ngrep "No branch name specified" err
515
+'
516
+
517
test_expect_success 'stash show format defaults to --stat' '
518
git stash clear &&
519
test_when_finished "git reset --hard HEAD" &&