Skip to content

Commit e8034e4

Browse files
committed
Add comprehensive test coverage for grepdiff -s
Expanded the grepdiff-status test to cover additional code paths: 1. File deletion with --empty-files-as-absent: Tests when the new file is empty and should be treated as deleted (displays -) 2. Context diff format: Tests grepdiff -s with context diff format (*** / --- style) to verify correct status display for additions, deletions, and modifications 3. Context diff with --empty-files-as-absent: Tests empty file detection in context diff format These additional test cases ensure complete coverage of the status calculation logic in both do_unified() and do_context() functions, including the empty file handling branches. All 194 tests pass (188 pass + 6 expected failures). Assisted-by: Claude Code
1 parent 5fab49c commit e8034e4

File tree

1 file changed

+74
-1
lines changed

1 file changed

+74
-1
lines changed

tests/grepdiff-status/run-test

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ cat << EOF | cmp - output2 || exit 1
4949
! another-modified
5050
EOF
5151

52-
# Test with --empty-files-as-absent
52+
# Test with --empty-files-as-absent for file addition
5353
# File with only additions should be treated as new file
5454
cat << EOF > diff3
5555
--- emptyfile
@@ -67,3 +67,76 @@ ${GREPDIFF} -s --empty-files-as-absent 'content' diff3 2>errors >output3 || exit
6767
cat << EOF | cmp - output3 || exit 1
6868
+ emptyfile
6969
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

0 commit comments

Comments
 (0)