git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Robert Estelle via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Robert Estelle <robert.estelle@gmail.com>,
	Robert Estelle <robertestelle@gmail.com>
Subject: [PATCH 1/3] blame: add test for --color-lines + --color-by-age
Date: Thu, 02 Feb 2023 19:16:44 +0000	[thread overview]
Message-ID: <01112de2b6ab7188e9fa9ef00aa06948ead74172.1675365406.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1449.git.git.1675365406.gitgitgadget@gmail.com>

From: Robert Estelle <robertestelle@gmail.com>

This adds a test verifying `git blame`'s output when run with both
`--color-lines` and `--color-by-age`. Those flags are not mutually
exclusive and both affect the output format. They were previously only
tested independently.

Signed-off-by: Robert Estelle <robertestelle@gmail.com>
---
 t/t8012-blame-colors.sh | 63 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/t/t8012-blame-colors.sh b/t/t8012-blame-colors.sh
index c3a5f6d01ff..820f86c3aed 100755
--- a/t/t8012-blame-colors.sh
+++ b/t/t8012-blame-colors.sh
@@ -49,4 +49,67 @@ test_expect_success 'blame color by age: new code is different' '
 	grep qfunc colored
 '
 
+# shellcheck disable=SC2317
+re_normalize_color_decoded_blame() {
+	# Construct the regex used by `normalize_color_decoded_blame`.
+	# This is simply for documentation: line comments aren't permitted in
+	# backslash-continuation lines, and POSIX sh does't support 'x+=' syntax.
+	printf '%s' '\(<[^>]*>\)'     # 1: capture the "<YELLOW>" etc
+	printf '%s' ' *'              # -- discard any spaces
+	printf '%s' '[0-9a-f]\{1,\}'  # -- discard the commit ID
+	printf '%s' ' *'              # -- discard any spaces
+	printf '%s' '('               # -- left paren
+	printf '%s' '\(.\)'           # 2: capture the single-char A/F/G/etc
+	printf '%s' '[^\)]*'          # -- discard author and timestamp stuff
+	printf '%s' '\([0-9]\)\{1,\}' # 3: capture the line number
+	printf '%s' ')'               # -- right paren
+	printf '%s' ' *'              # -- discard leading spaces
+	printf '%s' '\(.*$\)'         # 4: capture the remainder
+}
+
+# shellcheck disable=SC2317
+normalize_color_decoded_blame() {
+	# Reads from stdin and writes to stdout.
+	# Removes the commit ID and author/timestamp from blame output after
+	# "test_decode_color" has run.
+	#
+	# This is simply to make expected  outputs easier to describe
+	# and compare without having to refer to magic line counts.
+	re="$(re_normalize_color_decoded_blame)" || return $?
+	sed -e 's/^'"${re}"'/\1 (\2 \3) \4/'
+}
+
+test_expect_success 'blame color by age and lines' '
+	git \
+		-c color.blame.repeatedLines=blue \
+		-c color.blame.highlightRecent="yellow,1 month ago, cyan" \
+		blame \
+		--color-lines \
+		--color-by-age \
+		hello.c \
+		>actual.raw &&
+
+	test_decode_color <actual.raw >actual &&
+	normalize_color_decoded_blame <actual >actual.norm &&
+
+	normalize_color_decoded_blame >expected.norm <<-EOF &&
+		<YELLOW>11111111 (H ... 1)  <RESET>#include <stdio.h>
+		<YELLOW>22222222 (F ... 2)  <RESET>int main(int argc, const char *argv[])
+		<BLUE>  22222222 (F ... 3)  <RESET>{
+		<BLUE>  22222222 (F ... 4)  <RESET>	puts("hello");
+		<YELLOW>33333333 (G ... 5)  <RESET>	puts("goodbye");
+		<YELLOW>22222222 (F ... 6)  <RESET>}
+		<YELLOW>11111111 (H ... 7)  <RESET>void mail()
+		<BLUE>  11111111 (H ... 8)  <RESET>{
+		<BLUE>  11111111 (H ... 9)  <RESET>	puts("mail");
+		<BLUE>  11111111 (H ... 10) <RESET>}
+		<CYAN>  44444444 (A ... 11) <RESET>void qfunc();
+		EOF
+
+	test_cmp actual.norm expected.norm &&
+
+	grep "<YELLOW>" <actual.norm >sanity-check &&
+	test_line_count = 5 sanity-check
+'
+
 test_done
-- 
gitgitgadget


  reply	other threads:[~2023-02-02 19:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-02 19:16 [PATCH 0/3] blame: allow blame.coloring to specify both --color-lines and --color-by-age Robert Estelle via GitGitGadget
2023-02-02 19:16 ` Robert Estelle via GitGitGadget [this message]
2023-02-02 19:16 ` [PATCH 2/3] blame: document --color-{lines,by-age} config Robert Estelle via GitGitGadget
2023-02-02 19:16 ` [PATCH 3/3] blame: support multiple values in blame.coloring Robert Estelle via GitGitGadget

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=01112de2b6ab7188e9fa9ef00aa06948ead74172.1675365406.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=robert.estelle@gmail.com \
    --cc=robertestelle@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).