Skip to content

Commit 2064058

Browse files
committed
More lsdiff tests
Assisted-by: Cursor
1 parent 2ea26d1 commit 2064058

File tree

3 files changed

+323
-1
lines changed

3 files changed

+323
-1
lines changed

Makefile.am

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ TESTS = tests/newline1/run-test \
216216
tests/lsdiff-hunks-option/run-test \
217217
tests/lsdiff-lines-option/run-test \
218218
tests/lsdiff-exclusion-combined/run-test \
219+
tests/lsdiff-combination-filters/run-test \
220+
tests/lsdiff-exclusion-mode/run-test \
219221
tests/lsdiff-verbose-levels/run-test \
220222
tests/lsdiff-range-exclude/run-test \
221223
tests/patchview1/run-test \
@@ -347,7 +349,9 @@ if !USE_SCANNER_LSDIFF
347349
XFAIL_TESTS += \
348350
tests/lsdiff-lines-option/run-test \
349351
tests/lsdiff-hunks-option/run-test \
350-
tests/lsdiff-exclusion-combined/run-test
352+
tests/lsdiff-exclusion-combined/run-test \
353+
tests/lsdiff-combination-filters/run-test \
354+
tests/lsdiff-exclusion-mode/run-test
351355
endif
352356

353357
if USE_SCANNER_LSDIFF
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
#!/bin/sh
2+
3+
# Test lsdiff combination filtering with --lines and --hunks together
4+
# This tests the interaction between multiple filtering options
5+
6+
. ${top_srcdir-.}/tests/common.sh
7+
8+
# Create a complex test patch with multiple files and hunks at different lines
9+
cat << EOF > complex.diff
10+
--- file1
11+
+++ file1
12+
@@ -1,2 +1,3 @@
13+
line1
14+
+added at line 2
15+
line2
16+
@@ -10,2 +11,3 @@
17+
line10
18+
+added at line 11
19+
line11
20+
@@ -20,2 +22,3 @@
21+
line20
22+
+added at line 21
23+
line21
24+
--- file2
25+
+++ file2
26+
@@ -5,2 +5,3 @@
27+
line5
28+
+added at line 6
29+
line6
30+
@@ -15,2 +16,3 @@
31+
line15
32+
+added at line 16
33+
line16
34+
--- file3
35+
+++ file3
36+
@@ -8,2 +8,3 @@
37+
line8
38+
+added at line 9
39+
line9
40+
@@ -25,2 +26,3 @@
41+
line25
42+
+added at line 26
43+
line26
44+
@@ -30,2 +32,3 @@
45+
line30
46+
+added at line 31
47+
line31
48+
EOF
49+
50+
# Test 1: Combination of --lines and --hunks (both must match)
51+
# Files with hunks touching lines 1-15 AND having hunk #2
52+
# file1: hunks at lines 1,10,20 (hunks 1,2,3) -> lines 1,10 in range, has hunk 2 ✓
53+
# file2: hunks at lines 5,15 (hunks 1,2) -> both lines in range, has hunk 2 ✓
54+
# file3: hunks at lines 8,25,30 (hunks 1,2,3) -> line 8 in range, has hunk 2 ✓
55+
${LSDIFF} --lines 1-15 --hunks 2 complex.diff 2>errors1 >result1 || exit 1
56+
[ -s errors1 ] && exit 1
57+
58+
cat << EOF | cmp - result1 || exit 1
59+
file1
60+
file2
61+
file3
62+
EOF
63+
64+
# Test 2: More restrictive combination
65+
# Files with hunks touching lines 1-10 AND having hunk #1
66+
# file1: lines 1,10 in range, has hunk 1 ✓
67+
# file2: line 5 in range, has hunk 1 ✓
68+
# file3: line 8 in range, has hunk 1 ✓
69+
${LSDIFF} --lines 1-10 --hunks 1 complex.diff 2>errors2 >result2 || exit 1
70+
[ -s errors2 ] && exit 1
71+
72+
cat << EOF | cmp - result2 || exit 1
73+
file1
74+
file2
75+
file3
76+
EOF
77+
78+
# Test 3: Very restrictive combination (no matches expected)
79+
# Files with hunks touching lines 100-200 AND having hunk #1
80+
# No files have hunks in lines 100-200
81+
${LSDIFF} --lines 100-200 --hunks 1 complex.diff 2>errors3 >result3 || exit 1
82+
[ -s errors3 ] && exit 1
83+
[ -s result3 ] && exit 1 # Should be empty
84+
85+
# Test 4: Combination with --files range
86+
# Files #1-2 with hunks touching lines 10-20 AND having hunk #2
87+
# file1 (file #1): lines 10,20 in range, has hunk 2 ✓
88+
# file2 (file #2): line 15 in range, has hunk 2 ✓
89+
# file3 (file #3): not in file range ✗
90+
${LSDIFF} --files 1-2 --lines 10-20 --hunks 2 complex.diff 2>errors4 >result4 || exit 1
91+
[ -s errors4 ] && exit 1
92+
93+
cat << EOF | cmp - result4 || exit 1
94+
file1
95+
file2
96+
EOF
97+
98+
# Test 5: Test with -E (empty-files-as-absent) and combinations
99+
# Create a patch with empty files
100+
cat << EOF > empty-files.diff
101+
--- empty1
102+
+++ empty1
103+
@@ -0,0 +1,2 @@
104+
+line1
105+
+line2
106+
--- empty2
107+
+++ empty2
108+
@@ -1,2 +0,0 @@
109+
-line1
110+
-line2
111+
--- normal
112+
+++ normal
113+
@@ -5,2 +5,3 @@
114+
line5
115+
+added
116+
line6
117+
EOF
118+
119+
# Test empty files with combination filters
120+
# empty1: orig_offset=0 (not in range 1-10), hunk 1 ✓ -> NOT included (lines filter fails)
121+
# empty2: orig_offset=1, orig_count=2 (range 1-2, overlaps 1-10), hunk 1 ✓ -> included
122+
# normal: orig_offset=5, orig_count=2 (range 5-6, overlaps 1-10), hunk 1 ✓ -> included
123+
${LSDIFF} -E --lines 1-10 --hunks 1 empty-files.diff 2>errors5 >result5 || exit 1
124+
[ -s errors5 ] && exit 1
125+
126+
cat << EOF | cmp - result5 || exit 1
127+
empty2
128+
normal
129+
EOF
130+
131+
# Test 6: Combination with status display
132+
${LSDIFF} -s --lines 1-15 --hunks 2 complex.diff 2>errors6 >result6 || exit 1
133+
[ -s errors6 ] && exit 1
134+
135+
cat << EOF | cmp - result6 || exit 1
136+
! file1
137+
! file2
138+
! file3
139+
EOF
140+
141+
# Test 7: Combination with verbose mode and line numbers
142+
${LSDIFF} -n --lines 10-15 --hunks 2 complex.diff 2>errors7 >result7 || exit 1
143+
[ -s errors7 ] && exit 1
144+
145+
# Should show files with line numbers (exact format may vary)
146+
[ -s result7 ] || exit 1
147+
grep -q "file1" result7 || exit 1
148+
grep -q "file2" result7 || exit 1
149+
150+
echo "✓ All combination filtering tests passed"
151+
exit 0
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
#!/bin/sh
2+
3+
# Test lsdiff exclusion mode for --lines and --hunks options
4+
# Tests the 'x' prefix syntax for excluding ranges
5+
6+
. ${top_srcdir-.}/tests/common.sh
7+
8+
# Create test patch with files having hunks at known line ranges
9+
cat << EOF > test.diff
10+
--- file1
11+
+++ file1
12+
@@ -1,2 +1,3 @@
13+
line1
14+
+added
15+
line2
16+
@@ -10,2 +11,3 @@
17+
line10
18+
+added
19+
line11
20+
--- file2
21+
+++ file2
22+
@@ -5,2 +5,3 @@
23+
line5
24+
+added
25+
line6
26+
@@ -15,2 +16,3 @@
27+
line15
28+
+added
29+
line16
30+
@@ -25,2 +27,3 @@
31+
line25
32+
+added
33+
line26
34+
--- file3
35+
+++ file3
36+
@@ -8,2 +8,3 @@
37+
line8
38+
+added
39+
line9
40+
--- file4
41+
+++ file4
42+
@@ -20,2 +20,3 @@
43+
line20
44+
+added
45+
line21
46+
@@ -30,2 +31,3 @@
47+
line30
48+
+added
49+
line31
50+
EOF
51+
52+
# Test 1: Exclude files with hunks touching lines 1-10 (--lines x1-10)
53+
# file1: has hunks at lines 1,10 -> EXCLUDED
54+
# file2: has hunks at lines 5,15,25 -> line 5 in excluded range -> EXCLUDED
55+
# file3: has hunk at line 8 -> EXCLUDED
56+
# file4: has hunks at lines 20,30 -> NOT EXCLUDED
57+
${LSDIFF} --lines x1-10 test.diff 2>errors1 >result1 || exit 1
58+
[ -s errors1 ] && exit 1
59+
60+
cat << EOF | cmp - result1 || exit 1
61+
file4
62+
EOF
63+
64+
# Test 2: Exclude files with hunks touching specific line 15 (--lines x15)
65+
# file1: no hunks at line 15 -> NOT EXCLUDED
66+
# file2: has hunk at line 15 -> EXCLUDED
67+
# file3: no hunks at line 15 -> NOT EXCLUDED
68+
# file4: no hunks at line 15 -> NOT EXCLUDED
69+
${LSDIFF} --lines x15 test.diff 2>errors2 >result2 || exit 1
70+
[ -s errors2 ] && exit 1
71+
72+
cat << EOF | cmp - result2 || exit 1
73+
file1
74+
file3
75+
file4
76+
EOF
77+
78+
# Test 3: Exclude files with hunk #2 (--hunks x2)
79+
# file1: has 2 hunks -> has hunk #2 -> EXCLUDED
80+
# file2: has 3 hunks -> has hunk #2 -> EXCLUDED
81+
# file3: has 1 hunk -> no hunk #2 -> NOT EXCLUDED
82+
# file4: has 2 hunks -> has hunk #2 -> EXCLUDED
83+
${LSDIFF} --hunks x2 test.diff 2>errors3 >result3 || exit 1
84+
[ -s errors3 ] && exit 1
85+
86+
cat << EOF | cmp - result3 || exit 1
87+
file3
88+
EOF
89+
90+
# Test 4: Exclude files with hunk #1 (--hunks x1) - should exclude all files
91+
# All files have at least hunk #1
92+
${LSDIFF} --hunks x1 test.diff 2>errors4 >result4 || exit 1
93+
[ -s errors4 ] && exit 1
94+
[ -s result4 ] && exit 1 # Should be empty
95+
96+
# Test 5: Exclude files with hunks in range 2-3 (--hunks x2-3)
97+
# file1: has hunks 1,2 -> has hunk 2 -> EXCLUDED
98+
# file2: has hunks 1,2,3 -> has hunks 2,3 -> EXCLUDED
99+
# file3: has hunk 1 -> no hunks 2-3 -> NOT EXCLUDED
100+
# file4: has hunks 1,2 -> has hunk 2 -> EXCLUDED
101+
${LSDIFF} --hunks x2-3 test.diff 2>errors5 >result5 || exit 1
102+
[ -s errors5 ] && exit 1
103+
104+
cat << EOF | cmp - result5 || exit 1
105+
file3
106+
EOF
107+
108+
# Test 6: Combination exclusion - exclude lines 1-5 AND hunk 3
109+
# Only files that have BOTH excluded criteria should be excluded
110+
# file1: lines 1,10 (line 1 in excluded range) AND no hunk 3 -> EXCLUDED (lines)
111+
# file2: lines 5,15,25 (line 5 in excluded range) AND has hunk 3 -> EXCLUDED (both)
112+
# file3: line 8 (not in excluded range) AND no hunk 3 -> NOT EXCLUDED
113+
# file4: lines 20,30 (not in excluded range) AND no hunk 3 -> NOT EXCLUDED
114+
${LSDIFF} --lines x1-5 --hunks x3 test.diff 2>errors6 >result6 || exit 1
115+
[ -s errors6 ] && exit 1
116+
117+
cat << EOF | cmp - result6 || exit 1
118+
file3
119+
file4
120+
EOF
121+
122+
# Test 7: Test exclusion with --files range
123+
# Exclude files #1-2, then apply line exclusion
124+
${LSDIFF} --files x1-2 --lines x20-30 test.diff 2>errors7 >result7 || exit 1
125+
[ -s errors7 ] && exit 1
126+
127+
# file1,file2 excluded by --files x1-2
128+
# file3: not excluded by files, line 8 not in x20-30 -> NOT EXCLUDED
129+
# file4: not excluded by files, lines 20,30 in x20-30 -> EXCLUDED
130+
cat << EOF | cmp - result7 || exit 1
131+
file3
132+
EOF
133+
134+
# Test 8: Test exclusion with status display
135+
${LSDIFF} -s --lines x1-10 test.diff 2>errors8 >result8 || exit 1
136+
[ -s errors8 ] && exit 1
137+
138+
cat << EOF | cmp - result8 || exit 1
139+
! file4
140+
EOF
141+
142+
# Test 9: Complex exclusion test with empty ranges
143+
# Create a patch where exclusion results in no matches
144+
${LSDIFF} --lines x1-100 test.diff 2>errors9 >result9 || exit 1
145+
[ -s errors9 ] && exit 1
146+
[ -s result9 ] && exit 1 # Should be empty - all files excluded
147+
148+
# Test 10: Test exclusion range parsing edge cases
149+
# Exclude single hunk number
150+
${LSDIFF} --hunks x1 test.diff 2>errors10 >result10 || exit 1
151+
[ -s errors10 ] && exit 1
152+
[ -s result10 ] && exit 1 # Should be empty
153+
154+
# Test 11: Exclude open-ended range (x10-)
155+
# file1: lines 1,10 -> line 10 in x10- -> EXCLUDED
156+
# file2: lines 5,15,25 -> lines 15,25 in x10- -> EXCLUDED
157+
# file3: line 8 -> not in x10- -> NOT EXCLUDED
158+
# file4: lines 20,30 -> both in x10- -> EXCLUDED
159+
${LSDIFF} --lines x10- test.diff 2>errors11 >result11 || exit 1
160+
[ -s errors11 ] && exit 1
161+
162+
cat << EOF | cmp - result11 || exit 1
163+
file3
164+
EOF
165+
166+
echo "✓ All exclusion mode tests passed"
167+
exit 0

0 commit comments

Comments
 (0)