Skip to content

Commit 5401c9f

Browse files
committed
Add three basic tests for interdiff fuzzy diffing
1 parent f5dc380 commit 5401c9f

File tree

4 files changed

+174
-1
lines changed

4 files changed

+174
-1
lines changed

Makefile.am

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

437440
# Scanner tests (only when scanner-patchfilter is enabled)
438441
if USE_SCANNER_PATCHFILTER

tests/fuzzy1/run-test

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/sh
2+
3+
# This is an interdiff(1) testcase.
4+
# Test: Fuzzy diffing with rejected hunks.
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 +1 @@ INTERDIFF: rejected hunk from patch1, cannot diff context
40+
-line 1
41+
+LINE 1
42+
@@ -1,9 +1,4 @@
43+
-line 5
44+
-if
45+
-1
46+
-fi
47+
-if
48+
-2
49+
-fi
50+
-A
51+
-B
52+
+line 1
53+
+line 2
54+
+line 3
55+
+line 4
56+
@@ -5,9 +5,6 @@ INTERDIFF: rejected hunk from patch2, cannot diff context
57+
line 5
58+
if
59+
1
60+
-fi
61+
-if
62+
-2
63+
fi
64+
A
65+
B
66+
EOF
67+
68+
${INTERDIFF} --fuzzy patch1 patch2 2>errors >output
69+
[ -s errors ] && exit 1
70+
71+
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

0 commit comments

Comments
 (0)