Skip to content

Commit c3f6cf6

Browse files
committed
Add test for -p vs --strip
Assisted-by: Cursor
1 parent eaf8353 commit c3f6cf6

2 files changed

Lines changed: 89 additions & 0 deletions

File tree

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ TESTS = tests/newline1/run-test \
205205
tests/lscontext3/run-test \
206206
tests/filterb/run-test \
207207
tests/filterp/run-test \
208+
tests/strip-vs-match/run-test \
208209
tests/select1/run-test \
209210
tests/select2/run-test \
210211
tests/select3/run-test \

tests/strip-vs-match/run-test

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/bin/sh
2+
3+
# This is a filterdiff(1) testcase.
4+
# Test: Verify that -p (strip-match) and --strip work independently
5+
# -p should affect filename matching for -i/-x patterns
6+
# --strip should affect output path components
7+
8+
. ${top_srcdir-.}/tests/common.sh
9+
10+
# Create test patch with multi-level paths
11+
cat << EOF > test.patch
12+
--- a/level1/level2/file1.txt
13+
+++ b/level1/level2/file1.txt
14+
@@ -1 +1 @@
15+
-old content in file1
16+
+new content in file1
17+
--- a/level1/level2/file2.c
18+
+++ b/level1/level2/file2.c
19+
@@ -1 +1 @@
20+
-old content in file2
21+
+new content in file2
22+
--- a/other/path/file3.txt
23+
+++ b/other/path/file3.txt
24+
@@ -1 +1 @@
25+
-old content in file3
26+
+new content in file3
27+
EOF
28+
29+
# Test 1: Use -p for filename matching (strip 2 components for matching)
30+
# and --strip for output (strip 1 component from output)
31+
# Should match "level2/file1.txt" after stripping "a/level1/" (2 components)
32+
# But output should have "level1/level2/file1.txt" (strip only 1 component)
33+
${FILTERDIFF} -p2 --strip=1 -i "level2/file1.txt" test.patch 2>errors1 >result1 || exit 1
34+
[ -s errors1 ] && exit 1
35+
36+
cat << EOF | cmp - result1 || exit 1
37+
--- level1/level2/file1.txt
38+
+++ level1/level2/file1.txt
39+
@@ -1 +1 @@
40+
-old content in file1
41+
+new content in file1
42+
EOF
43+
44+
# Test 2: Different -p and --strip values
45+
# Match "level1/level2/file2.c" after stripping 1 component for matching
46+
# But output should have "level2/file2.c" (strip 2 components from output)
47+
${FILTERDIFF} -p1 --strip=2 -i "level1/level2/file2.c" test.patch 2>errors2 >result2 || exit 1
48+
[ -s errors2 ] && exit 1
49+
50+
cat << EOF | cmp - result2 || exit 1
51+
--- level2/file2.c
52+
+++ level2/file2.c
53+
@@ -1 +1 @@
54+
-old content in file2
55+
+new content in file2
56+
EOF
57+
58+
# Test 3: Use -p for exclusion matching
59+
# Exclude "path/file3.txt" after stripping 2 components, but keep others
60+
# Output should strip 1 component
61+
${FILTERDIFF} -p2 --strip=1 -x "path/file3.txt" test.patch 2>errors3 >result3 || exit 1
62+
[ -s errors3 ] && exit 1
63+
64+
cat << EOF | cmp - result3 || exit 1
65+
--- level1/level2/file1.txt
66+
+++ level1/level2/file1.txt
67+
@@ -1 +1 @@
68+
-old content in file1
69+
+new content in file1
70+
--- level1/level2/file2.c
71+
+++ level1/level2/file2.c
72+
@@ -1 +1 @@
73+
-old content in file2
74+
+new content in file2
75+
EOF
76+
77+
# Test 4: Verify that -p without -i/-x gets converted to --strip
78+
# (backward compatibility behavior) - this only happens in non-filter modes like lsdiff
79+
${LSDIFF} -p1 test.patch 2>errors4 >result4 || exit 1
80+
grep -q "guessing that you meant --strip instead" errors4 || exit 1
81+
82+
# The result should be the same as --strip=1
83+
${LSDIFF} --strip=1 test.patch 2>errors5 >result5 || exit 1
84+
[ -s errors5 ] && exit 1
85+
86+
cmp result4 result5 || exit 1
87+
88+
exit 0

0 commit comments

Comments
 (0)