From: Karthik Nayak <karthik.188@gmail.com>
To: oliver@schinagl.nl
Cc: git@vger.kernel.org, Karthik Nayak <karthik.188@gmail.com>
Subject: [PATCH 1/2] t4034: extract out `diff_with_opts`
Date: Sat, 2 Mar 2024 10:57:50 +0100 [thread overview]
Message-ID: <20240302095751.123138-2-karthik.188@gmail.com> (raw)
In-Reply-To: <20240302095751.123138-1-karthik.188@gmail.com>
The current `word_diff` function in t4034 uses the arguments provided to
obtain the diff and compare them.
Let's rename this to `diff_with_opts` and add a new function `word_diff`
which is specific to the `--word-diff=` option. This function will act
as a wrapper around `diff_with_opts`.
In the following commit, when we introduce a config option for
`--word-diff`, we'd want to test the existing tests also with the config
option and at this point we can expand `word_diff` to test both config
and command line options.
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
---
t/t4034-diff-words.sh | 54 +++++++++++++++++++++++--------------------
1 file changed, 29 insertions(+), 25 deletions(-)
diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh
index 74586f3813..4f70aa6e9f 100755
--- a/t/t4034-diff-words.sh
+++ b/t/t4034-diff-words.sh
@@ -51,7 +51,7 @@ cat >expect.non-whitespace-is-word <<-EOF
<GREEN>aeff = aeff * ( aaa )<RESET>
EOF
-word_diff () {
+diff_with_opts () {
pre=$(git rev-parse --short $(git hash-object pre)) &&
post=$(git rev-parse --short $(git hash-object post)) &&
test_must_fail git diff --no-index "$@" pre post >output &&
@@ -60,6 +60,10 @@ word_diff () {
test_cmp expected output.decrypted
}
+word_diff () {
+ diff_with_opts "--word-diff=$1" $(echo "$@" | cut -d' ' -s -f 2-)
+}
+
test_language_driver () {
lang=$1
test_expect_success "diff driver '$lang'" '
@@ -67,11 +71,11 @@ test_language_driver () {
"$TEST_DIRECTORY/t4034/'"$lang"'/post" \
"$TEST_DIRECTORY/t4034/'"$lang"'/expect" . &&
echo "* diff='"$lang"'" >.gitattributes &&
- word_diff --color-words
+ diff_with_opts --color-words
'
test_expect_success "diff driver '$lang' in Islandic" '
LANG=is_IS.UTF-8 LANGUAGE=is LC_ALL="$is_IS_locale" \
- word_diff --color-words
+ diff_with_opts --color-words
'
}
@@ -81,7 +85,7 @@ test_expect_success setup '
git config diff.color.func magenta
'
-test_expect_success 'set up pre and post with runs of whitespace' '
+test_expect_success 'setup pre and post with runs of whitespace' '
cp pre.simple pre &&
cp post.simple post
'
@@ -101,9 +105,9 @@ test_expect_success 'word diff with runs of whitespace' '
<GREEN>aeff = aeff * ( aaa )<RESET>
EOF
- word_diff --color-words &&
- word_diff --word-diff=color &&
- word_diff --color --word-diff=color
+ diff_with_opts --color-words &&
+ word_diff color &&
+ diff_with_opts --color --word-diff=color
'
test_expect_success '--word-diff=porcelain' '
@@ -127,7 +131,7 @@ test_expect_success '--word-diff=porcelain' '
+aeff = aeff * ( aaa )
~
EOF
- word_diff --word-diff=porcelain
+ word_diff porcelain
'
test_expect_success '--word-diff=plain' '
@@ -145,8 +149,8 @@ test_expect_success '--word-diff=plain' '
{+aeff = aeff * ( aaa )+}
EOF
- word_diff --word-diff=plain &&
- word_diff --word-diff=plain --no-color
+ diff_with_opts --word-diff=plain &&
+ word_diff plain --no-color
'
test_expect_success '--word-diff=plain --color' '
@@ -164,7 +168,7 @@ test_expect_success '--word-diff=plain --color' '
<GREEN>{+aeff = aeff * ( aaa )+}<RESET>
EOF
- word_diff --word-diff=plain --color
+ word_diff plain --color
'
test_expect_success 'word diff without context' '
@@ -181,17 +185,17 @@ test_expect_success 'word diff without context' '
<GREEN>aeff = aeff * ( aaa )<RESET>
EOF
- word_diff --color-words --unified=0
+ diff_with_opts --color-words --unified=0
'
test_expect_success 'word diff with a regular expression' '
cp expect.letter-runs-are-words expect &&
- word_diff --color-words="[a-z]+"
+ diff_with_opts --color-words="[a-z]+"
'
test_expect_success 'word diff with zero length matches' '
cp expect.letter-runs-are-words expect &&
- word_diff --color-words="[a-z${LF}]*"
+ diff_with_opts --color-words="[a-z${LF}]*"
'
test_expect_success 'set up a diff driver' '
@@ -204,12 +208,12 @@ test_expect_success 'set up a diff driver' '
test_expect_success 'option overrides .gitattributes' '
cp expect.letter-runs-are-words expect &&
- word_diff --color-words="[a-z]+"
+ diff_with_opts --color-words="[a-z]+"
'
test_expect_success 'use regex supplied by driver' '
cp expect.non-whitespace-is-word expect &&
- word_diff --color-words
+ diff_with_opts --color-words
'
test_expect_success 'set up diff.wordRegex option' '
@@ -218,7 +222,7 @@ test_expect_success 'set up diff.wordRegex option' '
test_expect_success 'command-line overrides config' '
cp expect.letter-runs-are-words expect &&
- word_diff --color-words="[a-z]+"
+ diff_with_opts --color-words="[a-z]+"
'
test_expect_success 'command-line overrides config: --word-diff-regex' '
@@ -236,12 +240,12 @@ test_expect_success 'command-line overrides config: --word-diff-regex' '
<GREEN>{+aeff = aeff * ( aaa+}<RESET> )
EOF
- word_diff --color --word-diff-regex="[a-z]+"
+ diff_with_opts --color --word-diff-regex="[a-z]+"
'
test_expect_success '.gitattributes override config' '
cp expect.non-whitespace-is-word expect &&
- word_diff --color-words
+ diff_with_opts --color-words
'
test_expect_success 'setup: remove diff driver regex' '
@@ -263,7 +267,7 @@ test_expect_success 'use configured regex' '
<GREEN>aeff = aeff * ( aaa<RESET> )
EOF
- word_diff --color-words
+ diff_with_opts --color-words
'
test_expect_success 'test parsing words for newline' '
@@ -279,7 +283,7 @@ test_expect_success 'test parsing words for newline' '
<CYAN>@@ -1 +1 @@<RESET>
aaa (aaa) <GREEN>aaa<RESET>
EOF
- word_diff --color-words="a+"
+ diff_with_opts --color-words="a+"
'
test_expect_success 'test when words are only removed at the end' '
@@ -295,7 +299,7 @@ test_expect_success 'test when words are only removed at the end' '
<CYAN>@@ -1 +1 @@<RESET>
(<RED>:<RESET>
EOF
- word_diff --color-words=.
+ diff_with_opts --color-words=.
'
test_expect_success '--word-diff=none' '
@@ -312,7 +316,7 @@ test_expect_success '--word-diff=none' '
-(:
+(
EOF
- word_diff --word-diff=plain --word-diff=none
+ word_diff plain --word-diff=none
'
test_expect_success 'unset default driver' '
@@ -363,7 +367,7 @@ test_expect_success 'word-diff with diff.sbe' '
[-b-]{+c+}
EOF
test_config diff.suppress-blank-empty true &&
- word_diff --word-diff=plain
+ word_diff plain
'
test_expect_success 'word-diff with no newline at EOF' '
@@ -379,7 +383,7 @@ test_expect_success 'word-diff with no newline at EOF' '
@@ -1 +1 @@
a a [-a-]{+ab+} a a
EOF
- word_diff --word-diff=plain
+ word_diff plain
'
test_expect_success 'setup history with two files' '
--
2.43.GIT
next prev parent reply other threads:[~2024-03-02 9:57 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-28 8:54 Allow setting diff.worddiff=color via gitconfig Olliver Schinagl
2024-03-02 9:57 ` [PATCH 0/2] Support diff.wordDiff config Karthik Nayak
2024-03-02 9:57 ` Karthik Nayak [this message]
2024-03-02 9:57 ` [PATCH 2/2] diff: add 'diff.wordDiff' config option Karthik Nayak
2024-03-02 10:25 ` Eric Sunshine
2024-03-02 18:02 ` Karthik Nayak
2024-03-02 19:57 ` Jean-Noël AVILA
2024-03-02 17:03 ` [PATCH 0/2] Support diff.wordDiff config Junio C Hamano
2024-03-02 18:02 ` Karthik Nayak
2024-03-02 19:57 ` Kristoffer Haugsbakk
2024-03-03 7:23 ` Chris Torek
2024-03-03 17:45 ` Junio C Hamano
2024-03-22 22:08 ` Olliver Schinagl
2024-03-25 21:53 ` Dragan Simic
2024-03-22 22:05 ` Olliver Schinagl
2024-03-22 21:59 ` Olliver Schinagl
2024-03-22 21:57 ` Olliver Schinagl
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=20240302095751.123138-2-karthik.188@gmail.com \
--to=karthik.188@gmail.com \
--cc=git@vger.kernel.org \
--cc=oliver@schinagl.nl \
/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).