rpatch 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +22 -0
- data/README.md +90 -0
- data/bin/rpatch +27 -0
- data/lib/rpatch/entry.rb +137 -0
- data/lib/rpatch/error.rb +8 -0
- data/lib/rpatch/hunk.rb +271 -0
- data/lib/rpatch/patch.rb +158 -0
- data/lib/rpatch/runner.rb +44 -0
- data/lib/rpatch/version.rb +3 -0
- data/spec/patch_entry_spec.rb +234 -0
- data/spec/patch_file_regexp_spec.rb +73 -0
- data/spec/patch_file_spec.rb +267 -0
- data/spec/patch_hunk_spec.rb +272 -0
- data/spec/spec_helper.rb +24 -0
- data/t/Makefile +80 -0
- data/t/README +3 -0
- data/t/aggregate-results.sh +46 -0
- data/t/t0000-patch-file.sh +297 -0
- data/t/t0100-patch-directory.sh +203 -0
- data/t/test-lib-functions.sh +722 -0
- data/t/test-lib.sh +623 -0
- metadata +132 -0
@@ -0,0 +1,203 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
#
|
3
|
+
# Copyright (c) 2013 Jiang Xin
|
4
|
+
#
|
5
|
+
|
6
|
+
test_description='patch file test'
|
7
|
+
|
8
|
+
. ./test-lib.sh
|
9
|
+
|
10
|
+
############################################################
|
11
|
+
|
12
|
+
cat > diff <<EOF
|
13
|
+
diff -u a/foo b/foo
|
14
|
+
--- a/foo 2013-11-04 16:01:56.000000000 +0800
|
15
|
+
+++ b/foo 2013-11-04 16:01:59.000000000 +0800
|
16
|
+
@@ add two lines
|
17
|
+
+baz
|
18
|
+
+foo
|
19
|
+
diff -u a/bar b/bar
|
20
|
+
--- a/bar 2013-11-04 16:01:56.000000000 +0800
|
21
|
+
+++ b/bar 2013-11-04 16:01:59.000000000 +0800
|
22
|
+
@@ add two lines
|
23
|
+
+baz
|
24
|
+
+bar
|
25
|
+
EOF
|
26
|
+
|
27
|
+
cat > expect <<EOF
|
28
|
+
EOF
|
29
|
+
|
30
|
+
cat > expect_errlog <<EOF
|
31
|
+
Error: Multiple patch entries (2) have been found in patch <IO>
|
32
|
+
Error: Multiple patch entries (2) have been found in patch <IO>
|
33
|
+
EOF
|
34
|
+
|
35
|
+
test_expect_success 'cannot patch single file with multi patch entries' '
|
36
|
+
touch ! -f actual &&
|
37
|
+
touch actual &&
|
38
|
+
test_must_fail rpatch actual < diff 2>actual_errlog &&
|
39
|
+
test_cmp expect actual &&
|
40
|
+
test_cmp expect_errlog actual_errlog
|
41
|
+
'
|
42
|
+
|
43
|
+
############################################################
|
44
|
+
|
45
|
+
cat > expect_errlog <<EOF
|
46
|
+
Patched "output/foo".
|
47
|
+
Patched "output/bar".
|
48
|
+
EOF
|
49
|
+
|
50
|
+
cat > expect_foo <<EOF
|
51
|
+
baz
|
52
|
+
foo
|
53
|
+
EOF
|
54
|
+
|
55
|
+
cat > expect_bar <<EOF
|
56
|
+
baz
|
57
|
+
bar
|
58
|
+
EOF
|
59
|
+
|
60
|
+
test_expect_success 'Patch on directory: create new file automatically' '
|
61
|
+
mkdir output &&
|
62
|
+
rpatch output < diff 2>actual_errlog &&
|
63
|
+
test -f output/foo &&
|
64
|
+
test -f output/bar &&
|
65
|
+
test_cmp expect_foo output/foo &&
|
66
|
+
test_cmp expect_bar output/bar &&
|
67
|
+
test_cmp expect_errlog actual_errlog
|
68
|
+
'
|
69
|
+
|
70
|
+
############################################################
|
71
|
+
|
72
|
+
cat > diff <<EOF
|
73
|
+
diff -u a/foo b/foo
|
74
|
+
--- a/foo 2013-11-04 16:01:56.000000000 +0800
|
75
|
+
+++ b/foo 2013-11-04 16:01:59.000000000 +0800
|
76
|
+
@@ heading
|
77
|
+
+heading of foo...
|
78
|
+
-baz
|
79
|
+
@@ tail
|
80
|
+
foo
|
81
|
+
+tail of foo ...
|
82
|
+
diff -u a/bar b/bar
|
83
|
+
--- a/bar 2013-11-04 16:01:56.000000000 +0800
|
84
|
+
+++ b/bar 2013-11-04 16:01:59.000000000 +0800
|
85
|
+
@@ heading
|
86
|
+
+heading of bar...
|
87
|
+
-baz
|
88
|
+
@@ tail
|
89
|
+
bar
|
90
|
+
+tail of bar ...
|
91
|
+
EOF
|
92
|
+
|
93
|
+
cat > expect_errlog <<EOF
|
94
|
+
Patched "output/foo".
|
95
|
+
Patched "output/bar".
|
96
|
+
EOF
|
97
|
+
|
98
|
+
cat > expect_foo <<EOF
|
99
|
+
heading of foo...
|
100
|
+
foo
|
101
|
+
tail of foo ...
|
102
|
+
EOF
|
103
|
+
|
104
|
+
cat > expect_bar <<EOF
|
105
|
+
heading of bar...
|
106
|
+
bar
|
107
|
+
tail of bar ...
|
108
|
+
EOF
|
109
|
+
|
110
|
+
test_expect_success 'Patch on directory (2): patch exist files' '
|
111
|
+
rpatch output < diff 2>actual_errlog &&
|
112
|
+
test -f output/foo &&
|
113
|
+
test -f output/bar &&
|
114
|
+
test_cmp expect_foo output/foo &&
|
115
|
+
test_cmp expect_bar output/bar &&
|
116
|
+
test_cmp expect_errlog actual_errlog
|
117
|
+
'
|
118
|
+
|
119
|
+
############################################################
|
120
|
+
|
121
|
+
cat > diff <<EOF
|
122
|
+
diff -u a/foo b/foo
|
123
|
+
--- a/foo 2013-11-04 16:01:56.000000000 +0800
|
124
|
+
+++ b/foo 2013-11-04 16:01:59.000000000 +0800
|
125
|
+
@@ can not match
|
126
|
+
heading of foo...
|
127
|
+
foobar
|
128
|
+
-tail of foo ...
|
129
|
+
diff -u a/bar b/bar
|
130
|
+
--- a/bar 2013-11-04 16:01:56.000000000 +0800
|
131
|
+
+++ b/bar 2013-11-04 16:01:59.000000000 +0800
|
132
|
+
@@ remove tail
|
133
|
+
heading of bar...
|
134
|
+
bar
|
135
|
+
-tail of bar ...
|
136
|
+
EOF
|
137
|
+
|
138
|
+
cat > expect_errlog <<EOF
|
139
|
+
ERROR: output/foo: Hunk 1 (can not match) FAILED to apply. Match failed.
|
140
|
+
output/foo: nothing changed
|
141
|
+
Patched "output/bar".
|
142
|
+
EOF
|
143
|
+
|
144
|
+
cat > expect_foo <<EOF
|
145
|
+
heading of foo...
|
146
|
+
foo
|
147
|
+
tail of foo ...
|
148
|
+
EOF
|
149
|
+
|
150
|
+
cat > expect_bar <<EOF
|
151
|
+
heading of bar...
|
152
|
+
bar
|
153
|
+
EOF
|
154
|
+
|
155
|
+
test_expect_success 'Patch on directory (3): one fail, another success' '
|
156
|
+
test_must_fail rpatch output < diff 2>actual_errlog &&
|
157
|
+
test -f output/foo &&
|
158
|
+
test -f output/bar &&
|
159
|
+
test_cmp expect_foo output/foo &&
|
160
|
+
test_cmp expect_bar output/bar &&
|
161
|
+
test_cmp expect_errlog actual_errlog
|
162
|
+
'
|
163
|
+
|
164
|
+
############################################################
|
165
|
+
|
166
|
+
cat > diff <<EOF
|
167
|
+
diff -u a/foo b/foo
|
168
|
+
--- a/foo 2013-11-04 16:01:56.000000000 +0800
|
169
|
+
+++ b/foo 2013-11-04 16:01:59.000000000 +0800
|
170
|
+
@@ can not match
|
171
|
+
RE:-heading
|
172
|
+
RE:-foo
|
173
|
+
RE:-tail.*
|
174
|
+
diff -u a/bar b/bar
|
175
|
+
--- a/bar 2013-11-04 16:01:56.000000000 +0800
|
176
|
+
+++ b/bar 2013-11-04 16:01:59.000000000 +0800
|
177
|
+
@@ add tail
|
178
|
+
RE: ^[bB][aA][rR]$
|
179
|
+
+tail of bar...
|
180
|
+
EOF
|
181
|
+
|
182
|
+
cat > expect_errlog <<EOF
|
183
|
+
Remove "output/foo".
|
184
|
+
Patched "output/bar".
|
185
|
+
EOF
|
186
|
+
|
187
|
+
cat > expect_bar <<EOF
|
188
|
+
heading of bar...
|
189
|
+
bar
|
190
|
+
tail of bar...
|
191
|
+
EOF
|
192
|
+
|
193
|
+
test_expect_success 'Patch on directory (4): remove file' '
|
194
|
+
rpatch -p1 output < diff 2>actual_errlog &&
|
195
|
+
test ! -f output/foo &&
|
196
|
+
test -f output/bar &&
|
197
|
+
test_cmp expect_bar output/bar &&
|
198
|
+
test_cmp expect_errlog actual_errlog
|
199
|
+
'
|
200
|
+
|
201
|
+
############################################################
|
202
|
+
|
203
|
+
test_done
|