t3200: improve test style
Some tests use a preliminary heredoc for `expect` or have setup and teardown commands before and after, respectively. It is however preferred to keep all the logic in the test itself. Let’s move these into the tests. Also: • Remove a now-irrelevant comment about test placement and switch back to `main` post-test • Prefer indented literal heredocs (`-\EOF`) except for a block which says that this is intentional Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Kristoffer Haugsbakk committed
Mar 5, 2024 at 21:29 UTC
8c5001c68e8f768e7b97cb5c366bc0b1e7a31ba7
1 file changed
+55
-58
t/t3200-branch.sh
+55
-58
@@ -75,13 +75,13 @@ test_expect_success 'git branch HEAD should fail' '
75
test_must_fail git branch HEAD
76
'
77
78
-cat >expect <<EOF
79
-$HEAD refs/heads/d/e/f@{0}: branch: Created from main
80
-EOF
78
test_expect_success 'git branch --create-reflog d/e/f should create a branch and a log' '
79
GIT_COMMITTER_DATE="2005-05-26 23:30" \
80
git -c core.logallrefupdates=false branch --create-reflog d/e/f &&
81
test_ref_exists refs/heads/d/e/f &&
82
+ cat >expect <<-EOF &&
83
+ $HEAD refs/heads/d/e/f@{0}: branch: Created from main
84
+ EOF
85
git reflog show --no-abbrev-commit refs/heads/d/e/f >actual &&
86
test_cmp expect actual
87
'
@@ -440,10 +440,10 @@ test_expect_success 'git branch --list -v with --abbrev' '
440
441
test_expect_success 'git branch --column' '
442
COLUMNS=81 git branch --column=column >actual &&
443
- cat >expect <<\EOF &&
444
- a/b/c bam foo l * main n o/p r
445
- abc bar j/k m/m mb o/o q topic
446
-EOF
443
+ cat >expect <<-\EOF &&
444
+ a/b/c bam foo l * main n o/p r
445
+ abc bar j/k m/m mb o/o q topic
446
+ EOF
447
test_cmp expect actual
448
'
449
@@ -453,25 +453,25 @@ test_expect_success 'git branch --column with an extremely long branch name' '
453
test_when_finished "git branch -d $long" &&
454
git branch $long &&
455
COLUMNS=80 git branch --column=column >actual &&
456
- cat >expect <<EOF &&
457
- a/b/c
458
- abc
459
- bam
460
- bar
461
- foo
462
- j/k
463
- l
464
- m/m
465
-* main
466
- mb
467
- n
468
- o/o
469
- o/p
470
- q
471
- r
472
- topic
473
- $long
474
-EOF
456
+ cat >expect <<-EOF &&
457
+ a/b/c
458
+ abc
459
+ bam
460
+ bar
461
+ foo
462
+ j/k
463
+ l
464
+ m/m
465
+ * main
466
+ mb
467
+ n
468
+ o/o
469
+ o/p
470
+ q
471
+ r
472
+ topic
473
+ $long
474
+ EOF
475
test_cmp expect actual
476
'
477
@@ -481,10 +481,10 @@ test_expect_success 'git branch with column.*' '
481
COLUMNS=80 git branch >actual &&
482
git config --unset column.branch &&
483
git config --unset column.ui &&
484
- cat >expect <<\EOF &&
485
- a/b/c bam foo l * main n o/p r
486
- abc bar j/k m/m mb o/o q topic
487
-EOF
484
+ cat >expect <<-\EOF &&
485
+ a/b/c bam foo l * main n o/p r
486
+ abc bar j/k m/m mb o/o q topic
487
+ EOF
488
test_cmp expect actual
489
'
490
@@ -496,39 +496,36 @@ test_expect_success 'git branch -v with column.ui ignored' '
496
git config column.ui column &&
497
COLUMNS=80 git branch -v | cut -c -8 | sed "s/ *$//" >actual &&
498
git config --unset column.ui &&
499
- cat >expect <<\EOF &&
500
- a/b/c
501
- abc
502
- bam
503
- bar
504
- foo
505
- j/k
506
- l
507
- m/m
508
-* main
509
- mb
510
- n
511
- o/o
512
- o/p
513
- q
514
- r
515
- topic
516
-EOF
499
+ cat >expect <<-\EOF &&
500
+ a/b/c
501
+ abc
502
+ bam
503
+ bar
504
+ foo
505
+ j/k
506
+ l
507
+ m/m
508
+ * main
509
+ mb
510
+ n
511
+ o/o
512
+ o/p
513
+ q
514
+ r
515
+ topic
516
+ EOF
517
test_cmp expect actual
518
'
519
520
-mv .git/config .git/config-saved
521
-
520
test_expect_success DEFAULT_REPO_FORMAT 'git branch -m q q2 without config should succeed' '
521
+ test_when_finished mv .git/config-saved .git/config &&
522
+ mv .git/config .git/config-saved &&
523
git branch -m q q2 &&
524
git branch -m q2 q
525
'
526
527
-mv .git/config-saved .git/config
528
-
529
-git config branch.s/s.dummy Hello
530
-
527
test_expect_success 'git branch -m s/s s should work when s/t is deleted' '
528
+ git config branch.s/s.dummy Hello &&
529
git branch --create-reflog s/s &&
530
git reflog exists refs/heads/s/s &&
531
git branch --create-reflog s/t &&
@@ -1141,14 +1138,14 @@ test_expect_success '--set-upstream-to notices an error to set branch as own ups
1138
test_cmp expect actual
1139
"
1140
1144
-# Keep this test last, as it changes the current branch
1145
-cat >expect <<EOF
1146
-$HEAD refs/heads/g/h/i@{0}: branch: Created from main
1147
-EOF
1141
test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' '
1142
+ test_when_finished git checkout main &&
1143
GIT_COMMITTER_DATE="2005-05-26 23:30" \
1144
git checkout -b g/h/i -l main &&
1145
test_ref_exists refs/heads/g/h/i &&
1146
+ cat >expect <<-EOF &&
1147
+ $HEAD refs/heads/g/h/i@{0}: branch: Created from main
1148
+ EOF
1149
git reflog show --no-abbrev-commit refs/heads/g/h/i >actual &&
1150
test_cmp expect actual
1151
'