Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ TESTS = tests/newline1/run-test \
tests/lsdiff15/run-test \
tests/lsdiff-hunks-option/run-test \
tests/lsdiff-lines-option/run-test \
tests/lsdiff-exclusion-combined/run-test \
tests/lsdiff-verbose-levels/run-test \
tests/lsdiff-range-exclude/run-test \
tests/patchview1/run-test \
tests/patchview2/run-test \
tests/fuzz1/run-test \
Expand Down Expand Up @@ -312,7 +314,8 @@ XFAIL_TESTS = \
tests/delhunk6/run-test \
tests/rediff-empty-hunk/run-test \
tests/lsdiff-hunks-option/run-test \
tests/lsdiff-lines-option/run-test
tests/lsdiff-lines-option/run-test \
tests/lsdiff-exclusion-combined/run-test

test-perms: src/combinediff$(EXEEXT) src/flipdiff$(EXEEXT) \
src/lsdiff$(EXEEXT) src/grepdiff$(EXEEXT) src/patchview$(EXEEXT) \
Expand Down
120 changes: 120 additions & 0 deletions tests/lsdiff-exclusion-combined/run-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#!/bin/sh

# This is a lsdiff(1) testcase for exclusion and combined filtering.
# Test: --lines exclusion, --hunks exclusion, and combined filters

. ${top_srcdir-.}/tests/common.sh

cat << EOF > diff
--- file1
+++ file1
@@ -1 +1,2 @@
-A
+a
+b
--- file2
+++ file2
@@ -5 +5,2 @@
-E
+e
+f
@@ -20 +21,2 @@
-G
+g
+h
--- file3
+++ file3
@@ -10 +10,2 @@
-I
+i
+j
@@ -15 +16,2 @@
-K
+k
+l
@@ -25 +27,2 @@
-M
+m
+n
EOF

# Test --lines exclusion: x1-5 (exclude files with hunks touching lines 1-5)
# file1 has hunk at line 1, file2 has hunk at line 5 -> both excluded
# file3 has hunks at lines 10, 15, 25 -> included
${LSDIFF} --lines x1-5 diff 2>errors >lines-exclude-1-5 || exit 1
[ -s errors ] && exit 1

cat << EOF | cmp - lines-exclude-1-5 || exit 1
file3
EOF

# Test --lines exclusion: x15-25 (exclude files with hunks touching lines 15-25)
# file1 has hunk at line 1 -> included
# file2 has hunk at line 20 -> excluded
# file3 has hunks at lines 15, 25 -> excluded
${LSDIFF} --lines x15-25 diff 2>errors >lines-exclude-15-25 || exit 1
[ -s errors ] && exit 1

cat << EOF | cmp - lines-exclude-15-25 || exit 1
file1
EOF

# Test --hunks exclusion: x1 (exclude files with hunk 1)
# All files have hunk 1, so none should be shown
${LSDIFF} --hunks x1 diff 2>errors >hunks-exclude-1 || exit 1
[ -s errors ] && exit 1
[ -s hunks-exclude-1 ] && exit 1 # Should be empty

# Test --hunks exclusion: x2 (exclude files with hunk 2)
# file1 has only 1 hunk -> included
# file2 and file3 have hunk 2 -> excluded
${LSDIFF} --hunks x2 diff 2>errors >hunks-exclude-2 || exit 1
[ -s errors ] && exit 1

cat << EOF | cmp - hunks-exclude-2 || exit 1
file1
EOF

# Test --hunks exclusion: x3 (exclude files with hunk 3)
# file1 and file2 don't have hunk 3 -> included
# file3 has hunk 3 -> excluded
${LSDIFF} --hunks x3 diff 2>errors >hunks-exclude-3 || exit 1
[ -s errors ] && exit 1

cat << EOF | cmp - hunks-exclude-3 || exit 1
file1
file2
EOF

# Test combined filters: --lines 10-25 --hunks 2 (AND logic)
# Must have lines 10-25 AND hunk 2
# file1: no lines 10-25 -> excluded
# file2: has line 20 AND hunk 2 -> included
# file3: has lines 10,15,25 AND hunk 2 -> included
${LSDIFF} --lines 10-25 --hunks 2 diff 2>errors >combined-lines-hunks || exit 1
[ -s errors ] && exit 1

cat << EOF | cmp - combined-lines-hunks || exit 1
file2
file3
EOF

# Test combined filters with exclusion: --lines x1-5 --hunks x3 (AND logic)
# Must NOT have lines 1-5 AND NOT have hunk 3
# file1: has line 1 -> excluded
# file2: has line 5 -> excluded
# file3: no lines 1-5 but has hunk 3 -> excluded
${LSDIFF} --lines x1-5 --hunks x3 diff 2>errors >combined-exclude || exit 1
[ -s errors ] && exit 1
[ -s combined-exclude ] && exit 1 # Should be empty

