Skip to content

Commit 74cfa7b

Browse files
stefanbellergitster
authored andcommitted
t4015: avoid git as a pipe input
In t4015 we have a pattern of git diff [<options, related to color>] | grep -v "index" | test_decode_color >actual && to produce output that we want to test against. This pattern was introduced in 86b452e (diff.c: add dimming to moved line detection, 2017-06-30) as then the focus on getting the colors right. However the pattern used is not best practice as we do care about the exit code of Git. So let's not have Git as the upstream of a pipe. Piping the output of grep to some function is fine as we assume grep to be un-flawed in our test suite. Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 21c770b commit 74cfa7b

File tree

1 file changed

+20
-30
lines changed

1 file changed

+20
-30
lines changed

t/t4015-diff-whitespace.sh

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,9 +1271,8 @@ test_expect_success 'detect permutations inside moved code -- dimmed_zebra' '
12711271
test_config color.diff.newMovedDimmed "normal cyan" &&
12721272
test_config color.diff.oldMovedAlternativeDimmed "normal blue" &&
12731273
test_config color.diff.newMovedAlternativeDimmed "normal yellow" &&
1274-
git diff HEAD --no-renames --color-moved=dimmed_zebra --color |
1275-
grep -v "index" |
1276-
test_decode_color >actual &&
1274+
git diff HEAD --no-renames --color-moved=dimmed_zebra --color >actual.raw &&
1275+
grep -v "index" actual.raw | test_decode_color >actual &&
12771276
cat <<-\EOF >expected &&
12781277
<BOLD>diff --git a/lines.txt b/lines.txt<RESET>
12791278
<BOLD>--- a/lines.txt<RESET>
@@ -1315,9 +1314,8 @@ test_expect_success 'cmd option assumes configured colored-moved' '
13151314
test_config color.diff.oldMovedAlternativeDimmed "normal blue" &&
13161315
test_config color.diff.newMovedAlternativeDimmed "normal yellow" &&
13171316
test_config diff.colorMoved zebra &&
1318-
git diff HEAD --no-renames --color-moved --color |
1319-
grep -v "index" |
1320-
test_decode_color >actual &&
1317+
git diff HEAD --no-renames --color-moved --color >actual.raw &&
1318+
grep -v "index" actual.raw | test_decode_color >actual &&
13211319
cat <<-\EOF >expected &&
13221320
<BOLD>diff --git a/lines.txt b/lines.txt<RESET>
13231321
<BOLD>--- a/lines.txt<RESET>
@@ -1395,9 +1393,8 @@ test_expect_success 'move detection ignoring whitespace ' '
13951393
line 4
13961394
line 5
13971395
EOF
1398-
git diff HEAD --no-renames --color-moved --color |
1399-
grep -v "index" |
1400-
test_decode_color >actual &&
1396+
git diff HEAD --no-renames --color-moved --color >actual.raw &&
1397+
grep -v "index" actual.raw | test_decode_color >actual &&
14011398
cat <<-\EOF >expected &&
14021399
<BOLD>diff --git a/lines.txt b/lines.txt<RESET>
14031400
<BOLD>--- a/lines.txt<RESET>
@@ -1419,9 +1416,8 @@ test_expect_success 'move detection ignoring whitespace ' '
14191416
EOF
14201417
test_cmp expected actual &&
14211418
1422-
git diff HEAD --no-renames -w --color-moved --color |
1423-
grep -v "index" |
1424-
test_decode_color >actual &&
1419+
git diff HEAD --no-renames -w --color-moved --color >actual.raw &&
1420+
grep -v "index" actual.raw | test_decode_color >actual &&
14251421
cat <<-\EOF >expected &&
14261422
<BOLD>diff --git a/lines.txt b/lines.txt<RESET>
14271423
<BOLD>--- a/lines.txt<RESET>
@@ -1459,9 +1455,8 @@ test_expect_success 'move detection ignoring whitespace changes' '
14591455
line 5
14601456
EOF
14611457
1462-
git diff HEAD --no-renames --color-moved --color |
1463-
grep -v "index" |
1464-
test_decode_color >actual &&
1458+
git diff HEAD --no-renames --color-moved --color >actual.raw &&
1459+
grep -v "index" actual.raw | test_decode_color >actual &&
14651460
cat <<-\EOF >expected &&
14661461
<BOLD>diff --git a/lines.txt b/lines.txt<RESET>
14671462
<BOLD>--- a/lines.txt<RESET>
@@ -1483,9 +1478,8 @@ test_expect_success 'move detection ignoring whitespace changes' '
14831478
EOF
14841479
test_cmp expected actual &&
14851480
1486-
git diff HEAD --no-renames -b --color-moved --color |
1487-
grep -v "index" |
1488-
test_decode_color >actual &&
1481+
git diff HEAD --no-renames -b --color-moved --color >actual.raw &&
1482+
grep -v "index" actual.raw | test_decode_color >actual &&
14891483
cat <<-\EOF >expected &&
14901484
<BOLD>diff --git a/lines.txt b/lines.txt<RESET>
14911485
<BOLD>--- a/lines.txt<RESET>
@@ -1526,9 +1520,8 @@ test_expect_success 'move detection ignoring whitespace at eol' '
15261520
# avoid cluttering the output with complaints about our eol whitespace
15271521
test_config core.whitespace -blank-at-eol &&
15281522
1529-
git diff HEAD --no-renames --color-moved --color |
1530-
grep -v "index" |
1531-
test_decode_color >actual &&
1523+
git diff HEAD --no-renames --color-moved --color >actual.raw &&
1524+
grep -v "index" actual.raw | test_decode_color >actual &&
15321525
cat <<-\EOF >expected &&
15331526
<BOLD>diff --git a/lines.txt b/lines.txt<RESET>
15341527
<BOLD>--- a/lines.txt<RESET>
@@ -1550,9 +1543,8 @@ test_expect_success 'move detection ignoring whitespace at eol' '
15501543
EOF
15511544
test_cmp expected actual &&
15521545
1553-
git diff HEAD --no-renames --ignore-space-at-eol --color-moved --color |
1554-
grep -v "index" |
1555-
test_decode_color >actual &&
1546+
git diff HEAD --no-renames --ignore-space-at-eol --color-moved --color >actual.raw &&
1547+
grep -v "index" actual.raw | test_decode_color >actual &&
15561548
cat <<-\EOF >expected &&
15571549
<BOLD>diff --git a/lines.txt b/lines.txt<RESET>
15581550
<BOLD>--- a/lines.txt<RESET>
@@ -1597,9 +1589,8 @@ test_expect_success '--color-moved block at end of diff output respects MIN_ALNU
15971589
irrelevant_line
15981590
EOF
15991591
1600-
git diff HEAD --color-moved=zebra --color --no-renames |
1601-
grep -v "index" |
1602-
test_decode_color >actual &&
1592+
git diff HEAD --color-moved=zebra --color --no-renames >actual.raw &&
1593+
grep -v "index" actual.raw | test_decode_color >actual &&
16031594
cat >expected <<-\EOF &&
16041595
<BOLD>diff --git a/bar b/bar<RESET>
16051596
<BOLD>--- a/bar<RESET>
@@ -1636,9 +1627,8 @@ test_expect_success '--color-moved respects MIN_ALNUM_COUNT' '
16361627
nineteen chars 456789
16371628
EOF
16381629
1639-
git diff HEAD --color-moved=zebra --color --no-renames |
1640-
grep -v "index" |
1641-
test_decode_color >actual &&
1630+
git diff HEAD --color-moved=zebra --color --no-renames >actual.raw &&
1631+
grep -v "index" actual.raw | test_decode_color >actual &&
16421632
cat >expected <<-\EOF &&
16431633
<BOLD>diff --git a/bar b/bar<RESET>
16441634
<BOLD>--- a/bar<RESET>

0 commit comments

Comments
 (0)