Debian Codegraph @

tests/lsdiff-exclusion-combined/run-test

raw
1 #!/bin/sh
2
3 # This is a lsdiff(1) testcase for exclusion and combined filtering.
4 # Test: --lines exclusion, --hunks exclusion, and combined filters
5
6 . ${top_srcdir-.}/tests/common.sh
7
8 cat << EOF > diff
9 --- file1
10 +++ file1
11 @@ -1 +1,2 @@
12 -A
13 +a
14 +b
15 --- file2
16 +++ file2
17 @@ -5 +5,2 @@
18 -E
19 +e
20 +f
21 @@ -20 +21,2 @@
22 -G
23 +g
24 +h
25 --- file3
26 +++ file3
27 @@ -10 +10,2 @@
28 -I
29 +i
30 +j
31 @@ -15 +16,2 @@
32 -K
33 +k
34 +l
35 @@ -25 +27,2 @@
36 -M
37 +m
38 +n
39 EOF
40
41 # Test --lines exclusion: x1-5 (exclude files with hunks touching lines 1-5)
42 # file1 has hunk at line 1, file2 has hunk at line 5 -> both excluded
43 # file3 has hunks at lines 10, 15, 25 -> included
44 ${LSDIFF} --lines x1-5 diff 2>errors >lines-exclude-1-5 || exit 1
45 [ -s errors ] && exit 1
46
47 cat << EOF | cmp - lines-exclude-1-5 || exit 1
48 file3
49 EOF
50
51 # Test --lines exclusion: x15-25 (exclude files with hunks touching lines 15-25)
52 # file1 has hunk at line 1 -> included
53 # file2 has hunk at line 20 -> excluded
54 # file3 has hunks at lines 15, 25 -> excluded
55 ${LSDIFF} --lines x15-25 diff 2>errors >lines-exclude-15-25 || exit 1
56 [ -s errors ] && exit 1
57
58 cat << EOF | cmp - lines-exclude-15-25 || exit 1
59 file1
60 EOF
61
62 # Test --hunks exclusion: x1 (exclude files with hunk 1)
63 # All files have hunk 1, so none should be shown
64 ${LSDIFF} --hunks x1 diff 2>errors >hunks-exclude-1 || exit 1
65 [ -s errors ] && exit 1
66 [ -s hunks-exclude-1 ] && exit 1 # Should be empty
67
68 # Test --hunks exclusion: x2 (exclude files with hunk 2)
69 # file1 has only 1 hunk -> included
70 # file2 and file3 have hunk 2 -> excluded
71 ${LSDIFF} --hunks x2 diff 2>errors >hunks-exclude-2 || exit 1
72 [ -s errors ] && exit 1
73
74 cat << EOF | cmp - hunks-exclude-2 || exit 1
75 file1
76 EOF
77
78 # Test --hunks exclusion: x3 (exclude files with hunk 3)
79 # file1 and file2 don't have hunk 3 -> included
80 # file3 has hunk 3 -> excluded
81 ${LSDIFF} --hunks x3 diff 2>errors >hunks-exclude-3 || exit 1
82 [ -s errors ] && exit 1
83
84 cat << EOF | cmp - hunks-exclude-3 || exit 1
85 file1
86 file2
87 EOF
88
89 # Test combined filters: --lines 10-25 --hunks 2 (AND logic)
90 # Must have lines 10-25 AND hunk 2
91 # file1: no lines 10-25 -> excluded
92 # file2: has line 20 AND hunk 2 -> included
93 # file3: has lines 10,15,25 AND hunk 2 -> included
94 ${LSDIFF} --lines 10-25 --hunks 2 diff 2>errors >combined-lines-hunks || exit 1
95 [ -s errors ] && exit 1
96
97 cat << EOF | cmp - combined-lines-hunks || exit 1
98 file2
99 file3
100 EOF
101
102 # Test combined filters with exclusion: --lines x1-5 --hunks x3 (AND logic)
103 # Must NOT have lines 1-5 AND NOT have hunk 3
104 # file1: has line 1 -> excluded
105 # file2: has line 5 -> excluded
106 # file3: no lines 1-5 but has hunk 3 -> excluded
107 ${LSDIFF} --lines x1-5 --hunks x3 diff 2>errors >combined-exclude || exit 1
108 [ -s errors ] && exit 1
109 [ -s combined-exclude ] && exit 1 # Should be empty
110
111 # Test mixed include/exclude: --lines 10-25 --hunks x1 (AND logic)
112 # Must have lines 10-25 AND NOT have hunk 1
113 # file1: no lines 10-25 -> excluded
114 # file2: has lines 10-25 but has hunk 1 -> excluded
115 # file3: has lines 10-25 but has hunk 1 -> excluded
116 ${LSDIFF} --lines 10-25 --hunks x1 diff 2>errors >mixed-include-exclude || exit 1
117 [ -s errors ] && exit 1
118 [ -s mixed-include-exclude ] && exit 1 # Should be empty
119
120 exit 0