Skip to content

Commit 8ef0b67

Browse files
committed
Fix grepdiff --status test expectations
The previous test expected '!' for all matching files, but this is incorrect according to the grepdiff(1) documentation. The -s/--status flag should show: + for file additions (old file is /dev/null) - for file removals (new file is /dev/null) ! for file modifications (both files exist) This matches the behavior documented for both grepdiff and lsdiff. The legacy filterdiff implementation in --grep mode has a bug where it always shows '!' regardless of the actual file operation. This test now correctly verifies the documented behavior. The test now comprehensively checks all three status indicators: - First test (pattern 'content'): verifies +, -, and ! - Second test (pattern 'new'): verifies ! for modifications - Third test (with --empty-files-as-absent): verifies that empty files with only additions are treated as new files and show + Note: The implementation does not yet pass these tests. The fixes will come in a later commit. Assisted-by: Claude Code
1 parent 7e30407 commit 8ef0b67

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

tests/grepdiff-status/run-test

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#!/bin/sh
22

33
# Test grepdiff -s/--status option
4-
# Shows file status: + (addition), - (removal), ! (modification)
4+
# According to the documentation, -s should show:
5+
# + for file additions
6+
# - for file removals
7+
# ! for file modifications
58

69
. ${top_srcdir-.}/tests/common.sh
710

@@ -19,20 +22,48 @@ cat << EOF > diff
1922
@@ -1 +1 @@
2023
-old
2124
+new
25+
--- another-modified
26+
+++ another-modified
27+
@@ -1,2 +1,2 @@
28+
context
29+
-old content
30+
+new content
2231
EOF
2332

33+
# Test additions and deletions (files with 'content' pattern)
2434
${GREPDIFF} -s 'content' diff 2>errors >output || exit 1
2535
[ -s errors ] && exit 1
2636

2737
cat << EOF | cmp - output || exit 1
28-
! newfile
29-
! oldfile
38+
+ newfile
39+
- oldfile
40+
! another-modified
3041
EOF
3142

32-
# Test with modification
43+
# Test modification only (file with 'new' pattern)
3344
${GREPDIFF} -s 'new' diff 2>errors >output2 || exit 1
3445
[ -s errors ] && exit 1
3546

3647
cat << EOF | cmp - output2 || exit 1
3748
! modified
49+
! another-modified
50+
EOF
51+
52+
# Test with --empty-files-as-absent
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
3869
EOF

0 commit comments

Comments
 (0)