Debian Codegraph @

tests/git-binary-formats/run-test

raw
1 #!/bin/sh
2
3 # Test coverage for binary patch content handling
4 # Tests binary patch formats: "GIT binary patch" and "literal"
5
6 . ${top_srcdir-.}/tests/common.sh
7
8 # Test 1: GIT binary patch format
9 cat << 'EOF' > git-binary-patch.patch
10 diff --git a/file1.bin b/file1.bin
11 new file mode 100644
12 index 0000000..abc123
13 Binary files /dev/null and b/file1.bin differ
14 GIT binary patch
15 literal 12
16 TcmZn~00001
17
18 diff --git a/file2.txt b/file2.txt
19 new file mode 100644
20 index 0000000..def456
21 --- /dev/null
22 +++ b/file2.txt
23 @@ -0,0 +1 @@
24 +text content
25 EOF
26
27 # Test 2: literal format binary patch
28 cat << 'EOF' > literal-patch.patch
29 diff --git a/file3.bin b/file3.bin
30 new file mode 100644
31 index 0000000..ghi789
32 Binary files /dev/null and b/file3.bin differ
33 literal 8
34 PcmZn~0001
35
36 diff --git a/file4.txt b/file4.txt
37 new file mode 100644
38 index 0000000..jkl012
39 --- /dev/null
40 +++ b/file4.txt
41 @@ -0,0 +1 @@
42 +more text
43 EOF
44
45 # Test 3: delta format binary patch (working format)
46 cat << 'EOF' > delta-patch.patch
47 diff --git a/file5.bin b/file5.bin
48 new file mode 100644
49 index 0000000..mno345
50 Binary files /dev/null and b/file5.bin differ
51 delta 16
52 XcmZn~00002Tc
53
54 diff --git a/file6.txt b/file6.txt
55 new file mode 100644
56 index 0000000..pqr678
57 --- /dev/null
58 +++ b/file6.txt
59 @@ -0,0 +1 @@
60 +final text
61 EOF
62
63 # Test filtering binary files with GIT binary patch format - should include binary content
64 echo "Testing GIT binary patch format (include)..."
65 ${FILTERDIFF} --git-extended-diffs=include --git-prefixes=strip -i "file1.bin" git-binary-patch.patch 2>errors1 >result1 || exit 1
66 [ -s errors1 ] && { echo "Unexpected errors in test 1:"; cat errors1; exit 1; }
67
68 cat << 'EOF' | cmp - result1 || { echo "Test 1 failed"; exit 1; }
69 diff --git a/file1.bin b/file1.bin
70 new file mode 100644
71 index 0000000..abc123
72 Binary files /dev/null and b/file1.bin differ
73 GIT binary patch
74 literal 12
75 TcmZn~00001
76
77 EOF
78
79 # Test filtering binary files with literal format - should include binary content
80 echo "Testing literal format (include)..."
81 ${FILTERDIFF} --git-extended-diffs=include --git-prefixes=strip -i "file3.bin" literal-patch.patch 2>errors2 >result2 || exit 1
82 [ -s errors2 ] && { echo "Unexpected errors in test 2:"; cat errors2; exit 1; }
83
84 cat << 'EOF' | cmp - result2 || { echo "Test 2 failed"; exit 1; }
85 diff --git a/file3.bin b/file3.bin
86 new file mode 100644
87 index 0000000..ghi789
88 Binary files /dev/null and b/file3.bin differ
89 literal 8
90 PcmZn~0001
91
92 EOF
93
94 # Test filtering binary files with delta format - should include binary content
95 echo "Testing delta format (include)..."
96 ${FILTERDIFF} --git-extended-diffs=include --git-prefixes=strip -i "file5.bin" delta-patch.patch 2>errors3 >result3 || exit 1
97 [ -s errors3 ] && { echo "Unexpected errors in test 3:"; cat errors3; exit 1; }
98
99 cat << 'EOF' | cmp - result3 || { echo "Test 3 failed"; exit 1; }
100 diff --git a/file5.bin b/file5.bin
101 new file mode 100644
102 index 0000000..mno345
103 Binary files /dev/null and b/file5.bin differ
104 delta 16
105 XcmZn~00002Tc
106
107 EOF
108
109 # Test excluding binary files - should skip binary content
110 echo "Testing binary patch exclusion..."
111 ${FILTERDIFF} --git-extended-diffs=include --git-prefixes=strip -x "file1.bin" git-binary-patch.patch 2>errors4 >result4 || exit 1
112 [ -s errors4 ] && { echo "Unexpected errors in test 4:"; cat errors4; exit 1; }
113
114 cat << 'EOF' | cmp - result4 || { echo "Test 4 failed"; exit 1; }
115
116 diff --git a/file2.txt b/file2.txt
117 new file mode 100644
118 index 0000000..def456
119 --- /dev/null
120 +++ b/file2.txt
121 @@ -0,0 +1 @@
122 +text content
123 EOF
124
125 echo "All binary format tests passed!"
126 exit 0