Debian Codegraph @

tests/grepdiff-status/run-test

raw
1 #!/bin/sh
2
3 # Test grepdiff -s/--status option
4 # According to the documentation, -s should show:
5 # + for file additions
6 # - for file removals
7 # ! for file modifications
8
9 . ${top_srcdir-.}/tests/common.sh
10
11 cat << EOF > diff
12 --- /dev/null
13 +++ newfile
14 @@ -0,0 +1 @@
15 +content
16 --- oldfile
17 +++ /dev/null
18 @@ -1 +0,0 @@
19 -content
20 --- modified
21 +++ modified
22 @@ -1 +1 @@
23 -old
24 +new
25 --- another-modified
26 +++ another-modified
27 @@ -1,2 +1,2 @@
28 context
29 -old content
30 +new content
31 EOF
32
33 # Test additions and deletions (files with 'content' pattern)
34 ${GREPDIFF} -s 'content' diff 2>errors >output || exit 1
35 [ -s errors ] && exit 1
36
37 cat << EOF | cmp - output || exit 1
38 + newfile
39 - oldfile
40 ! another-modified
41 EOF
42
43 # Test modification only (file with 'new' pattern)
44 ${GREPDIFF} -s 'new' diff 2>errors >output2 || exit 1
45 [ -s errors ] && exit 1
46
47 cat << EOF | cmp - output2 || exit 1
48 ! modified
49 ! another-modified
50 EOF
51
52 # Test with --empty-files-as-absent for file addition
53 # File with only additions should be treated as new file
54 cat << EOF > diff3
55 --- emptyfile
56 +++ emptyfile
57 @@ -0,0 +1 @@
58 +content
59 @@ -60 +60 @@
60 -old
61 +new
62 EOF
63
64 ${GREPDIFF} -s --empty-files-as-absent 'content' diff3 2>errors >output3 || exit 1
65 [ -s errors ] && exit 1
66
67 cat << EOF | cmp - output3 || exit 1
68 + emptyfile
69 EOF
70
71 # Test with --empty-files-as-absent for file deletion
72 # File with only deletions should be treated as deleted
73 cat << EOF > diff4
74 --- deletedfile
75 +++ deletedfile
76 @@ -1 +0,0 @@
77 -content
78 @@ -60 +60 @@
79 -old
80 +new
81 EOF
82
83 ${GREPDIFF} -s --empty-files-as-absent 'content' diff4 2>errors >output4 || exit 1
84 [ -s errors ] && exit 1
85
86 cat << EOF | cmp - output4 || exit 1
87 - deletedfile
88 EOF
89
90 # Test with context diff format
91 cat << EOF > diff5
92 *** /dev/null
93 --- newfile-ctx
94 ***************
95 *** 0 ****
96 --- 1 ----
97 + content
98 *** oldfile-ctx
99 --- /dev/null
100 ***************
101 *** 1 ****
102 - content
103 --- 0 ----
104 *** modified-ctx
105 --- modified-ctx
106 ***************
107 *** 1 ****
108 ! old content
109 --- 1 ----
110 ! new content
111 EOF
112
113 ${GREPDIFF} -s 'content' diff5 2>errors >output5 || exit 1
114 [ -s errors ] && exit 1
115
116 cat << EOF | cmp - output5 || exit 1
117 + newfile-ctx
118 - oldfile-ctx
119 ! modified-ctx
120 EOF
121
122 # Test context diff with --empty-files-as-absent
123 cat << EOF > diff6
124 *** emptyfile-ctx
125 --- emptyfile-ctx
126 ***************
127 *** 0 ****
128 --- 1 ----
129 + content
130 ***************
131 *** 60 ****
132 ! old
133 --- 60 ----
134 ! new
135 EOF
136
137 ${GREPDIFF} -s --empty-files-as-absent 'content' diff6 2>errors >output6 || exit 1
138 [ -s errors ] && exit 1
139
140 cat << EOF | cmp - output6 || exit 1
141 + emptyfile-ctx
142 EOF