Skip to content

Commit 60a60b3

Browse files
committed
Add tests for interdiff fuzzy diffing
1 parent a32d159 commit 60a60b3

File tree

9 files changed

+3149
-1
lines changed

9 files changed

+3149
-1
lines changed

Makefile.am

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,15 @@ TESTS = tests/newline1/run-test \
432432
tests/git-deleted-file/run-test \
433433
tests/git-pure-rename/run-test \
434434
tests/git-diff-edge-cases/run-test \
435-
tests/malformed-diff-headers/run-test
435+
tests/malformed-diff-headers/run-test \
436+
tests/fuzzy1/run-test \
437+
tests/fuzzy2/run-test \
438+
tests/fuzzy3/run-test \
439+
tests/fuzzy4/run-test \
440+
tests/fuzzy5/run-test \
441+
tests/fuzzy6/run-test \
442+
tests/fuzzy7/run-test \
443+
tests/fuzzy8/run-test
436444

437445
# Scanner tests (only when scanner-patchfilter is enabled)
438446
if USE_SCANNER_PATCHFILTER

tests/fuzzy1/run-test

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/sh
2+
3+
# This is an interdiff(1) testcase.
4+
# Test: Fuzzy diffing with one rejected hunk per patched file.
5+
6+
7+
. ${top_srcdir-.}/tests/common.sh
8+
9+
cat << 'EOF' > patch1
10+
--- file
11+
+++ file
12+
@@ -1,4 +1,4 @@
13+
-line 1
14+
+LINE 1
15+
line 2
16+
line 3
17+
line 4
18+
EOF
19+
20+
cat << 'EOF' > patch2
21+
--- file
22+
+++ file
23+
@@ -5,9 +5,6 @@
24+
line 5
25+
if
26+
1
27+
-fi
28+
-if
29+
-2
30+
fi
31+
A
32+
B
33+
EOF
34+
35+
cat << 'EOF' > expected
36+
diff -u file file
37+
--- file
38+
+++ file
39+
@@ -1,4 +1,4 @@ INTERDIFF: rejected hunk from patch1, cannot diff context
40+
-line 1
41+
+LINE 1
42+
line 2
43+
line 3
44+
line 4
45+
@@ -1,9 +1,4 @@
46+
-line 5
47+
-if
48+
-1
49+
-fi
50+
-if
51+
-2
52+
-fi
53+
-A
54+
-B
55+
+line 1
56+
+line 2
57+
+line 3
58+
+line 4
59+
@@ -5,9 +5,6 @@ INTERDIFF: rejected hunk from patch2, cannot diff context
60+
line 5
61+
if
62+
1
63+
-fi
64+
-if
65+
-2
66+
fi
67+
A
68+
B
69+
EOF
70+
71+
${INTERDIFF} --fuzzy patch1 patch2 2>errors >output
72+
[ -s errors ] && exit 1
73+
74+
cmp output expected || exit 1

tests/fuzzy2/run-test

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/sh
2+
3+
# This is an interdiff(1) testcase.
4+
# Test: Fuzzy diffing with line offsets successfully fuzzed.
5+
6+
7+
. ${top_srcdir-.}/tests/common.sh
8+
9+
cat << 'EOF' > patch1
10+
--- file
11+
+++ file
12+
@@ -5,9 +5,6 @@
13+
line 5
14+
if
15+
1
16+
-fi
17+
-if
18+
-2
19+
fi
20+
A
21+
B
22+
EOF
23+
24+
cat << 'EOF' > patch2
25+
--- file
26+
+++ file
27+
@@ -50,9 +50,6 @@
28+
line 5
29+
if
30+
1
31+
-fi
32+
-if
33+
-2
34+
fi
35+
A
36+
B
37+
EOF
38+
39+
${INTERDIFF} --fuzzy patch1 patch2 2>errors >output
40+
[ -s errors ] && exit 1
41+
[ -s output ] && exit 1
42+
exit 0

tests/fuzzy3/run-test

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/sh
2+
3+
# This is an interdiff(1) testcase.
4+
# Test: Fuzzy diffing with differing context lines and line offsets fuzzed.
5+
6+
7+
. ${top_srcdir-.}/tests/common.sh
8+
9+
cat << 'EOF' > patch1
10+
--- file
11+
+++ file
12+
@@ -5,9 +5,6 @@
13+
line 5
14+
if
15+
1
16+
-fi
17+
-if
18+
-2
19+
fi
20+
A
21+
B
22+
EOF
23+
24+
cat << 'EOF' > patch2
25+
--- file
26+
+++ file
27+
@@ -50,9 +50,6 @@
28+
line 6
29+
if
30+
1
31+
-fi
32+
-if
33+
-2
34+
fi
35+
B
36+
C
37+
EOF
38+
39+
cat << 'EOF' > expected
40+
diff -u file file
41+
--- file
42+
+++ file
43+
@@ -2,6 +2,6 @@
44+
-line 6
45+
+line 5
46+
if
47+
1
48+
fi
49+
+A
50+
B
51+
-C
52+
EOF
53+
54+
${INTERDIFF} --fuzzy patch1 patch2 2>errors >output
55+
[ -s errors ] && exit 1
56+
57+
cmp output expected || exit 1

