show-branch tests: modernize test code

Modernize test code added in ce567d1867a (Add test to show that show-branch misses out the 8th column, 2008-07-23) and 11ee57bc4c4 (sort_in_topological_order(): avoid setting a commit flag, 2008-07-23) to use test helpers. I'm renaming "out" to "actual" for consistency with other tests, and introducing a "branches.sorted" file in the setup, to make it clear that it's important that the list be sorted in this particular way. The "show-branch" output is indented with spaces, which would cause complaints under "git show --check" with an indented here-doc block. Let's prefix the lines with "> " to work around that, and to make it clear that the leading whitespace is important. We can also get rid of the hardcoding of "main" added here in 334afbc76fb (tests: mark tests relying on the current default for `init.defaultBranch`, 2020-11-18). For this test we're setting up an "initial" commit anyway, and now that we've moved over to test_commit we can reference that instead. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Jun 14, 2021 at 19:18 UTC 9b6e74a9c0133c4e34f6ec56cc93a6a83eba2c3c
1 file changed +40 -52
t/t3202-show-branch.sh
+40 -52
@@ -2,69 +2,57 @@
2
3 test_description='test show-branch'
4
5 -GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 -export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7 -
5 . ./test-lib.sh
6
10 -numbers="1 2 3 4 5 6 7 8 9 10"
11 -
7 test_expect_success 'setup' '
13 -
14 - > file &&
15 - git add file &&
16 - test_tick &&
17 - git commit -m initial &&
18 -
19 - for i in $numbers
8 + test_commit initial &&
9 + for i in $(test_seq 1 10)
10 do
21 - git checkout -b branch$i main &&
22 - > file$i &&
23 - git add file$i &&
24 - test_tick &&
25 - git commit -m branch$i || return 1
26 - done
27 -
11 + git checkout -b branch$i initial &&
12 + test_commit --no-tag branch$i
13 + done &&
14 + git for-each-ref \
15 + --sort=version:refname \
16 + --format="%(refname:strip=2)" \
17 + "refs/heads/branch*" >branches.sorted &&
18 + sed "s/^> //" >expect <<-\EOF
19 + > ! [branch1] branch1
20 + > ! [branch2] branch2
21 + > ! [branch3] branch3
22 + > ! [branch4] branch4
23 + > ! [branch5] branch5
24 + > ! [branch6] branch6
25 + > ! [branch7] branch7
26 + > ! [branch8] branch8
27 + > ! [branch9] branch9
28 + > * [branch10] branch10
29 + > ----------
30 + > * [branch10] branch10
31 + > + [branch9] branch9
32 + > + [branch8] branch8
33 + > + [branch7] branch7
34 + > + [branch6] branch6
35 + > + [branch5] branch5
36 + > + [branch4] branch4
37 + > + [branch3] branch3
38 + > + [branch2] branch2
39 + > + [branch1] branch1
40 + > +++++++++* [branch10^] initial
41 + EOF
42 '
43
30 -cat > expect << EOF
31 -! [branch1] branch1
32 - ! [branch2] branch2
33 - ! [branch3] branch3
34 - ! [branch4] branch4
35 - ! [branch5] branch5
36 - ! [branch6] branch6
37 - ! [branch7] branch7
38 - ! [branch8] branch8
39 - ! [branch9] branch9
40 - * [branch10] branch10
41 -----------
42 - * [branch10] branch10
43 - + [branch9] branch9
44 - + [branch8] branch8
45 - + [branch7] branch7
46 - + [branch6] branch6
47 - + [branch5] branch5
48 - + [branch4] branch4
49 - + [branch3] branch3
50 - + [branch2] branch2
51 -+ [branch1] branch1
52 -+++++++++* [branch10^] initial
53 -EOF
54 -
44 test_expect_success 'show-branch with more than 8 branches' '
56 -
57 - git show-branch $(for i in $numbers; do echo branch$i; done) > out &&
58 - test_cmp expect out
59 -
45 + git show-branch $(cat branches.sorted) >actual &&
46 + test_cmp expect actual
47 '
48
49 test_expect_success 'show-branch with showbranch.default' '
63 - for i in $numbers; do
64 - git config --add showbranch.default branch$i
50 + for branch in $(cat branches.sorted)
51 + do
52 + test_config showbranch.default $branch --add
53 done &&
66 - git show-branch >out &&
67 - test_cmp expect out
54 + git show-branch >actual &&
55 + test_cmp expect actual
56 '
57
58 test_done