Skip to content

Commit b004521

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b877e61 commit b004521

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

t/t4207-log-decoration-colors.sh

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Copyright (c) 2010 Nazri Ramliy
44
#
55

6-
test_description='Test for "git log --decorate" colors'
6+
test_description='test "git log --decorate" colors'
77

88
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
99
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
@@ -42,25 +42,28 @@ test_expect_success setup '
4242
git stash save Changes to A.t
4343
'
4444

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+
}
5649

5750
# We want log to show all, but the second parent to refs/stash is irrelevant
5851
# 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
6467
'
6568

6669
test_done

0 commit comments

Comments
 (0)