tests/fuzzy4/run-test

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/sh
2+
3+
# This is an interdiff(1) testcase.
4+
# Test: Fuzzy diffing test of the optional N argument to --fuzzy. Triggers
5+
# rejects by setting the fuzz value to 1, when it could've been fuzzed with the
6+
# default fuzz value of 2 in `patch`.
7+
8+
9+
. ${top_srcdir-.}/tests/common.sh
10+
11+
cat << 'EOF' > patch1
12+
--- file
13+
+++ file
14+
@@ -5,9 +5,6 @@
15+
line 5
16+
if
17+
1
18+
-fi
19+
-if
20+
-2
21+
fi
22+
A
23+
B
24+
EOF
25+
26+
cat << 'EOF' > patch2
27+
--- file
28+
+++ file
29+
@@ -50,9 +50,6 @@
30+
line 6
31+
if
32+
1
33+
-fi
34+
-if
35+
-2
36+
fi
37+
B
38+
C
39+
EOF
40+
41+
cat << 'EOF' > expected
42+
diff -u file file
43+
--- file
44+
+++ file
45+
@@ -2,9 +2,9 @@
46+
-line 6
47+
+line 5
48+
if
49+
1
50+
fi
51+
if
52+
2
53+
fi
54+
+A
55+
B
56+
-C
57+
@@ -5,9 +5,6 @@ INTERDIFF: rejected hunk from patch1, cannot diff context
58+
line 5
59+
if
60+
1
61+
-fi
62+
-if
63+
-2
64+
fi
65+
A
66+
B
67+
@@ -50,9 +50,6 @@ INTERDIFF: rejected hunk from patch2, cannot diff context
68+
line 6
69+
if
70+
1
71+
-fi
72+
-if
73+
-2
74+
fi
75+
B
76+
C
77+
EOF
78+
79+
${INTERDIFF} --fuzzy=1 patch1 patch2 2>errors >output
80+
[ -s errors ] && exit 1
81+
82+
cmp output expected || exit 1

tests/fuzzy5/run-test

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/bin/sh
2+
3+
# This is an interdiff(1) testcase.
4+
# Test: Fuzzy diffing with more than one rejected hunk per patched file. This
5+
# also tests the hunk parser by inserting whitespace between the +++ line and
6+
# the first hunk, which should be gracefully ignored.
7+
8+
9+
. ${top_srcdir-.}/tests/common.sh
10+
11+
cat << 'EOF' > patch1
12+
--- file
13+
+++ file
14+
15+
16+
17+
@@ -5,9 +5,6 @@
18+
line 5
19+
if
20+
1
21+
-fi
22+
-if
23+
-2
24+
fi
25+
A
26+
B
27+
@@ -7,7 +7,7 @@
28+
C
29+
9
30+
8
31+
-1
32+
+7
33+
D
34+
E
35+
if
36+
EOF
37+
38+
cat << 'EOF' > patch2
39+
--- file
40+
+++ file
41+
42+
@@ -50,9 +50,6 @@
43+
line 6
44+
if
45+
1
46+
-fi
47+
-if
48+
-2
49+
fi
50+
B
51+
C
52+
@@ -7,7 +7,7 @@
53+
D
54+
Z
55+
1
56+
-1
57+
+7
58+
F
59+
E
60+
if
61+
EOF
62+
63+
cat << 'EOF' > expected
64+
diff -u file file
65+
--- file
66+
+++ file
67+
@@ -2,9 +2,2 @@
68+
-line 6
69+
+line 5
70+
if
71+
1
72+
fi
73+
if
74+
2
75+
fi
76+
+A
77+
B
78+
-C
79+
@@ -5,9 +5,6 @@ INTERDIFF: rejected hunk from patch1, cannot diff context
80+
line 5
81+
if
82+
1
83+
-fi
84+
-if
85+
-2
86+
fi
87+
A
88+
B
89+
@@ -7,7 +7,7 @@ INTERDIFF: rejected hunk from patch1, cannot diff context
90+
C
91+
9
92+
8
93+
-1
94+
+7
95+
D
96+
E
97+
if
98+
@@ -50,9 +50,6 @@ INTERDIFF: rejected hunk from patch2, cannot diff context
99+
line 6
100+
if
101+
1
102+
-fi
103+
-if
104+
-2
105+
fi
106+
B
107+
C
108+
@@ -7,7 +7,7 @@ INTERDIFF: rejected hunk from patch2, cannot diff context
109+
D
110+
Z
111+
1
112+
-1
113+
+7
114+
F
115+
E
116+
if
117+
EOF
118+
119+
${INTERDIFF} --fuzzy=1 patch1 patch2 2>errors >output
120+
[ -s errors ] && exit 1
121+
122+
cmp output expected || exit 1

0 commit comments

Comments
 (0)