t4207: modernize test

Before adding new tests to t4207-log-decoration-colors.sh, update the existing test to use modern test conventions. This includes: 1. Use lowercase in test names. 2. Keep all test setup inside the test_expect_success blocks. We need to be careful about left whitespace in the broken lines of the input file. 3. Do not use 'git' commands on the left side of a pipe. 4. Create a cmp_filtered_decorations helper to perform the 'log', 'sed', and test_decode_color manipulations. Move the '--all' option to be an argument so we can change that value in future tests. 5. Modify the 'sed' command to use a simpler form that is more portable. The next change will introduce new tests usinge these new conventions. Signed-off-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Aug 5, 2022 at 17:58 UTC b004521aa6f935fecd1426cab2997f7f8b31dcab
1 file changed +20 -17
t/t4207-log-decoration-colors.sh
+20 -17
@@ -3,7 +3,7 @@
3 # Copyright (c) 2010 Nazri Ramliy
4 #
5
6 -test_description='Test for "git log --decorate" colors'
6 +test_description='test "git log --decorate" colors'
7
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
@@ -42,25 +42,28 @@ test_expect_success setup '
42 git stash save Changes to A.t
43 '
44
45 -cat >expected <<EOF
46 -${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_HEAD}HEAD ->\
47 - ${c_reset}${c_branch}main${c_reset}${c_commit},\
48 - ${c_reset}${c_tag}tag: v1.0${c_reset}${c_commit},\
49 - ${c_reset}${c_tag}tag: B${c_reset}${c_commit})${c_reset} B
50 -${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: A1${c_reset}${c_commit},\
51 - ${c_reset}${c_remoteBranch}other/main${c_reset}${c_commit})${c_reset} A1
52 -${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_stash}refs/stash${c_reset}${c_commit})${c_reset}\
53 - On main: Changes to A.t
54 -${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: A${c_reset}${c_commit})${c_reset} A
55 -EOF
45 +cmp_filtered_decorations () {
46 + sed "s/$OID_REGEX/COMMIT_ID/" actual | test_decode_color >filtered &&
47 + test_cmp expect filtered
48 +}
49
50 # We want log to show all, but the second parent to refs/stash is irrelevant
51 # to this test since it does not contain any decoration, hence --first-parent
59 -test_expect_success 'Commit Decorations Colored Correctly' '
60 - git log --first-parent --abbrev=10 --all --decorate --oneline --color=always |
61 - sed "s/[0-9a-f]\{10,10\}/COMMIT_ID/" |
62 - test_decode_color >out &&
63 - test_cmp expected out
52 +test_expect_success 'commit decorations colored correctly' '
53 + cat >expect <<-EOF &&
54 + ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_HEAD}HEAD -> \
55 +${c_reset}${c_branch}main${c_reset}${c_commit}, \
56 +${c_reset}${c_tag}tag: v1.0${c_reset}${c_commit}, \
57 +${c_reset}${c_tag}tag: B${c_reset}${c_commit})${c_reset} B
58 +${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: A1${c_reset}${c_commit}, \
59 +${c_reset}${c_remoteBranch}other/main${c_reset}${c_commit})${c_reset} A1
60 + ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_stash}refs/stash${c_reset}${c_commit})${c_reset} \
61 +On main: Changes to A.t
62 + ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: A${c_reset}${c_commit})${c_reset} A
63 + EOF
64 +
65 + git log --first-parent --no-abbrev --decorate --oneline --color=always --all >actual &&
66 + cmp_filtered_decorations
67 '
68
69 test_done