Debian Codegraph @

tests/lsdiff-range-exclude/run-test

raw
1 #!/bin/sh
2
3 # This is a lsdiff(1) testcase for range exclusion functionality (-F x prefix).
4
5 . ${top_srcdir-.}/tests/common.sh
6
7 # Create a patch with 5 files to test various range exclusion patterns
8 cat << EOF > multi-file.patch
9 --- file1.txt
10 +++ file1.txt
11 @@ -1 +1 @@
12 -old1
13 +new1
14 --- file2.txt
15 +++ file2.txt
16 @@ -1 +1 @@
17 -old2
18 +new2
19 --- file3.txt
20 +++ file3.txt
21 @@ -1 +1 @@
22 -old3
23 +new3
24 --- file4.txt
25 +++ file4.txt
26 @@ -1 +1 @@
27 -old4
28 +new4
29 --- file5.txt
30 +++ file5.txt
31 @@ -1 +1 @@
32 -old5
33 +new5
34 EOF
35
36 # Test 1: Exclude single file (x2) - should show files 1, 3, 4, 5
37 echo "Testing single file exclusion (x2)..."
38 ${LSDIFF} -F x2 multi-file.patch 2>errors1 >result1 || exit 1
39 [ -s errors1 ] && { echo "Unexpected errors in test 1:"; cat errors1; exit 1; }
40
41 cat << EOF | cmp - result1 || { echo "Test 1 failed"; exit 1; }
42 file1.txt
43 file3.txt
44 file4.txt
45 file5.txt
46 EOF
47
48 # Test 2: Exclude comma-separated list (x1,3,5) - should show files 2, 4
49 echo "Testing comma-separated exclusion (x1,3,5)..."
50 ${LSDIFF} -F x1,3,5 multi-file.patch 2>errors2 >result2 || exit 1
51 [ -s errors2 ] && { echo "Unexpected errors in test 2:"; cat errors2; exit 1; }
52
53 cat << EOF | cmp - result2 || { echo "Test 2 failed"; exit 1; }
54 file2.txt
55 file4.txt
56 EOF
57
58 # Test 3: Exclude range (x2-4) - should show files 1, 5
59 echo "Testing range exclusion (x2-4)..."
60 ${LSDIFF} -F x2-4 multi-file.patch 2>errors3 >result3 || exit 1
61 [ -s errors3 ] && { echo "Unexpected errors in test 3:"; cat errors3; exit 1; }
62
63 cat << EOF | cmp - result3 || { echo "Test 3 failed"; exit 1; }
64 file1.txt
65 file5.txt
66 EOF
67
68 # Test 4: Exclude open-ended range (x3-) - should show files 1, 2
69 echo "Testing open-ended range exclusion (x3-)..."
70 ${LSDIFF} -F x3- multi-file.patch 2>errors4 >result4 || exit 1
71 [ -s errors4 ] && { echo "Unexpected errors in test 4:"; cat errors4; exit 1; }
72
73 cat << EOF | cmp - result4 || { echo "Test 4 failed"; exit 1; }
74 file1.txt
75 file2.txt
76 EOF
77
78 # Test 5: Mixed exclusion (x1,4-5) - should show files 2, 3
79 echo "Testing mixed exclusion (x1,4-5)..."
80 ${LSDIFF} -F x1,4-5 multi-file.patch 2>errors5 >result5 || exit 1
81 [ -s errors5 ] && { echo "Unexpected errors in test 5:"; cat errors5; exit 1; }
82
83 cat << EOF | cmp - result5 || { echo "Test 5 failed"; exit 1; }
84 file2.txt
85 file3.txt
86 EOF
87
88 # Test 6: Compare with positive range selection to ensure exclusion works correctly
89 # First test positive selection (2,4) - should show files 2, 4
90 echo "Testing positive range selection for comparison (2,4)..."
91 ${LSDIFF} -F 2,4 multi-file.patch 2>errors6 >result6 || exit 1
92 [ -s errors6 ] && { echo "Unexpected errors in test 6:"; cat errors6; exit 1; }
93
94 cat << EOF | cmp - result6 || { echo "Test 6 failed"; exit 1; }
95 file2.txt
96 file4.txt
97 EOF
98
99 # Test 7: Verify that exclusion of 2,4 gives the complement of positive selection
100 echo "Testing exclusion complement (x2,4)..."
101 ${LSDIFF} -F x2,4 multi-file.patch 2>errors7 >result7 || exit 1
102 [ -s errors7 ] && { echo "Unexpected errors in test 7:"; cat errors7; exit 1; }
103
104 cat << EOF | cmp - result7 || { echo "Test 7 failed"; exit 1; }
105 file1.txt
106 file3.txt
107 file5.txt
108 EOF
109
110 echo "All range exclusion tests passed!"