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 <gitster@pobox.com>
Junio C Hamano committed
Jul 20, 2008 at 01:33 UTC
ac2e28c0a43ced3837fbbcf66fd693244b6c6693
11 files changed
+190
-123
t/t4109-apply-multifrag.sh
+19
-36
@@ -4,49 +4,32 @@
4
# Copyright (c) 2005 Robert Fitzsimons
5
#
6
7
-test_description='git apply test patches with multiple fragments.
7
+test_description='git apply test patches with multiple fragments.'
8
9
-'
9
. ./test-lib.sh
10
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" .
15
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
21
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
27
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
+'
32
mv main.c main.c.git
33
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
-
34
test_done
35
t/t4109/expect-1
new
+31
@@ -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
new
+23
@@ -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
new
+24
@@ -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
+9
-87
@@ -9,92 +9,14 @@ test_description='git apply test for patches which require scanning forwards and
9
'
10
. ./test-lib.sh
11
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
+'
21
22
test_done
t/t4110/expect
new
+20
@@ -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
new
+17
@@ -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
new
+11
@@ -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
new
+14
@@ -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
new
+11
@@ -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
t/t4110/patch5.patch
new
+11
@@ -0,0 +1,11 @@
1
+diff --git a/new.txt b/new.txt
2
+--- a/new.txt
3
++++ b/new.txt
4
+@@ -10,3 +10,7 @@
5
+ c11
6
+ c111
7
+ c1111
8
++c2
9
++c22
10
++c222
11
++c2222