rpatch 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +16 -7
- data/lib/rpatch/entry.rb +18 -12
- data/lib/rpatch/hunk.rb +181 -119
- data/lib/rpatch/patch.rb +29 -20
- data/lib/rpatch/runner.rb +5 -2
- data/lib/rpatch/utils.rb +121 -0
- data/lib/rpatch/version.rb +1 -1
- data/spec/patch_file_regexp_spec.rb +6 -8
- data/spec/patch_file_spec.rb +10 -3
- data/spec/patch_hunk_with_location_spec.rb +149 -0
- data/spec/patch_hunk_with_qmark_exp_spec.rb +152 -0
- data/spec/patch_hunk_with_regex_spec.rb +72 -0
- data/t/t0000-patch-file.sh +27 -28
- data/t/t0010-patch-special-direction.sh +336 -0
- data/t/t0100-patch-directory.sh +89 -42
- metadata +59 -73
@@ -0,0 +1,152 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
|
6
|
+
describe Rpatch::PatchHunk do
|
7
|
+
|
8
|
+
it "Question mark expression in pattern" do
|
9
|
+
before = <<-EOF
|
10
|
+
original text
|
11
|
+
end of text
|
12
|
+
EOF
|
13
|
+
|
14
|
+
diff = <<-EOF
|
15
|
+
? original text
|
16
|
+
+ foobar
|
17
|
+
EOF
|
18
|
+
|
19
|
+
after = <<-EOF
|
20
|
+
original text
|
21
|
+
foobar
|
22
|
+
end of text
|
23
|
+
EOF
|
24
|
+
|
25
|
+
hunk = Rpatch::PatchHunk.new('@@ description')
|
26
|
+
diff.split($/).each {|line| hunk.feed_line line.chomp}
|
27
|
+
|
28
|
+
hunk.match_after_patch(before.split($/)).should eq nil
|
29
|
+
hunk.match_before_patch(before.split($/)).should eq [0, 1]
|
30
|
+
result = hunk.patch(before.split($/))
|
31
|
+
(result * "\n" + "\n").should eq after
|
32
|
+
end
|
33
|
+
|
34
|
+
it "Question mark expression in pattern (2)" do
|
35
|
+
before = <<-EOF
|
36
|
+
original text
|
37
|
+
end of text
|
38
|
+
EOF
|
39
|
+
|
40
|
+
diff = <<-EOF
|
41
|
+
? original text
|
42
|
+
?+ # comment for foobar
|
43
|
+
+ foobar
|
44
|
+
EOF
|
45
|
+
|
46
|
+
after = <<-EOF
|
47
|
+
original text
|
48
|
+
# comment for foobar
|
49
|
+
foobar
|
50
|
+
end of text
|
51
|
+
EOF
|
52
|
+
|
53
|
+
hunk = Rpatch::PatchHunk.new('@@ description')
|
54
|
+
diff.split($/).each {|line| hunk.feed_line line.chomp}
|
55
|
+
|
56
|
+
hunk.match_after_patch(before.split($/)).should eq nil
|
57
|
+
hunk.match_before_patch(before.split($/)).should eq [0, 1]
|
58
|
+
result = hunk.patch(before.split($/))
|
59
|
+
(result * "\n" + "\n").should eq after
|
60
|
+
end
|
61
|
+
|
62
|
+
it "Question mark expression in pattern (3)" do
|
63
|
+
before = <<-EOF
|
64
|
+
changed original contents
|
65
|
+
foobar
|
66
|
+
end of text
|
67
|
+
EOF
|
68
|
+
|
69
|
+
diff = <<-EOF
|
70
|
+
? original text
|
71
|
+
?+ # comment for foobar
|
72
|
+
+ foobar
|
73
|
+
EOF
|
74
|
+
|
75
|
+
after = <<-EOF
|
76
|
+
changed original contents
|
77
|
+
foobar
|
78
|
+
end of text
|
79
|
+
EOF
|
80
|
+
|
81
|
+
hunk = Rpatch::PatchHunk.new('@@ patch with qmark')
|
82
|
+
diff.split($/).each {|line| hunk.feed_line line.chomp}
|
83
|
+
|
84
|
+
hunk.match_after_patch(before.split($/)).should eq [1, 1]
|
85
|
+
hunk.match_before_patch(before.split($/)).should eq nil
|
86
|
+
expect {
|
87
|
+
hunk.patch(before.split($/))
|
88
|
+
}.to raise_exception Rpatch::AlreadyPatchedError, /Hunk # \(patch with qmark\) is already patched\./
|
89
|
+
end
|
90
|
+
|
91
|
+
it "Question mark expression in pattern (4)" do
|
92
|
+
before = <<-EOF
|
93
|
+
Copyright 2013, jiangxin
|
94
|
+
foo
|
95
|
+
baz
|
96
|
+
|
97
|
+
bar
|
98
|
+
bye.
|
99
|
+
EOF
|
100
|
+
|
101
|
+
diff = <<-EOF
|
102
|
+
?/ [cC]opyright [0-9]{4}
|
103
|
+
? Hello, world
|
104
|
+
?+
|
105
|
+
+ baz
|
106
|
+
EOF
|
107
|
+
|
108
|
+
after = before.dup
|
109
|
+
|
110
|
+
hunk = Rpatch::PatchHunk.new('@@ patch with qmark')
|
111
|
+
diff.split($/).each {|line| hunk.feed_line line.chomp}
|
112
|
+
|
113
|
+
hunk.match_after_patch(before.split($/)).should eq [2, 1]
|
114
|
+
hunk.match_before_patch(before.split($/)).should eq nil
|
115
|
+
expect {
|
116
|
+
hunk.patch(before.split($/))
|
117
|
+
}.to raise_exception Rpatch::AlreadyPatchedError, /Hunk # \(patch with qmark\) is already patched\./
|
118
|
+
end
|
119
|
+
|
120
|
+
it "Question mark expression in pattern (5)" do
|
121
|
+
before = <<-EOF
|
122
|
+
Copyright 2013, jiangxin
|
123
|
+
Hello, world
|
124
|
+
foo
|
125
|
+
baz
|
126
|
+
|
127
|
+
bar
|
128
|
+
bye.
|
129
|
+
EOF
|
130
|
+
|
131
|
+
diff = <<-EOF
|
132
|
+
?/ [cC]opyright [0-9]{4}
|
133
|
+
? Hello, world
|
134
|
+
?+
|
135
|
+
+ baz
|
136
|
+
EOF
|
137
|
+
|
138
|
+
after = before.dup
|
139
|
+
|
140
|
+
hunk = Rpatch::PatchHunk.new('@@ patch with qmark')
|
141
|
+
diff.split($/).each {|line| hunk.feed_line line.chomp}
|
142
|
+
|
143
|
+
hunk.match_after_patch(before.split($/)).should eq [3, 1]
|
144
|
+
hunk.match_before_patch(before.split($/)).should eq [0, 2]
|
145
|
+
hunk.patterns_before_patch.size.should eq 2
|
146
|
+
hunk.patterns_after_patch.size.should eq 1
|
147
|
+
expect {
|
148
|
+
hunk.patch(before.split($/))
|
149
|
+
}.to raise_exception Rpatch::AlreadyPatchedError, /Hunk # \(patch with qmark\) is already patched\./
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
|
6
|
+
describe Rpatch::PatchHunk do
|
7
|
+
|
8
|
+
it "Regexp in pattern" do
|
9
|
+
before = <<-EOF
|
10
|
+
HeLLo
|
11
|
+
world
|
12
|
+
EOF
|
13
|
+
|
14
|
+
diff = <<-EOF
|
15
|
+
/ [hH][eE][lL]{2}[oO]
|
16
|
+
+foo
|
17
|
+
+bar
|
18
|
+
EOF
|
19
|
+
|
20
|
+
after = <<-EOF
|
21
|
+
HeLLo
|
22
|
+
foo
|
23
|
+
bar
|
24
|
+
world
|
25
|
+
EOF
|
26
|
+
|
27
|
+
hunk = Rpatch::PatchHunk.new('@@ description')
|
28
|
+
diff.split($/).each {|line| hunk.feed_line line.chomp}
|
29
|
+
|
30
|
+
hunk.match_after_patch(before.split($/)).should eq nil
|
31
|
+
hunk.match_before_patch(before.split($/)).should eq [0, 1]
|
32
|
+
result = hunk.patch(before.split($/))
|
33
|
+
(result * "\n" + "\n").should eq after
|
34
|
+
end
|
35
|
+
|
36
|
+
it "Regexp in pattern (2)" do
|
37
|
+
before = <<-EOF
|
38
|
+
Copyright 2013
|
39
|
+
HeLLo
|
40
|
+
world
|
41
|
+
--
|
42
|
+
jiangxin
|
43
|
+
EOF
|
44
|
+
|
45
|
+
diff = <<-EOF
|
46
|
+
/ [hH][eE][lL]{2}[oO]
|
47
|
+
+foo
|
48
|
+
+bar
|
49
|
+
/-wo*
|
50
|
+
+baz
|
51
|
+
EOF
|
52
|
+
|
53
|
+
after = <<-EOF
|
54
|
+
Copyright 2013
|
55
|
+
HeLLo
|
56
|
+
foo
|
57
|
+
bar
|
58
|
+
baz
|
59
|
+
--
|
60
|
+
jiangxin
|
61
|
+
EOF
|
62
|
+
|
63
|
+
hunk = Rpatch::PatchHunk.new('@@ description')
|
64
|
+
diff.split($/).each {|line| hunk.feed_line line.chomp}
|
65
|
+
|
66
|
+
hunk.match_after_patch(before.split($/)).should eq nil
|
67
|
+
hunk.match_before_patch(before.split($/)).should eq [1, 2]
|
68
|
+
result = hunk.patch(before.split($/))
|
69
|
+
(result * "\n" + "\n").should eq after
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
data/t/t0000-patch-file.sh
CHANGED
@@ -10,8 +10,8 @@ test_description='patch file test'
|
|
10
10
|
############################################################
|
11
11
|
|
12
12
|
cat > diff <<EOF
|
13
|
-
diff -u
|
14
|
-
---
|
13
|
+
diff -u /dev/null b/foo
|
14
|
+
--- /dev/null 2013-11-04 16:01:56.000000000 +0800
|
15
15
|
+++ b/foo 2013-11-04 16:01:59.000000000 +0800
|
16
16
|
@@ add two lines
|
17
17
|
+bar
|
@@ -34,15 +34,15 @@ test_expect_success 'patch newfile' '
|
|
34
34
|
|
35
35
|
cat > expect_errlog <<EOF
|
36
36
|
Patched "actual".
|
37
|
-
actual: Hunk 1 (add two lines) is already patched.
|
37
|
+
INFO: actual: Hunk 1 (add two lines) is already patched.
|
38
38
|
actual: nothing changed
|
39
39
|
EOF
|
40
40
|
|
41
41
|
test_expect_success 'patch newfile (2nd)' '
|
42
42
|
rm actual &&
|
43
43
|
touch actual &&
|
44
|
-
rpatch actual < diff 2> actual_errlog &&
|
45
|
-
rpatch actual < diff 2>>actual_errlog &&
|
44
|
+
rpatch -vv actual < diff 2> actual_errlog &&
|
45
|
+
rpatch -vv actual < diff 2>>actual_errlog &&
|
46
46
|
test_cmp expect actual &&
|
47
47
|
test_cmp expect_errlog actual_errlog
|
48
48
|
'
|
@@ -55,7 +55,6 @@ baz
|
|
55
55
|
EOF
|
56
56
|
|
57
57
|
cat > diff <<EOF
|
58
|
-
diff -u a/foo b/foo
|
59
58
|
--- a/foo 2013-11-04 16:01:56.000000000 +0800
|
60
59
|
+++ b/foo 2013-11-04 16:01:59.000000000 +0800
|
61
60
|
@@ insert heading
|
@@ -85,14 +84,14 @@ test_expect_success 'patch add/remote contents' '
|
|
85
84
|
############################################################
|
86
85
|
|
87
86
|
cat > expect_errlog <<EOF
|
88
|
-
actual: Hunk 1 (insert heading) is already patched.
|
89
|
-
actual: Hunk 2 (add/remove) is already patched.
|
90
|
-
actual: Hunk 3 (insert footer) is already patched.
|
87
|
+
INFO: actual: Hunk 1 (insert heading) is already patched.
|
88
|
+
INFO: actual: Hunk 2 (add/remove) is already patched.
|
89
|
+
INFO: actual: Hunk 3 (insert footer) is already patched.
|
91
90
|
actual: nothing changed
|
92
91
|
EOF
|
93
92
|
|
94
93
|
test_expect_success 'patch add/remote contents (2nd)' '
|
95
|
-
rpatch actual < diff 2>actual_errlog &&
|
94
|
+
rpatch -vv actual < diff 2>actual_errlog &&
|
96
95
|
test_cmp expect actual &&
|
97
96
|
test_cmp expect_errlog actual_errlog
|
98
97
|
'
|
@@ -115,7 +114,7 @@ Remove "actual".
|
|
115
114
|
EOF
|
116
115
|
|
117
116
|
test_expect_success 'patch to rm file' '
|
118
|
-
rpatch -p1 actual < diff 2> actual_errlog &&
|
117
|
+
rpatch -vv -p1 actual < diff 2> actual_errlog &&
|
119
118
|
test ! -f actual &&
|
120
119
|
test_cmp expect_errlog actual_errlog
|
121
120
|
'
|
@@ -123,13 +122,13 @@ test_expect_success 'patch to rm file' '
|
|
123
122
|
############################################################
|
124
123
|
|
125
124
|
cat > expect_errlog <<EOF
|
126
|
-
actual: Hunk 1 (delete all) is already patched.
|
125
|
+
INFO: actual: Hunk 1 (delete all) is already patched.
|
127
126
|
actual: nothing changed
|
128
127
|
EOF
|
129
128
|
|
130
129
|
test_expect_success 'patch to rm file (2nd)' '
|
131
130
|
touch actual &&
|
132
|
-
rpatch -p1 actual < diff 2> actual_errlog &&
|
131
|
+
rpatch -vv -p1 actual < diff 2> actual_errlog &&
|
133
132
|
test -z "$(cat actual)" &&
|
134
133
|
test_cmp expect_errlog actual_errlog
|
135
134
|
'
|
@@ -147,11 +146,11 @@ diff -u a/foo b/foo
|
|
147
146
|
--- a/foo 2013-11-04 16:01:56.000000000 +0800
|
148
147
|
+++ b/foo 2013-11-04 16:01:59.000000000 +0800
|
149
148
|
@@ remove bAr
|
150
|
-
|
151
|
-
|
149
|
+
/ ^[\\s]+(foo|FOO)\$
|
150
|
+
/-[bB][aA][rR]
|
152
151
|
+bar
|
153
152
|
@@ mixed
|
154
|
-
|
153
|
+
/ baz
|
155
154
|
+end of text
|
156
155
|
EOF
|
157
156
|
|
@@ -168,7 +167,7 @@ EOF
|
|
168
167
|
|
169
168
|
test_expect_success 'use regexp in patch' '
|
170
169
|
cp orig actual &&
|
171
|
-
rpatch actual < diff 2> actual_errlog &&
|
170
|
+
rpatch -vv actual < diff 2> actual_errlog &&
|
172
171
|
test_cmp expect actual &&
|
173
172
|
test_cmp expect_errlog actual_errlog
|
174
173
|
'
|
@@ -176,13 +175,13 @@ test_expect_success 'use regexp in patch' '
|
|
176
175
|
############################################################
|
177
176
|
|
178
177
|
cat > expect_errlog <<EOF
|
179
|
-
actual: Hunk 1 (remove bAr) is already patched.
|
180
|
-
actual: Hunk 2 (mixed) is already patched.
|
178
|
+
INFO: actual: Hunk 1 (remove bAr) is already patched.
|
179
|
+
INFO: actual: Hunk 2 (mixed) is already patched.
|
181
180
|
actual: nothing changed
|
182
181
|
EOF
|
183
182
|
|
184
183
|
test_expect_success 'use regexp in patch (2nd)' '
|
185
|
-
rpatch actual < diff 2> actual_errlog &&
|
184
|
+
rpatch -vv actual < diff 2> actual_errlog &&
|
186
185
|
test_cmp expect actual &&
|
187
186
|
test_cmp expect_errlog actual_errlog
|
188
187
|
'
|
@@ -200,14 +199,14 @@ trash text
|
|
200
199
|
EOF
|
201
200
|
|
202
201
|
cat > expect_errlog <<EOF
|
203
|
-
|
204
|
-
|
202
|
+
ERROR: Line 6 of patch "<IO>" is invalid.
|
203
|
+
=> "trash text"
|
205
204
|
EOF
|
206
205
|
|
207
206
|
test_expect_success 'patch load fail: bad syntax' '
|
208
207
|
rm actual &&
|
209
208
|
touch actual &&
|
210
|
-
test_must_fail rpatch actual < diff 2> actual_errlog &&
|
209
|
+
test_must_fail rpatch -vv actual < diff 2> actual_errlog &&
|
211
210
|
test_cmp expect_errlog actual_errlog
|
212
211
|
'
|
213
212
|
|
@@ -233,7 +232,7 @@ EOF
|
|
233
232
|
|
234
233
|
test_expect_success 'patch apply fail' '
|
235
234
|
cp orig actual &&
|
236
|
-
test_must_fail rpatch actual < diff 2> actual_errlog &&
|
235
|
+
test_must_fail rpatch -vv actual < diff 2> actual_errlog &&
|
237
236
|
test_cmp expect_errlog actual_errlog
|
238
237
|
'
|
239
238
|
|
@@ -262,14 +261,14 @@ EOF
|
|
262
261
|
|
263
262
|
cat > expect_errlog <<EOF
|
264
263
|
ERROR: actual: Hunk 2 (add footer) FAILED to apply. Match failed.
|
265
|
-
|
264
|
+
WARNING: saved orignal file as "actual.orig".
|
266
265
|
Patched "actual".
|
267
266
|
EOF
|
268
267
|
|
269
268
|
test_expect_success 'partial patch success' '
|
270
269
|
cp orig actual &&
|
271
270
|
test ! -f actual.orig &&
|
272
|
-
test_must_fail rpatch actual < diff 2> actual_errlog &&
|
271
|
+
test_must_fail rpatch -vv actual < diff 2> actual_errlog &&
|
273
272
|
test -f actual.orig &&
|
274
273
|
test_cmp actual.orig orig &&
|
275
274
|
test_cmp actual expect &&
|
@@ -279,13 +278,13 @@ test_expect_success 'partial patch success' '
|
|
279
278
|
############################################################
|
280
279
|
|
281
280
|
cat > expect_errlog <<EOF
|
282
|
-
actual: Hunk 1 (add header) is already patched.
|
281
|
+
INFO: actual: Hunk 1 (add header) is already patched.
|
283
282
|
ERROR: actual: Hunk 2 (add footer) FAILED to apply. Match failed.
|
284
283
|
actual: nothing changed
|
285
284
|
EOF
|
286
285
|
|
287
286
|
test_expect_success 'partial patch success (2nd)' '
|
288
|
-
test_must_fail rpatch actual < diff 2> actual_errlog &&
|
287
|
+
test_must_fail rpatch -vv actual < diff 2> actual_errlog &&
|
289
288
|
test -f actual.orig &&
|
290
289
|
test_cmp actual.orig orig &&
|
291
290
|
test_cmp actual expect &&
|
@@ -0,0 +1,336 @@
|
|
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
|
+
<
|
18
|
+
+bar
|
19
|
+
+baz
|
20
|
+
EOF
|
21
|
+
|
22
|
+
cat > actual <<EOF
|
23
|
+
hello
|
24
|
+
world
|
25
|
+
EOF
|
26
|
+
|
27
|
+
|
28
|
+
cat > expect <<EOF
|
29
|
+
bar
|
30
|
+
baz
|
31
|
+
hello
|
32
|
+
world
|
33
|
+
EOF
|
34
|
+
|
35
|
+
cat > expect_errlog <<EOF
|
36
|
+
Patched "actual".
|
37
|
+
EOF
|
38
|
+
|
39
|
+
test_expect_success 'patch from beginning' '
|
40
|
+
rpatch -p1 -vv actual < diff 2>actual_errlog &&
|
41
|
+
test_cmp expect actual &&
|
42
|
+
test_cmp expect_errlog actual_errlog
|
43
|
+
'
|
44
|
+
|
45
|
+
############################################################
|
46
|
+
|
47
|
+
cat > diff <<EOF
|
48
|
+
diff -u a/foo b/foo
|
49
|
+
--- a/foo 2013-11-04 16:01:56.000000000 +0800
|
50
|
+
+++ b/foo 2013-11-04 16:01:59.000000000 +0800
|
51
|
+
@@ add two lines
|
52
|
+
>
|
53
|
+
+bar
|
54
|
+
+baz
|
55
|
+
EOF
|
56
|
+
|
57
|
+
cat > actual <<EOF
|
58
|
+
hello
|
59
|
+
world
|
60
|
+
EOF
|
61
|
+
|
62
|
+
|
63
|
+
cat > expect <<EOF
|
64
|
+
hello
|
65
|
+
world
|
66
|
+
bar
|
67
|
+
baz
|
68
|
+
EOF
|
69
|
+
|
70
|
+
cat > expect_errlog <<EOF
|
71
|
+
Patched "actual".
|
72
|
+
EOF
|
73
|
+
|
74
|
+
test_expect_success 'patch from tail' '
|
75
|
+
rpatch -p1 -vv actual < diff 2>actual_errlog &&
|
76
|
+
test_cmp expect actual &&
|
77
|
+
test_cmp expect_errlog actual_errlog
|
78
|
+
'
|
79
|
+
|
80
|
+
############################################################
|
81
|
+
|
82
|
+
cat > diff <<EOF
|
83
|
+
diff -u a/foo b/foo
|
84
|
+
--- a/foo 2013-11-04 16:01:56.000000000 +0800
|
85
|
+
+++ b/foo 2013-11-04 16:01:59.000000000 +0800
|
86
|
+
@@ add two lines
|
87
|
+
<
|
88
|
+
hello, world
|
89
|
+
+bar
|
90
|
+
+baz
|
91
|
+
EOF
|
92
|
+
|
93
|
+
cat > actual <<EOF
|
94
|
+
hello, world
|
95
|
+
hello, world
|
96
|
+
EOF
|
97
|
+
|
98
|
+
|
99
|
+
cat > expect <<EOF
|
100
|
+
hello, world
|
101
|
+
bar
|
102
|
+
baz
|
103
|
+
hello, world
|
104
|
+
EOF
|
105
|
+
|
106
|
+
cat > expect_errlog <<EOF
|
107
|
+
Patched "actual".
|
108
|
+
EOF
|
109
|
+
|
110
|
+
test_expect_success 'patch from beginning (2)' '
|
111
|
+
rpatch -p1 -vv actual < diff 2>actual_errlog &&
|
112
|
+
test_cmp expect actual &&
|
113
|
+
test_cmp expect_errlog actual_errlog
|
114
|
+
'
|
115
|
+
|
116
|
+
############################################################
|
117
|
+
|
118
|
+
cat > diff <<EOF
|
119
|
+
diff -u a/foo b/foo
|
120
|
+
--- a/foo 2013-11-04 16:01:56.000000000 +0800
|
121
|
+
+++ b/foo 2013-11-04 16:01:59.000000000 +0800
|
122
|
+
@@ add two lines
|
123
|
+
>
|
124
|
+
hello, world
|
125
|
+
+bar
|
126
|
+
+baz
|
127
|
+
EOF
|
128
|
+
|
129
|
+
cat > actual <<EOF
|
130
|
+
hello, world
|
131
|
+
hello, world
|
132
|
+
EOF
|
133
|
+
|
134
|
+
|
135
|
+
cat > expect <<EOF
|
136
|
+
hello, world
|
137
|
+
hello, world
|
138
|
+
bar
|
139
|
+
baz
|
140
|
+
EOF
|
141
|
+
|
142
|
+
cat > expect_errlog <<EOF
|
143
|
+
Patched "actual".
|
144
|
+
EOF
|
145
|
+
|
146
|
+
test_expect_success 'patch from tail (2)' '
|
147
|
+
rpatch -p1 -vv actual < diff 2>actual_errlog &&
|
148
|
+
test_cmp expect actual &&
|
149
|
+
test_cmp expect_errlog actual_errlog
|
150
|
+
'
|
151
|
+
|
152
|
+
############################################################
|
153
|
+
|
154
|
+
cat > actual <<EOF
|
155
|
+
Copyright 2013, jiangxin
|
156
|
+
Hello, world
|
157
|
+
bye.
|
158
|
+
EOF
|
159
|
+
|
160
|
+
cat > diff <<EOF
|
161
|
+
diff -u a/foo b/foo
|
162
|
+
--- a/foo 2013-11-04 16:01:56.000000000 +0800
|
163
|
+
+++ b/foo 2013-11-04 16:01:59.000000000 +0800
|
164
|
+
@@ add two lines
|
165
|
+
/ [cC]opyright [0-9]{4}
|
166
|
+
/-[Hh]ello
|
167
|
+
+foo
|
168
|
+
+bar
|
169
|
+
EOF
|
170
|
+
|
171
|
+
cat > expect <<EOF
|
172
|
+
Copyright 2013, jiangxin
|
173
|
+
foo
|
174
|
+
bar
|
175
|
+
bye.
|
176
|
+
EOF
|
177
|
+
|
178
|
+
cat > expect_errlog <<EOF
|
179
|
+
Patched "actual".
|
180
|
+
EOF
|
181
|
+
|
182
|
+
test_expect_success 'Start regex pattern with /' '
|
183
|
+
rpatch -p1 -vv actual < diff 2>actual_errlog &&
|
184
|
+
test_cmp expect actual &&
|
185
|
+
test_cmp expect_errlog actual_errlog
|
186
|
+
'
|
187
|
+
|
188
|
+
############################################################
|
189
|
+
|
190
|
+
cat > actual <<EOF
|
191
|
+
Copyright 2013, jiangxin
|
192
|
+
Hello, world
|
193
|
+
bye.
|
194
|
+
EOF
|
195
|
+
|
196
|
+
cat > diff <<EOF
|
197
|
+
diff -u a/foo b/foo
|
198
|
+
--- a/foo 2013-11-04 16:01:56.000000000 +0800
|
199
|
+
+++ b/foo 2013-11-04 16:01:59.000000000 +0800
|
200
|
+
@@ foo
|
201
|
+
?/ [cC]opyright [0-9]{4}
|
202
|
+
? Hello, world
|
203
|
+
?+
|
204
|
+
+ foo
|
205
|
+
@@ bar
|
206
|
+
?/ [cC]opyright [0-9]{4}
|
207
|
+
? Hello, world
|
208
|
+
?+
|
209
|
+
+ bar
|
210
|
+
@@ baz
|
211
|
+
?/ [cC]opyright [0-9]{4}
|
212
|
+
? Hello, world
|
213
|
+
?+
|
214
|
+
+ baz
|
215
|
+
EOF
|
216
|
+
|
217
|
+
cat > expect <<EOF
|
218
|
+
Copyright 2013, jiangxin
|
219
|
+
Hello, world
|
220
|
+
|
221
|
+
baz
|
222
|
+
|
223
|
+
bar
|
224
|
+
|
225
|
+
foo
|
226
|
+
bye.
|
227
|
+
EOF
|
228
|
+
|
229
|
+
cat > expect_errlog <<EOF
|
230
|
+
Patched "actual".
|
231
|
+
EOF
|
232
|
+
|
233
|
+
test_expect_success 'Question mark patterns test (1)' '
|
234
|
+
rpatch -p1 -vv actual < diff 2>actual_errlog &&
|
235
|
+
test_cmp expect actual &&
|
236
|
+
test_cmp expect_errlog actual_errlog
|
237
|
+
'
|
238
|
+
|
239
|
+
############################################################
|
240
|
+
|
241
|
+
cat > actual <<EOF
|
242
|
+
Copyright 2013, jiangxin
|
243
|
+
foo
|
244
|
+
baz
|
245
|
+
|
246
|
+
bar
|
247
|
+
bye.
|
248
|
+
EOF
|
249
|
+
|
250
|
+
cat > diff <<EOF
|
251
|
+
diff -u a/foo b/foo
|
252
|
+
--- a/foo 2013-11-04 16:01:56.000000000 +0800
|
253
|
+
+++ b/foo 2013-11-04 16:01:59.000000000 +0800
|
254
|
+
@@ foo
|
255
|
+
?/ [cC]opyright [0-9]{4}
|
256
|
+
? Hello, world
|
257
|
+
?+
|
258
|
+
+ foo
|
259
|
+
@@ bar
|
260
|
+
?/ [cC]opyright [0-9]{4}
|
261
|
+
? Hello, world
|
262
|
+
?+
|
263
|
+
+ bar
|
264
|
+
@@ baz
|
265
|
+
?/ [cC]opyright [0-9]{4}
|
266
|
+
? Hello, world
|
267
|
+
?+
|
268
|
+
+ baz
|
269
|
+
EOF
|
270
|
+
|
271
|
+
cp actual expect
|
272
|
+
|
273
|
+
cat > expect_errlog <<EOF
|
274
|
+
INFO: actual: Hunk 1 (foo) is already patched.
|
275
|
+
INFO: actual: Hunk 2 (bar) is already patched.
|
276
|
+
INFO: actual: Hunk 3 (baz) is already patched.
|
277
|
+
actual: nothing changed
|
278
|
+
EOF
|
279
|
+
|
280
|
+
test_expect_success 'Question mark patterns test (2)' '
|
281
|
+
rpatch -p1 -vv actual < diff 2>actual_errlog &&
|
282
|
+
test_cmp expect actual &&
|
283
|
+
test_cmp expect_errlog actual_errlog
|
284
|
+
'
|
285
|
+
|
286
|
+
############################################################
|
287
|
+
|
288
|
+
cat > actual <<EOF
|
289
|
+
Copyright 2013, jiangxin
|
290
|
+
Hello, world
|
291
|
+
foo
|
292
|
+
baz
|
293
|
+
|
294
|
+
bar
|
295
|
+
bye.
|
296
|
+
EOF
|
297
|
+
|
298
|
+
cat > diff <<EOF
|
299
|
+
diff -u a/foo b/foo
|
300
|
+
--- a/foo 2013-11-04 16:01:56.000000000 +0800
|
301
|
+
+++ b/foo 2013-11-04 16:01:59.000000000 +0800
|
302
|
+
@@ foo
|
303
|
+
?/ [cC]opyright [0-9]{4}
|
304
|
+
? Hello, world
|
305
|
+
?+
|
306
|
+
+ foo
|
307
|
+
@@ bar
|
308
|
+
?/ [cC]opyright [0-9]{4}
|
309
|
+
? Hello, world
|
310
|
+
?+
|
311
|
+
+ bar
|
312
|
+
@@ baz
|
313
|
+
?/ [cC]opyright [0-9]{4}
|
314
|
+
? Hello, world
|
315
|
+
?+
|
316
|
+
+ baz
|
317
|
+
EOF
|
318
|
+
|
319
|
+
cp actual expect
|
320
|
+
|
321
|
+
cat > expect_errlog <<EOF
|
322
|
+
INFO: actual: Hunk 1 (foo) is already patched.
|
323
|
+
INFO: actual: Hunk 2 (bar) is already patched.
|
324
|
+
INFO: actual: Hunk 3 (baz) is already patched.
|
325
|
+
actual: nothing changed
|
326
|
+
EOF
|
327
|
+
|
328
|
+
test_expect_success 'Question mark patterns test (3)' '
|
329
|
+
rpatch -p1 -vv actual < diff 2>actual_errlog &&
|
330
|
+
test_cmp expect actual &&
|
331
|
+
test_cmp expect_errlog actual_errlog
|
332
|
+
'
|
333
|
+
|
334
|
+
############################################################
|
335
|
+
|
336
|
+
test_done
|