Debian Codegraph @

tests/git-error-handling/run-test

raw
1 #!/bin/sh
2
3 # Test error handling and edge cases for git diff processing
4 # This test ensures robust handling of malformed or unusual git diffs
5
6 . ${top_srcdir-.}/tests/common.sh
7
8 # Test 1: Malformed git diff line (missing space)
9 cat << EOF > malformed1.patch
10 diff --gita/file.txt b/file.txt
11 index abc123..def456 100644
12 --- a/file.txt
13 +++ b/file.txt
14 @@ -1 +1 @@
15 -old
16 +new
17 EOF
18
19 # Should handle gracefully and treat as regular diff
20 ${FILTERDIFF} --git-extended-diffs=include malformed1.patch 2>errors1 >result1 || exit 1
21 [ -s errors1 ] && exit 1
22 grep -q "file.txt" result1 || exit 1
23
24 # Test 2: Git diff with missing filenames in git line
25 cat << EOF > malformed2.patch
26 diff --git
27 index abc123..def456 100644
28 --- a/file.txt
29 +++ b/file.txt
30 @@ -1 +1 @@
31 -old
32 +new
33 EOF
34
35 # Should handle gracefully
36 ${FILTERDIFF} --git-extended-diffs=include malformed2.patch 2>errors2 >result2 || exit 1
37 [ -s errors2 ] && exit 1
38
39 # Test 3: Git diff with only one filename in git line
40 cat << EOF > malformed3.patch
41 diff --git a/single-file.txt
42 index abc123..def456 100644
43 --- a/single-file.txt
44 +++ b/single-file.txt
45 @@ -1 +1 @@
46 -old
47 +new
48 EOF
49
50 # Should handle gracefully
51 ${FILTERDIFF} --git-extended-diffs=include malformed3.patch 2>errors3 >result3 || exit 1
52 [ -s errors3 ] && exit 1
53
54 # Test 4: Git diff with unusual prefixes (not a/ b/)
55 cat << EOF > unusual-prefixes.patch
56 diff --git x/file.txt y/file.txt
57 index abc123..def456 100644
58 --- x/file.txt
59 +++ y/file.txt
60 @@ -1 +1 @@
61 -old
62 +new
63 EOF
64
65 # Should handle gracefully
66 ${FILTERDIFF} --git-extended-diffs=include unusual-prefixes.patch 2>errors4 >result4 || exit 1
67 [ -s errors4 ] && exit 1
68 grep -q "file.txt" result4 || exit 1
69
70 # Test 5: Test --git-prefixes with unusual prefixes
71 ${FILTERDIFF} --git-extended-diffs=include --git-prefixes=strip unusual-prefixes.patch 2>errors5 >result5 || exit 1
72 [ -s errors5 ] && exit 1
73 grep -q "file.txt" result5 || exit 1
74
75 # Test 6: Git diff with no prefixes at all
76 cat << EOF > no-prefixes.patch
77 diff --git file.txt file.txt
78 index abc123..def456 100644
79 --- file.txt
80 +++ file.txt
81 @@ -1 +1 @@
82 -old
83 +new
84 EOF
85
86 ${FILTERDIFF} --git-extended-diffs=include --git-prefixes=strip no-prefixes.patch 2>errors6 >result6 || exit 1
87 [ -s errors6 ] && exit 1
88 grep -q "file.txt" result6 || exit 1
89
90 # Test 7: Binary diff with "Binary files" format (standard)
91 cat << EOF > git-binary-patch.patch
92 diff --git a/binary.dat b/binary.dat
93 new file mode 100644
94 index 0000000..1234567
95 Binary files /dev/null and b/binary.dat differ
96 EOF
97
98 ${FILTERDIFF} --git-extended-diffs=include -i "*binary*" git-binary-patch.patch 2>errors7 >result7 || exit 1
99 [ -s errors7 ] && exit 1
100 grep -q "binary.dat" result7 || exit 1
101
102 # Test 8: Test lsdiff with binary patch format
103 ${LSDIFF} --git-extended-diffs=include --git-extended-diffs=include git-binary-patch.patch 2>errors8 >result8 || exit 1
104 [ -s errors8 ] && exit 1
105
106 cat << EOF | cmp - result8 || exit 1
107 a/binary.dat
108 EOF
109
110 # Test 9: Mixed binary formats in one patch
111 cat << EOF > mixed-binary.patch
112 diff --git a/file1.bin b/file1.bin
113 new file mode 100644
114 index 0000000..abc123
115 Binary files /dev/null and b/file1.bin differ
116 diff --git a/file2.dat b/file2.dat
117 new file mode 100644
118 index 0000000..def456
119 GIT binary patch
120 literal 512
121 zcmV+00000000000000000000000000000000000000000000000000000000
122 M000000000000000000000000000000000000000000000000000000000000
123 literal 0
124 HcmV?d00001
125
126 EOF
127
128 ${LSDIFF} --git-extended-diffs=include --git-extended-diffs=include mixed-binary.patch 2>errors9 >result9 || exit 1
129 [ -s errors9 ] && exit 1
130
131 cat << EOF | cmp - result9 || exit 1
132 a/file1.bin
133 a/file2.dat
134 EOF
135
136 # Test 10: Empty git diff (just headers, no content)
137 cat << EOF > empty-git.patch
138 diff --git a/empty.txt b/empty.txt
139 new file mode 100644
140 index 0000000..e69de29
141 --- /dev/null
142 +++ b/empty.txt
143 EOF
144
145 ${FILTERDIFF} --git-extended-diffs=include empty-git.patch 2>errors10 >result10 || exit 1
146 [ -s errors10 ] && exit 1
147 # Empty patch should produce no output
148 [ ! -s result10 ] || exit 1
149
150 exit 0