| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# This is a lsdiff(1) testcase for --hunks option. |
| 4 |
# Test: Select specific hunks from files |
| 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 --hunks 1 (first hunk - all files have at least 1 hunk) |
| 42 |
${LSDIFF} --hunks 1 diff 2>errors >hunks1 || exit 1 |
| 43 |
[ -s errors ] && exit 1 |
| 44 |
|
| 45 |
cat << EOF | cmp - hunks1 || exit 1 |
| 46 |
file1 |
| 47 |
file2 |
| 48 |
file3 |
| 49 |
EOF |
| 50 |
|
| 51 |
# Test --hunks 2 (second hunk - only file2 and file3 have 2+ hunks) |
| 52 |
${LSDIFF} --hunks 2 diff 2>errors >hunks2 || exit 1 |
| 53 |
[ -s errors ] && exit 1 |
| 54 |
|
| 55 |
cat << EOF | cmp - hunks2 || exit 1 |
| 56 |
file2 |
| 57 |
file3 |
| 58 |
EOF |
| 59 |
|
| 60 |
# Test --hunks 3 (third hunk - only file3 has 3 hunks) |
| 61 |
${LSDIFF} --hunks 3 diff 2>errors >hunks3 || exit 1 |
| 62 |
[ -s errors ] && exit 1 |
| 63 |
|
| 64 |
cat << EOF | cmp - hunks3 || exit 1 |
| 65 |
file3 |
| 66 |
EOF |
| 67 |
|
| 68 |
# Test --hunks 1-2 (range: first and second hunks - all files have hunk 1, file2 and file3 have hunk 2) |
| 69 |
${LSDIFF} --hunks 1-2 diff 2>errors >hunks1-2 || exit 1 |
| 70 |
[ -s errors ] && exit 1 |
| 71 |
|
| 72 |
cat << EOF | cmp - hunks1-2 || exit 1 |
| 73 |
file1 |
| 74 |
file2 |
| 75 |
file3 |
| 76 |
EOF |
| 77 |
|
| 78 |
# Test --hunks 2-3 (range: second and third hunks - file2 has hunk 2, file3 has hunks 2 and 3) |
| 79 |
${LSDIFF} --hunks 2-3 diff 2>errors >hunks2-3 || exit 1 |
| 80 |
[ -s errors ] && exit 1 |
| 81 |
|
| 82 |
cat << EOF | cmp - hunks2-3 || exit 1 |
| 83 |
file2 |
| 84 |
file3 |
| 85 |
EOF |
| 86 |
|
| 87 |
# Test --hunks 4 (fourth hunk - no files have 4 hunks, should be empty) |
| 88 |
${LSDIFF} --hunks 4 diff 2>errors >hunks4 || exit 1 |
| 89 |
[ -s errors ] && exit 1 |
| 90 |
[ -s hunks4 ] && exit 1 # Should be empty |
| 91 |
exit 0 |