# Test mixed include/exclude: --lines 10-25 --hunks x1 (AND logic)
# Must have lines 10-25 AND NOT have hunk 1
# file1: no lines 10-25 -> excluded
# file2: has lines 10-25 but has hunk 1 -> excluded
# file3: has lines 10-25 but has hunk 1 -> excluded
${LSDIFF} --lines 10-25 --hunks x1 diff 2>errors >mixed-include-exclude || exit 1
[ -s errors ] && exit 1
[ -s mixed-include-exclude ] && exit 1 # Should be empty

exit 0
1 change: 1 addition & 0 deletions tests/lsdiff-hunks-option/run-test
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,4 @@ EOF
${LSDIFF} --hunks 4 diff 2>errors >hunks4 || exit 1
[ -s errors ] && exit 1
[ -s hunks4 ] && exit 1 # Should be empty
exit 0
1 change: 1 addition & 0 deletions tests/lsdiff-lines-option/run-test
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ EOF
${LSDIFF} --lines 100 diff 2>errors >lines100 || exit 1
[ -s errors ] && exit 1
[ -s lines100 ] && exit 1 # Should be empty
exit 0
110 changes: 110 additions & 0 deletions tests/lsdiff-range-exclude/run-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/bin/sh

# This is a lsdiff(1) testcase for range exclusion functionality (-F x prefix).

. ${top_srcdir-.}/tests/common.sh

# Create a patch with 5 files to test various range exclusion patterns
cat << EOF > multi-file.patch
--- file1.txt
+++ file1.txt
@@ -1 +1 @@
-old1
+new1
--- file2.txt
+++ file2.txt
@@ -1 +1 @@
-old2
+new2
--- file3.txt
+++ file3.txt
@@ -1 +1 @@
-old3
+new3
--- file4.txt
+++ file4.txt
@@ -1 +1 @@
-old4
+new4
--- file5.txt
+++ file5.txt
@@ -1 +1 @@
-old5
+new5
EOF

# Test 1: Exclude single file (x2) - should show files 1, 3, 4, 5
echo "Testing single file exclusion (x2)..."
${LSDIFF} -F x2 multi-file.patch 2>errors1 >result1 || exit 1
[ -s errors1 ] && { echo "Unexpected errors in test 1:"; cat errors1; exit 1; }

cat << EOF | cmp - result1 || { echo "Test 1 failed"; exit 1; }
file1.txt
file3.txt
file4.txt
file5.txt
EOF

# Test 2: Exclude comma-separated list (x1,3,5) - should show files 2, 4
echo "Testing comma-separated exclusion (x1,3,5)..."
${LSDIFF} -F x1,3,5 multi-file.patch 2>errors2 >result2 || exit 1
[ -s errors2 ] && { echo "Unexpected errors in test 2:"; cat errors2; exit 1; }

cat << EOF | cmp - result2 || { echo "Test 2 failed"; exit 1; }
file2.txt
file4.txt
EOF

# Test 3: Exclude range (x2-4) - should show files 1, 5
echo "Testing range exclusion (x2-4)..."
${LSDIFF} -F x2-4 multi-file.patch 2>errors3 >result3 || exit 1
[ -s errors3 ] && { echo "Unexpected errors in test 3:"; cat errors3; exit 1; }

cat << EOF | cmp - result3 || { echo "Test 3 failed"; exit 1; }
file1.txt
file5.txt
EOF

# Test 4: Exclude open-ended range (x3-) - should show files 1, 2
echo "Testing open-ended range exclusion (x3-)..."
${LSDIFF} -F x3- multi-file.patch 2>errors4 >result4 || exit 1
[ -s errors4 ] && { echo "Unexpected errors in test 4:"; cat errors4; exit 1; }

cat << EOF | cmp - result4 || { echo "Test 4 failed"; exit 1; }
file1.txt
file2.txt
EOF

# Test 5: Mixed exclusion (x1,4-5) - should show files 2, 3
echo "Testing mixed exclusion (x1,4-5)..."
${LSDIFF} -F x1,4-5 multi-file.patch 2>errors5 >result5 || exit 1
[ -s errors5 ] && { echo "Unexpected errors in test 5:"; cat errors5; exit 1; }

cat << EOF | cmp - result5 || { echo "Test 5 failed"; exit 1; }
file2.txt
file3.txt
EOF

# Test 6: Compare with positive range selection to ensure exclusion works correctly
# First test positive selection (2,4) - should show files 2, 4
echo "Testing positive range selection for comparison (2,4)..."
${LSDIFF} -F 2,4 multi-file.patch 2>errors6 >result6 || exit 1
[ -s errors6 ] && { echo "Unexpected errors in test 6:"; cat errors6; exit 1; }

cat << EOF | cmp - result6 || { echo "Test 6 failed"; exit 1; }
file2.txt
file4.txt
EOF

# Test 7: Verify that exclusion of 2,4 gives the complement of positive selection
echo "Testing exclusion complement (x2,4)..."
${LSDIFF} -F x2,4 multi-file.patch 2>errors7 >result7 || exit 1
[ -s errors7 ] && { echo "Unexpected errors in test 7:"; cat errors7; exit 1; }

cat << EOF | cmp - result7 || { echo "Test 7 failed"; exit 1; }
file1.txt
file3.txt
file5.txt
EOF

echo "All range exclusion tests passed!"