Skip to content

Commit 01efe36

Browse files
committed
Add tests for interdiff fuzzy diffing
1 parent 33674eb commit 01efe36

8 files changed

Lines changed: 1405 additions & 1 deletion

File tree

Makefile.am

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,14 @@ 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
436443

437444
# Scanner tests (only when scanner-patchfilter is enabled)
438445
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

0 commit comments

Comments
 (0)