Skip to content

Commit ac2e28c

Browse files
committed
tests: do not rely on external "patch"
Some of our tests assumed a working "patch" command to produce expected results when checking "git-apply", but some systems have broken "patch". We can compare our output with expected output that is precomputed instead to sidestep this issue. Signed-off-by: Junio C Hamano <[email protected]>
1 parent c79cc2e commit ac2e28c

File tree

11 files changed

+190
-123
lines changed

11 files changed

+190
-123
lines changed

t/t4109-apply-multifrag.sh

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,32 @@
44
# Copyright (c) 2005 Robert Fitzsimons
55
#
66

7-
test_description='git apply test patches with multiple fragments.
7+
test_description='git apply test patches with multiple fragments.'
88

9-
'
109
. ./test-lib.sh
1110

12-
cp ../t4109/patch1.patch .
13-
cp ../t4109/patch2.patch .
14-
cp ../t4109/patch3.patch .
15-
cp ../t4109/patch4.patch .
16-
17-
test_expect_success "S = git apply (1)" \
18-
'git apply patch1.patch patch2.patch'
19-
mv main.c main.c.git
20-
21-
test_expect_success "S = patch (1)" \
22-
'cat patch1.patch patch2.patch | patch -p1'
23-
24-
test_expect_success "S = cmp (1)" \
25-
'cmp main.c.git main.c'
26-
27-
rm -f main.c main.c.git
28-
29-
test_expect_success "S = git apply (2)" \
30-
'git apply patch1.patch patch2.patch patch3.patch'
31-
mv main.c main.c.git
32-
33-
test_expect_success "S = patch (2)" \
34-
'cat patch1.patch patch2.patch patch3.patch | patch -p1'
11+
cp "$TEST_DIRECTORY/t4109/patch1.patch" .
12+
cp "$TEST_DIRECTORY/t4109/patch2.patch" .
13+
cp "$TEST_DIRECTORY/t4109/patch3.patch" .
14+
cp "$TEST_DIRECTORY/t4109/patch4.patch" .
3515

36-
test_expect_success "S = cmp (2)" \
37-
'cmp main.c.git main.c'
16+
test_expect_success 'git apply (1)' '
17+
git apply patch1.patch patch2.patch &&
18+
test_cmp "$TEST_DIRECTORY/t4109/expect-1" main.c
19+
'
20+
rm -f main.c
3821

39-
rm -f main.c main.c.git
22+
test_expect_success 'git apply (2)' '
23+
git apply patch1.patch patch2.patch patch3.patch &&
24+
test_cmp "$TEST_DIRECTORY/t4109/expect-2" main.c
25+
'
26+
rm -f main.c
4027

41-
test_expect_success "S = git apply (3)" \
42-
'git apply patch1.patch patch4.patch'
28+
test_expect_success 'git apply (3)' '
29+
git apply patch1.patch patch4.patch &&
30+
test_cmp "$TEST_DIRECTORY/t4109/expect-3" main.c
31+
'
4332
mv main.c main.c.git
4433

45-
test_expect_success "S = patch (3)" \
46-
'cat patch1.patch patch4.patch | patch -p1'
47-
48-
test_expect_success "S = cmp (3)" \
49-
'cmp main.c.git main.c'
50-
5134
test_done
5235

t/t4109/expect-1

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <stdlib.h>
2+
#include <stdio.h>
3+
4+
int func(int num);
5+
void print_int(int num);
6+
void print_ln();
7+
8+
int main() {
9+
int i;
10+
11+
for (i = 0; i < 10; i++) {
12+
print_int(func(i));
13+
}
14+
15+
print_ln();
16+
17+
return 0;
18+
}
19+
20+
int func(int num) {
21+
return num * num;
22+
}
23+
24+
void print_int(int num) {
25+
printf("%d", num);
26+
}
27+
28+
void print_ln() {
29+
printf("\n");
30+
}
31+

t/t4109/expect-2

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <stdio.h>
2+
3+
int func(int num);
4+
void print_int(int num);
5+
6+
int main() {
7+
int i;
8+
9+
for (i = 0; i < 10; i++) {
10+
print_int(func(i));
11+
}
12+
13+
return 0;
14+
}
15+
16+
int func(int num) {
17+
return num * num;
18+
}
19+
20+
void print_int(int num) {
21+
printf("%d", num);
22+
}
23+

t/t4109/expect-3

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <stdio.h>
2+
3+
int func(int num);
4+
int func2(int num);
5+
6+
int main() {
7+
int i;
8+
9+
for (i = 0; i < 10; i++) {
10+
printf("%d", func(i));
11+
printf("%d", func3(i));
12+
}
13+
14+
return 0;
15+
}
16+
17+
int func(int num) {
18+
return num * num;
19+
}
20+
21+
int func2(int num) {
22+
return num * num * num;
23+
}
24+

t/t4110-apply-scan.sh

