From 05fdaf9ecabf72c88a0569062cfb852714727ee9 Mon Sep 17 00:00:00 2001 From: Tim Waugh Date: Tue, 16 Sep 2025 16:18:03 +0100 Subject: [PATCH 1/3] New lsdiff: add file range exclusion and a test for it Assisted-by: Cursor --- Makefile.am | 1 + tests/lsdiff-range-exclude/run-test | 110 ++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100755 tests/lsdiff-range-exclude/run-test diff --git a/Makefile.am b/Makefile.am index b6fce229..53e84711 100644 --- a/Makefile.am +++ b/Makefile.am @@ -189,6 +189,7 @@ TESTS = tests/newline1/run-test \ tests/lsdiff-hunks-option/run-test \ tests/lsdiff-lines-option/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 \ diff --git a/tests/lsdiff-range-exclude/run-test b/tests/lsdiff-range-exclude/run-test new file mode 100755 index 00000000..db6eac46 --- /dev/null +++ b/tests/lsdiff-range-exclude/run-test @@ -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!" From b0d8bccb89a89329e02a102a2fa59c601501f29a Mon Sep 17 00:00:00 2001 From: Tim Waugh Date: Thu, 18 Sep 2025 15:13:18 +0100 Subject: [PATCH 2/3] Fix lsdiff-lines-option and lsdiff-hunks-option tests --- tests/lsdiff-hunks-option/run-test | 1 + tests/lsdiff-lines-option/run-test | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/lsdiff-hunks-option/run-test b/tests/lsdiff-hunks-option/run-test index 572500f2..c2d8abbd 100755 --- a/tests/lsdiff-hunks-option/run-test +++ b/tests/lsdiff-hunks-option/run-test @@ -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 diff --git a/tests/lsdiff-lines-option/run-test b/tests/lsdiff-lines-option/run-test index cdf6981a..6cc789b1 100755 --- a/tests/lsdiff-lines-option/run-test +++ b/tests/lsdiff-lines-option/run-test @@ -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 From 5035b3407866c20b7931dce522e8f5c900cc722c Mon Sep 17 00:00:00 2001 From: Tim Waugh Date: Thu, 18 Sep 2025 15:06:58 +0100 Subject: [PATCH 3/3] New test case for lsdiff, for combining --lines and --hunks filters Assisted-by: Cursor --- Makefile.am | 4 +- tests/lsdiff-exclusion-combined/run-test | 120 +++++++++++++++++++++++ 2 files changed, 123 insertions(+), 1 deletion(-) create mode 100755 tests/lsdiff-exclusion-combined/run-test diff --git a/Makefile.am b/Makefile.am index 53e84711..e9859e33 100644 --- a/Makefile.am +++ b/Makefile.am @@ -188,6 +188,7 @@ 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 \ @@ -313,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) \ diff --git a/tests/lsdiff-exclusion-combined/run-test b/tests/lsdiff-exclusion-combined/run-test new file mode 100755 index 00000000..2a279d95 --- /dev/null +++ b/tests/lsdiff-exclusion-combined/run-test @@ -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