Skip to content

Commit 4c71ec8

Browse files
trastdscho
authored andcommitted
range-diff: add tests
These are essentially lifted from https://github.com/trast/tbdiff, with light touch-ups to account for the command now being an option of `git branch`. Apart from renaming `tbdiff` to `range-diff`, only one test case needed to be adjusted: 11 - 'changed message'. The underlying reason it had to be adjusted is that diff generation is sometimes ambiguous. In this case, a comment line and an empty line are added, but it is ambiguous whether they were added after the existing empty line, or whether an empty line and the comment line are added *before* the existing empty line. And apparently xdiff picks a different option here than Python's difflib. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent a02bdb8 commit 4c71ec8

File tree

3 files changed

+750
-0
lines changed

3 files changed

+750
-0
lines changed

t/.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ t[0-9][0-9][0-9][0-9]/* -whitespace
1919
/t5515/* eol=lf
2020
/t556x_common eol=lf
2121
/t7500/* eol=lf
22+
/t7910/* eol=lf
2223
/t8005/*.txt eol=lf
2324
/t9*/*.dump eol=lf

t/t3206-range-diff.sh

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
#!/bin/sh
2+
3+
test_description='range-diff tests'
4+
5+
. ./test-lib.sh
6+
7+
# Note that because of the range-diff's heuristics, test_commit does more
8+
# harm than good. We need some real history.
9+
10+
test_expect_success 'setup' '
11+
git fast-import < "$TEST_DIRECTORY"/t3206/history.export
12+
'
13+
14+
test_expect_success 'simple A..B A..C (unmodified)' '
15+
git range-diff --no-color master..topic master..unmodified \
16+
>actual &&
17+
cat >expected <<-EOF &&
18+
1: 4de457d = 1: 35b9b25 s/5/A/
19+
2: fccce22 = 2: de345ab s/4/A/
20+
3: 147e64e = 3: 9af6654 s/11/B/
21+
4: a63e992 = 4: 2901f77 s/12/B/
22+
EOF
23+
test_cmp expected actual
24+
'
25+
26+
test_expect_success 'simple B...C (unmodified)' '
27+
git range-diff --no-color topic...unmodified >actual &&
28+
# same "expected" as above
29+
test_cmp expected actual
30+
'
31+
32+
test_expect_success 'simple A B C (unmodified)' '
33+
git range-diff --no-color master topic unmodified >actual &&
34+
# same "expected" as above
35+
test_cmp expected actual
36+
'
37+
38+
test_expect_success 'trivial reordering' '
39+
git range-diff --no-color master topic reordered >actual &&
40+
cat >expected <<-EOF &&
41+
1: 4de457d = 1: aca177a s/5/A/
42+
3: 147e64e = 2: 14ad629 s/11/B/
43+
4: a63e992 = 3: ee58208 s/12/B/
44+
2: fccce22 = 4: 307b27a s/4/A/
45+
EOF
46+
test_cmp expected actual
47+
'
48+
49+
test_expect_success 'removed a commit' '
50+
git range-diff --no-color master topic removed >actual &&
51+
cat >expected <<-EOF &&
52+
1: 4de457d = 1: 7657159 s/5/A/
53+
2: fccce22 < -: ------- s/4/A/
54+
3: 147e64e = 2: 43d84d3 s/11/B/
55+
4: a63e992 = 3: a740396 s/12/B/
56+
EOF
57+
test_cmp expected actual
58+
'
59+
60+
test_expect_success 'added a commit' '
61+
git range-diff --no-color master topic added >actual &&
62+
cat >expected <<-EOF &&
63+
1: 4de457d = 1: 2716022 s/5/A/
64+
2: fccce22 = 2: b62accd s/4/A/
65+
-: ------- > 3: df46cfa s/6/A/
66+
3: 147e64e = 4: 3e64548 s/11/B/
67+
4: a63e992 = 5: 12b4063 s/12/B/
68+
EOF
69+
test_cmp expected actual
70+
'
71+
72+
test_expect_success 'new base, A B C' '
73+
git range-diff --no-color master topic rebased >actual &&
74+
cat >expected <<-EOF &&
75+
1: 4de457d = 1: cc9c443 s/5/A/
76+
2: fccce22 = 2: c5d9641 s/4/A/
77+
3: 147e64e = 3: 28cc2b6 s/11/B/
78+
4: a63e992 = 4: 5628ab7 s/12/B/
79+
EOF
80+
test_cmp expected actual
81+
'
82+
83+
test_expect_success 'new base, B...C' '
84+
# this syntax includes the commits from master!
85+
git range-diff --no-color topic...rebased >actual &&
86+
cat >expected <<-EOF &&
87+
-: ------- > 1: a31b12e unrelated
88+
1: 4de457d = 2: cc9c443 s/5/A/
89+
2: fccce22 = 3: c5d9641 s/4/A/
90+
3: 147e64e = 4: 28cc2b6 s/11/B/
91+
4: a63e992 = 5: 5628ab7 s/12/B/
92+
EOF
93+
test_cmp expected actual
94+
'
95+
96+
test_expect_success 'changed commit' '
97+
git range-diff --no-color topic...changed >actual &&
98+
cat >expected <<-EOF &&
99+
1: 4de457d = 1: a4b3333 s/5/A/
100+
2: fccce22 = 2: f51d370 s/4/A/
101+
3: 147e64e ! 3: 0559556 s/11/B/
102+
@@ -10,7 +10,7 @@
103+
9
104+
10
105+
-11
106+
-+B
107+
++BB
108+
12
109+
13
110+
14
111+
4: a63e992 ! 4: d966c5c s/12/B/
112+
@@ -8,7 +8,7 @@
113+
@@
114+
9
115+
10
116+
- B
117+
+ BB
118+
-12
119+
+B
120+
13
121+
EOF
122+
test_cmp expected actual
123+
'
124+
125+
test_expect_success 'changed message' '
126+
git range-diff --no-color topic...changed-message >actual &&
127+
sed s/Z/\ /g >expected <<-EOF &&
128+
1: 4de457d = 1: f686024 s/5/A/
129+
2: fccce22 ! 2: 4ab067d s/4/A/
130+
@@ -2,6 +2,8 @@
131+
Z
132+
Z s/4/A/
133+
Z
134+
+ Also a silly comment here!
135+
+
136+
Zdiff --git a/file b/file
137+
Z--- a/file
138+
Z+++ b/file
139+
3: 147e64e = 3: b9cb956 s/11/B/
140+
4: a63e992 = 4: 8add5f1 s/12/B/
141+
EOF
142+
test_cmp expected actual
143+
'
144+
145+
test_done

0 commit comments

Comments
 (0)