Lines changed: 9 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -9,92 +9,14 @@ test_description='git apply test for patches which require scanning forwards and
99
'
1010
. ./test-lib.sh
1111

12-
# setup
13-
14-
cat > patch1.patch <<\EOF
15-
diff --git a/new.txt b/new.txt
16-
new file mode 100644
17-
--- /dev/null
18-
+++ b/new.txt
19-
@@ -0,0 +1,12 @@
20-
+a1
21-
+a11
22-
+a111
23-
+a1111
24-
+b1
25-
+b11
26-
+b111
27-
+b1111
28-
+c1
29-
+c11
30-
+c111
31-
+c1111
32-
EOF
33-
cat > patch2.patch <<\EOF
34-
diff --git a/new.txt b/new.txt
35-
--- a/new.txt
36-
+++ b/new.txt
37-
@@ -1,7 +1,3 @@
38-
-a1
39-
-a11
40-
-a111
41-
-a1111
42-
b1
43-
b11
44-
b111
45-
EOF
46-
cat > patch3.patch <<\EOF
47-
diff --git a/new.txt b/new.txt
48-
--- a/new.txt
49-
+++ b/new.txt
50-
@@ -6,6 +6,10 @@
51-
b11
52-
b111
53-
b1111
54-
+b2
55-
+b22
56-
+b222
57-
+b2222
58-
c1
59-
c11
60-
c111
61-
EOF
62-
cat > patch4.patch <<\EOF
63-
diff --git a/new.txt b/new.txt
64-
--- a/new.txt
65-
+++ b/new.txt
66-
@@ -1,3 +1,7 @@
67-
+a1
68-
+a11
69-
+a111
70-
+a1111
71-
b1
72-
b11
73-
b111
74-
EOF
75-
cat > patch5.patch <<\EOF
76-
diff --git a/new.txt b/new.txt
77-
--- a/new.txt
78-
+++ b/new.txt
79-
@@ -10,3 +10,7 @@
80-
c11
81-
c111
82-
c1111
83-
+c2
84-
+c22
85-
+c222
86-
+c2222
87-
EOF
88-
89-
test_expect_success "S = git apply scan" \
90-
'git apply patch1.patch patch2.patch patch3.patch patch4.patch patch5.patch'
91-
mv new.txt apply.txt
92-
93-
test_expect_success "S = patch scan" \
94-
'cat patch1.patch patch2.patch patch3.patch patch4.patch patch5.patch | patch'
95-
mv new.txt patch.txt
96-
97-
test_expect_success "S = cmp" \
98-
'cmp apply.txt patch.txt'
12+
test_expect_success 'git apply scan' '
13+
git apply \
14+
"$TEST_DIRECTORY/t4110/patch1.patch" \
15+
"$TEST_DIRECTORY/t4110/patch2.patch" \
16+
"$TEST_DIRECTORY/t4110/patch3.patch" \
17+
"$TEST_DIRECTORY/t4110/patch4.patch" \
18+
"$TEST_DIRECTORY/t4110/patch5.patch" &&
19+
test_cmp new.txt "$TEST_DIRECTORY/t4110/expect"
20+
'
9921

10022
test_done

t/t4110/expect

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
a1
2+
a11
3+
a111
4+
a1111
5+
b1
6+
b11
7+
b111
8+
b1111
9+
b2
10+
b22
11+
b222
12+
b2222
13+
c1
14+
c11
15+
c111
16+
c1111
17+
c2
18+
c22
19+
c222
20+
c2222

t/t4110/patch1.patch

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
diff --git a/new.txt b/new.txt
2+
new file mode 100644
3+
--- /dev/null
4+
+++ b/new.txt
5+
@@ -0,0 +1,12 @@
6+
+a1
7+
+a11
8+
+a111
9+
+a1111
10+
+b1
11+
+b11
12+
+b111
13+
+b1111
14+
+c1
15+
+c11
16+
+c111
17+
+c1111

t/t4110/patch2.patch

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
diff --git a/new.txt b/new.txt
2+
--- a/new.txt
3+
+++ b/new.txt
4+
@@ -1,7 +1,3 @@
5+
-a1
6+
-a11
7+
-a111
8+
-a1111
9+
b1
10+
b11
11+
b111

t/t4110/patch3.patch

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
diff --git a/new.txt b/new.txt
2+
--- a/new.txt
3+
+++ b/new.txt
4+
@@ -6,6 +6,10 @@
5+
b11
6+
b111
7+
b1111
8+
+b2
9+
+b22
10+
+b222
11+
+b2222
12+
c1
13+
c11
14+
c111

t/t4110/patch4.patch

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
diff --git a/new.txt b/new.txt
2+
--- a/new.txt
3+
+++ b/new.txt
4+
@@ -1,3 +1,7 @@
5+
+a1
6+
+a11
7+
+a111
8+
+a1111
9+
b1
10+
b11
11+
b111

0 commit comments

Comments
 (0)