Debian Codegraph @

tests/rediff4/run-test

raw
1 #!/bin/sh
2
3 # This is a rediff(1) testcase.
4 # Test: Preserve diff command headers in multi-file patches (GitHub issue #48)
5
6 . ${top_srcdir-.}/tests/common.sh
7
8 cat << "EOF" > patch.orig
9 diff -rpU 3 old/a.c new/a.c
10 --- old/a.c 2021-01-07 13:58:44.000000000 +0000
11 +++ new/a.c 2021-01-07 13:55:34.000000000 +0000
12 @@ -1,3 +1,4 @@
13 line1
14 line2
15 +added_line
16 line3
17 diff -rpU 3 old/b.c new/b.c
18 --- old/b.c 2021-01-07 14:01:32.000000000 +0000
19 +++ new/b.c 2021-01-07 13:57:02.000000000 +0000
20 @@ -1,3 +1,4 @@
21 another1
22 another2
23 +another_added
24 another3
25 diff -rpU 3 old/c.c new/c.c
26 --- old/c.c 2021-01-07 14:01:40.000000000 +0000
27 +++ new/c.c 2021-01-07 13:57:30.000000000 +0000
28 @@ -1,3 +1,6 @@
29 +#include <stdio.h>
30 +
31 int main() {
32 return 0;
33 }
34 EOF
35
36 # Test with identical files (no changes) - this was the failing case
37 ${REDIFF} patch.orig patch.orig > patch-rediffed 2>errors || exit 1
38 [ -s errors ] && exit 1
39
40 # Verify all diff command headers are preserved
41 if ! grep -q "^diff -rpU 3 old/a.c new/a.c$" patch-rediffed; then
42 echo "Missing diff header for a.c" >&2
43 exit 1
44 fi
45
46 if ! grep -q "^diff -rpU 3 old/b.c new/b.c$" patch-rediffed; then
47 echo "Missing diff header for b.c" >&2
48 exit 1
49 fi
50
51 if ! grep -q "^diff -rpU 3 old/c.c new/c.c$" patch-rediffed; then
52 echo "Missing diff header for c.c" >&2
53 exit 1
54 fi
55
56 # Verify the output is identical to input when no changes are made
57 cmp patch.orig patch-rediffed || exit 1
58
59 exit 0