Skip to content

Commit 8c5001c

Browse files
LemmingAvalanchegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Kristoffer Haugsbakk <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3c2a3fd commit 8c5001c

File tree

1 file changed

+55
-58
lines changed

1 file changed

+55
-58
lines changed

t/t3200-branch.sh

Lines changed: 55 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ test_expect_success 'git branch HEAD should fail' '
7575
test_must_fail git branch HEAD
7676
'
7777

78-
cat >expect <<EOF
79-
$HEAD refs/heads/d/e/f@{0}: branch: Created from main
80-
EOF
8178
test_expect_success 'git branch --create-reflog d/e/f should create a branch and a log' '
8279
GIT_COMMITTER_DATE="2005-05-26 23:30" \
8380
git -c core.logallrefupdates=false branch --create-reflog d/e/f &&
8481
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
8585
git reflog show --no-abbrev-commit refs/heads/d/e/f >actual &&
8686
test_cmp expect actual
8787
'
@@ -440,10 +440,10 @@ test_expect_success 'git branch --list -v with --abbrev' '
440440

441441
test_expect_success 'git branch --column' '
442442
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
447447
test_cmp expect actual
448448
'
449449

@@ -453,25 +453,25 @@ test_expect_success 'git branch --column with an extremely long branch name' '
453453
test_when_finished "git branch -d $long" &&
454454
git branch $long &&
455455
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
475475
test_cmp expect actual
476476
'
477477

@@ -481,10 +481,10 @@ test_expect_success 'git branch with column.*' '
481481
COLUMNS=80 git branch >actual &&
482482
git config --unset column.branch &&
483483
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
488488
test_cmp expect actual
489489
'
490490

@@ -496,39 +496,36 @@ test_expect_success 'git branch -v with column.ui ignored' '
496496
git config column.ui column &&
497497
COLUMNS=80 git branch -v | cut -c -8 | sed "s/ *$//" >actual &&
498498
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
517517
test_cmp expect actual
518518
'
519519

520-
mv .git/config .git/config-saved
521-
522520
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 &&
523523
git branch -m q q2 &&
524524
git branch -m q2 q
525525
'
526526

527-
mv .git/config-saved .git/config
528-
529-
git config branch.s/s.dummy Hello
530-
531527
test_expect_success 'git branch -m s/s s should work when s/t is deleted' '
528+
git config branch.s/s.dummy Hello &&
532529
git branch --create-reflog s/s &&
533530
git reflog exists refs/heads/s/s &&
534531
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
11411138
test_cmp expect actual
11421139
"
11431140

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
11481141
test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' '
1142+
test_when_finished git checkout main &&
11491143
GIT_COMMITTER_DATE="2005-05-26 23:30" \
11501144
git checkout -b g/h/i -l main &&
11511145
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
11521149
git reflog show --no-abbrev-commit refs/heads/g/h/i >actual &&
11531150
test_cmp expect actual
11541151
'

0 commit comments

Comments
 (0)