pa 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -1
- data/lib/pa/cmd.rb +18 -7
- data/lib/pa/util.rb +4 -0
- data/lib/pa/version.rb +1 -1
- data/pa.gemspec +2 -0
- data/spec/pa/cmd_spec.rb +388 -145
- data/spec/pa/directory_spec.rb +38 -66
- metadata +1 -7
data/.gitignore
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
/*.gem
|
data/lib/pa/cmd.rb
CHANGED
@@ -14,6 +14,12 @@ class Pa
|
|
14
14
|
module Cmd
|
15
15
|
extend Util::Concern
|
16
16
|
module ClassMethods
|
17
|
+
DELEGATE_METHODS = [ :home ]
|
18
|
+
|
19
|
+
def home2
|
20
|
+
Dir.home
|
21
|
+
end
|
22
|
+
|
17
23
|
# link
|
18
24
|
#
|
19
25
|
# @overload ln(src, dest)
|
@@ -31,7 +37,7 @@ class Pa
|
|
31
37
|
# @see ln
|
32
38
|
# @return [nil]
|
33
39
|
def ln_f(src_s, dest, o={})
|
34
|
-
o[:force]=true
|
40
|
+
o[:force] = true
|
35
41
|
_ln(:link, src_s, dest, o)
|
36
42
|
end
|
37
43
|
|
@@ -158,10 +164,6 @@ class Pa
|
|
158
164
|
p
|
159
165
|
end # def mktmpdir
|
160
166
|
|
161
|
-
def home
|
162
|
-
Dir.home
|
163
|
-
end
|
164
|
-
|
165
167
|
# make temp file
|
166
168
|
# @see mktmpdir
|
167
169
|
#
|
@@ -211,7 +213,7 @@ class Pa
|
|
211
213
|
paths, o = Util.extract_options(paths)
|
212
214
|
glob(*paths) { |pa|
|
213
215
|
extra_doc = o[:force] ? "-f " : nil
|
214
|
-
puts "rm #{extra_doc}#{
|
216
|
+
puts "rm #{extra_doc}#{pa.p}" if o[:verbose]
|
215
217
|
|
216
218
|
if File.directory?(pa.p)
|
217
219
|
if o[:force]
|
@@ -417,6 +419,7 @@ class Pa
|
|
417
419
|
end
|
418
420
|
end # def _move
|
419
421
|
|
422
|
+
# @param [Array<String,Pa>] paths
|
420
423
|
def _touch(paths, o)
|
421
424
|
o[:mode] ||= 0644
|
422
425
|
paths.map!{|v|get(v)}
|
@@ -430,7 +433,7 @@ class Pa
|
|
430
433
|
|
431
434
|
mkdir(File.dirname(p)) if o[:mkdir]
|
432
435
|
|
433
|
-
if win32?
|
436
|
+
if Util.win32?
|
434
437
|
# win32 BUG. must f.write("") then file can be deleted.
|
435
438
|
File.open(p, "w"){|f| f.chmod(o[:mode]); f.write("")}
|
436
439
|
else
|
@@ -548,6 +551,14 @@ class Pa
|
|
548
551
|
rescue Errno::ENOENT
|
549
552
|
end
|
550
553
|
end # _copy
|
554
|
+
|
555
|
+
DELEGATE_METHODS.each do |mth|
|
556
|
+
class_eval <<-EOF
|
557
|
+
def #{mth}(*args, &blk)
|
558
|
+
Pa(#{mth}2(*args, &blk))
|
559
|
+
end
|
560
|
+
EOF
|
561
|
+
end
|
551
562
|
end
|
552
563
|
end
|
553
564
|
end
|
data/lib/pa/util.rb
CHANGED
data/lib/pa/version.rb
CHANGED
data/pa.gemspec
CHANGED
data/spec/pa/cmd_spec.rb
CHANGED
@@ -10,134 +10,379 @@ describe Pa do
|
|
10
10
|
before :all do
|
11
11
|
@curdir = Dir.pwd
|
12
12
|
@tmpdir = Dir.mktmpdir
|
13
|
-
Dir.chdir
|
13
|
+
Dir.chdir @tmpdir
|
14
14
|
end
|
15
|
+
|
15
16
|
after :all do
|
16
|
-
Dir.chdir
|
17
|
+
Dir.chdir @curdir
|
17
18
|
FileUtils.rm_r @tmpdir
|
18
19
|
end
|
19
20
|
|
21
|
+
# clean up directory after each run
|
22
|
+
after :each do
|
23
|
+
FileUtils.rm_r Dir.glob("*", File::FNM_DOTMATCH)-%w[. ..]
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#home2" do
|
27
|
+
it "works" do
|
28
|
+
Pa.home2.should == Dir.home
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
20
32
|
describe "#_ln" do
|
21
|
-
#
|
22
|
-
before :
|
23
|
-
FileUtils.touch
|
33
|
+
# _lna
|
34
|
+
before :each do
|
35
|
+
FileUtils.touch %w[_lna]
|
24
36
|
end
|
25
37
|
|
26
38
|
it "works" do
|
27
39
|
output = capture :stdout do
|
28
|
-
Pa._ln(:link, "
|
40
|
+
Pa._ln(:link, "_lna", "_lnb", :verbose => true)
|
29
41
|
end
|
30
42
|
|
31
|
-
output.should == "ln
|
32
|
-
File.identical?("
|
43
|
+
output.should == "ln _lna _lnb\n"
|
44
|
+
File.identical?("_lna", "_lnb").should be_true
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#ln" do
|
49
|
+
# file1
|
50
|
+
before :each do
|
51
|
+
FileUtils.touch %w[file1]
|
52
|
+
end
|
53
|
+
|
54
|
+
it "works" do
|
55
|
+
Pa.ln("file1", "lna")
|
56
|
+
File.identical?("file1", "lna").should be_true
|
57
|
+
|
58
|
+
Pa.ln(Pa("file1"), Pa("lnb"))
|
59
|
+
File.identical?("file1", "lnb").should be_true
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "#ln_f" do
|
64
|
+
# file1
|
65
|
+
# file2
|
66
|
+
# file3
|
67
|
+
before :each do
|
68
|
+
FileUtils.touch %w[file1 file2 file3]
|
69
|
+
end
|
70
|
+
|
71
|
+
it "works" do
|
72
|
+
Pa.ln_f("file1", "file2")
|
73
|
+
File.identical?("file1", "file2").should be_true
|
74
|
+
|
75
|
+
Pa.ln_f(Pa("file1"), Pa("file3"))
|
76
|
+
File.identical?("file1", "file3").should be_true
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "#symln" do
|
81
|
+
# file1
|
82
|
+
before :each do
|
83
|
+
FileUtils.touch %w[file1]
|
84
|
+
end
|
85
|
+
|
86
|
+
it "works" do
|
87
|
+
Pa.symln("file1", "syma")
|
88
|
+
File.symlink?("syma").should be_true
|
89
|
+
|
90
|
+
Pa.symln(Pa("file1"), Pa("symb"))
|
91
|
+
File.symlink?("symb").should be_true
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "#symln_f" do
|
96
|
+
# file1
|
97
|
+
# file2
|
98
|
+
# file3
|
99
|
+
before :each do
|
100
|
+
FileUtils.touch %w[file1 file2 file3]
|
101
|
+
end
|
102
|
+
|
103
|
+
it "works" do
|
104
|
+
Pa.symln_f("file1", "file2")
|
105
|
+
File.symlink?("file2").should be_true
|
106
|
+
|
107
|
+
Pa.symln_f(Pa("file1"), Pa("file3"))
|
108
|
+
File.symlink?("file3").should be_true
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "#readlink" do
|
113
|
+
# syma -> file1
|
114
|
+
before :each do
|
115
|
+
FileUtils.touch %w[file1]
|
116
|
+
File.symlink "file1", "syma"
|
117
|
+
end
|
118
|
+
|
119
|
+
it "works" do
|
120
|
+
Pa.readlink("syma").should == "file1"
|
121
|
+
Pa.readlink(Pa("syma")).should == "file1"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe "#cd" do
|
126
|
+
# dir1/
|
127
|
+
before :each do
|
128
|
+
FileUtils.mkdir_p %w[dir1]
|
129
|
+
end
|
130
|
+
|
131
|
+
after :each do
|
132
|
+
Dir.chdir @tmpdir
|
133
|
+
end
|
134
|
+
|
135
|
+
it "works" do
|
136
|
+
Pa.cd("dir1")
|
137
|
+
Dir.pwd.should == File.join(@tmpdir, "dir1")
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe "#chroot" do
|
142
|
+
it "works" do
|
143
|
+
Dir.should_receive(:chroot).with("dir1")
|
144
|
+
Pa.chroot "dir1"
|
145
|
+
|
146
|
+
Dir.should_receive(:chroot).with("dir2")
|
147
|
+
Pa.chroot Pa("dir2")
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe "#_touch" do
|
152
|
+
it "works" do
|
153
|
+
Pa._touch ["file1", Pa("file2")], {}
|
154
|
+
|
155
|
+
File.exists?("file1").should be_true
|
156
|
+
File.exists?("file2").should be_true
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "#touch" do
|
161
|
+
it "works" do
|
162
|
+
Pa.touch("file1", "file2")
|
163
|
+
|
164
|
+
File.exists?("file1").should be_true
|
165
|
+
File.exists?("file2").should be_true
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
describe "#touch" do
|
170
|
+
# file1
|
171
|
+
# file2
|
172
|
+
before :each do
|
173
|
+
FileUtils.touch %w[file1 file2]
|
174
|
+
end
|
175
|
+
|
176
|
+
it "works" do
|
177
|
+
Pa.touch_f("file1", "file2")
|
178
|
+
|
179
|
+
File.exists?("file1").should be_true
|
180
|
+
File.exists?("file2").should be_true
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
describe "#mkdir" do
|
185
|
+
it "mkdir" do
|
186
|
+
Pa.mkdir("guten/tag")
|
187
|
+
File.exists?("guten/tag").should be_true
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
describe "#mkdir_f" do
|
192
|
+
# dir1/dira
|
193
|
+
before :each do
|
194
|
+
FileUtils.mkdir_p %w[dir1/dira]
|
195
|
+
end
|
196
|
+
|
197
|
+
it "mkdir" do
|
198
|
+
Pa.mkdir_f "dir1/dira"
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
describe "#_mktmpname" do
|
203
|
+
it "works" do
|
204
|
+
path = Pa._mktmpname("foo", :tmpdir => "guten")
|
205
|
+
|
206
|
+
path.should =~ %r~guten/foo\..{6}~
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
describe "#mktmpdir" do
|
211
|
+
it "works" do
|
212
|
+
Dir.should_receive(:mkdir)
|
213
|
+
|
214
|
+
path = Pa.mktmpdir("foo")
|
215
|
+
|
216
|
+
path.should =~ %r~#{Regexp.escape(ENV["TEMP"])}/foo~
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
describe "#mktmpfile2" do
|
221
|
+
it "works" do
|
222
|
+
path = Pa.mktmpfile2 :tmpdir => "foo"
|
223
|
+
|
224
|
+
path.should =~ %r~foo/#{$$}~
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
describe "#mktmpfile" do
|
229
|
+
it "works" do
|
230
|
+
path = Pa.mktmpfile
|
231
|
+
|
232
|
+
path.should be_an_instance_of(Pa)
|
33
233
|
end
|
34
234
|
end
|
35
235
|
|
36
236
|
describe "#_rmdir" do
|
37
237
|
# dir/
|
38
238
|
# a
|
39
|
-
#
|
239
|
+
# dir1/
|
40
240
|
# aa
|
41
|
-
before
|
42
|
-
|
43
|
-
FileUtils.
|
44
|
-
FileUtils.touch(%w(dir/a dir/dira/aa))
|
241
|
+
before :each do
|
242
|
+
FileUtils.mkdir_p %w[dir/dir1]
|
243
|
+
FileUtils.touch %w[dir/a dir/dir1/aa]
|
45
244
|
end
|
46
245
|
|
47
246
|
it "remove directory" do
|
48
|
-
|
247
|
+
Pa._rmdir Pa("dir")
|
49
248
|
File.exists?("dir").should be_false
|
50
249
|
end
|
51
250
|
end
|
52
251
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
252
|
+
describe "#rm" do
|
253
|
+
# rm family
|
254
|
+
# a
|
255
|
+
# dir/
|
256
|
+
# dir1/
|
257
|
+
# a
|
258
|
+
before :each do
|
259
|
+
FileUtils.mkdir_p %w[dir/dir1]
|
260
|
+
FileUtils.touch %w[a dir/a]
|
261
|
+
end
|
63
262
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
end
|
263
|
+
it "remove file" do
|
264
|
+
Pa.rm "a"
|
265
|
+
File.exists?("a").should be_false
|
266
|
+
lambda{Pa.rm("dir")}.should raise_error(Errno::EISDIR)
|
267
|
+
end
|
268
|
+
end
|
71
269
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
270
|
+
describe "#rm_f" do
|
271
|
+
# rm family
|
272
|
+
# a
|
273
|
+
# dir/
|
274
|
+
# dir1/
|
275
|
+
# a
|
276
|
+
before :each do
|
277
|
+
FileUtils.mkdir_p %w[dir/dir1]
|
278
|
+
FileUtils.touch %w[a dir/a]
|
279
|
+
end
|
77
280
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
lambda{Pa.rmdir("a")}.should raise_error(Errno::ENOTDIR)
|
83
|
-
end
|
84
|
-
end
|
281
|
+
it "remove file force" do
|
282
|
+
lambda{Pa.rm_f("dir")}.should_not raise_error(Errno::EISDIR)
|
283
|
+
end
|
284
|
+
end
|
85
285
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
286
|
+
describe "#rmdir" do
|
287
|
+
# rm family
|
288
|
+
# a
|
289
|
+
# dir/
|
290
|
+
# dir1/
|
291
|
+
# a
|
292
|
+
before :each do
|
293
|
+
FileUtils.mkdir_p %w[dir/dir1]
|
294
|
+
FileUtils.touch %w[a dir/a]
|
295
|
+
end
|
91
296
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
end
|
99
|
-
end
|
297
|
+
it "remove directory" do
|
298
|
+
Pa.rmdir "dir"
|
299
|
+
File.exists?("dir").should be_false
|
300
|
+
lambda{Pa.rmdir("a")}.should raise_error(Errno::ENOTDIR)
|
301
|
+
end
|
302
|
+
end
|
100
303
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
304
|
+
describe "#rmdir_f" do
|
305
|
+
# rm family
|
306
|
+
# a
|
307
|
+
# dir/
|
308
|
+
# dir1/
|
309
|
+
# a
|
310
|
+
before :each do
|
311
|
+
FileUtils.mkdir_p %w[dir/dir1]
|
312
|
+
FileUtils.touch %w[a dir/a]
|
313
|
+
end
|
107
314
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
315
|
+
it "remove directory force" do
|
316
|
+
lambda{Pa.rmdir_r("a")}.should_not raise_error(Errno::ENOTDIR)
|
317
|
+
end
|
318
|
+
end
|
112
319
|
|
113
|
-
|
320
|
+
describe "#rm_r" do
|
321
|
+
# rm family
|
322
|
+
# a
|
323
|
+
# dir/
|
324
|
+
# dir1/
|
325
|
+
# a
|
326
|
+
before :each do
|
327
|
+
FileUtils.mkdir_p %w[dir/dir1]
|
328
|
+
FileUtils.touch %w[a dir/a]
|
329
|
+
end
|
114
330
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
331
|
+
it "remove both file and directory" do
|
332
|
+
Pa.rm "a"
|
333
|
+
File.exists?("a").should be_false
|
334
|
+
Pa.rm_r "dir"
|
335
|
+
File.exists?("dir").should be_false
|
336
|
+
end
|
337
|
+
end
|
119
338
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
339
|
+
describe "#rm_if" do
|
340
|
+
# rm family
|
341
|
+
# a
|
342
|
+
# dir/
|
343
|
+
# dir1/
|
344
|
+
# a
|
345
|
+
before :each do
|
346
|
+
FileUtils.mkdir_p %w[dir/dir1]
|
347
|
+
FileUtils.touch %w[a dir/a]
|
348
|
+
end
|
349
|
+
|
350
|
+
it "remove if condition" do
|
351
|
+
Pa.rm_if(".") { |pa|
|
352
|
+
next if pa.p=="a"
|
353
|
+
yield if pa.b=="a"
|
354
|
+
}
|
355
|
+
|
356
|
+
File.exists?("a").should be_true
|
357
|
+
File.exists?("dir/dir1/a").should be_false
|
358
|
+
end
|
359
|
+
end
|
125
360
|
|
126
361
|
describe "#_copy" do
|
362
|
+
# rm family
|
363
|
+
# a
|
364
|
+
# dir/
|
365
|
+
# dir1/
|
366
|
+
# a
|
367
|
+
before :each do
|
368
|
+
FileUtils.mkdir_p %w[dir/dir1]
|
369
|
+
FileUtils.touch %w[a dir/a]
|
370
|
+
end
|
371
|
+
|
127
372
|
# a symfile
|
128
373
|
# ab
|
129
374
|
# ac
|
130
375
|
# dir/
|
131
376
|
# b # guten
|
132
|
-
#
|
377
|
+
# dir1/
|
133
378
|
# c
|
134
379
|
# destdir/
|
135
380
|
# b # tag
|
136
381
|
# dir/
|
137
|
-
before :
|
138
|
-
FileUtils.mkdir_p
|
139
|
-
FileUtils.touch
|
140
|
-
File.symlink
|
382
|
+
before :each do
|
383
|
+
FileUtils.mkdir_p %w[dir/dir1 destdir/dir]
|
384
|
+
FileUtils.touch %w[a ab ac dir/b dir/dir1/c destdir/dir/b]
|
385
|
+
File.symlink "a", "symfile"
|
141
386
|
open("dir/b", "w"){|f|f.write "guten"}
|
142
387
|
open("destdir/dir/b", "w"){|f|f.write "tag"}
|
143
388
|
end
|
@@ -154,8 +399,8 @@ describe Pa do
|
|
154
399
|
|
155
400
|
context "with :symlink" do
|
156
401
|
it "_copy" do
|
157
|
-
Pa._copy 'symfile', '
|
158
|
-
File.symlink?('
|
402
|
+
Pa._copy 'symfile', 'symfile1'
|
403
|
+
File.symlink?('symfile1').should be_true
|
159
404
|
end
|
160
405
|
|
161
406
|
it "_copy with :folsymlink" do
|
@@ -167,60 +412,66 @@ describe Pa do
|
|
167
412
|
end
|
168
413
|
|
169
414
|
context "with :mkdir" do
|
170
|
-
it "_copy" do
|
415
|
+
it "_copy with :mkdir => false" do
|
171
416
|
lambda{Pa.cp "a", "destdir/mkdir/dir"}.should raise_error(Errno::ENOENT)
|
172
417
|
end
|
173
418
|
|
174
|
-
it "_copy with :mkdir" do
|
419
|
+
it "_copy with :mkdir => true" do
|
175
420
|
lambda{Pa.cp "a", "destdir/mkdir/dir", mkdir:true}.should_not raise_error(Errno::ENOENT)
|
176
421
|
File.exists?("destdir/mkdir/dir/a").should be_true
|
177
422
|
end
|
178
423
|
|
179
|
-
it "_copy with :mkdir" do
|
180
|
-
lambda{Pa.cp "a", "destdir/
|
181
|
-
File.exists?("destdir/
|
424
|
+
it "_copy with :mkdir => true" do
|
425
|
+
lambda{Pa.cp "a", "destdir/mkdir1", mkdir:true}.should_not raise_error(Errno::ENOENT)
|
426
|
+
File.exists?("destdir/mkdir1/a").should be_true
|
182
427
|
end
|
183
428
|
end
|
184
429
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
end
|
430
|
+
it "_copy with :force => false" do
|
431
|
+
File.open("destdir/overwrite","w"){|f|f.write("")}
|
432
|
+
lambda{Pa.cp "a", "destdir/overwrite"}.should raise_error(Errno::EEXIST)
|
433
|
+
end
|
190
434
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
end
|
435
|
+
it "_copy with :force => true" do
|
436
|
+
lambda{Pa.cp "a", "destdir/overwrite", force:true}.should_not raise_error(Errno::EEXIST)
|
437
|
+
end
|
195
438
|
|
196
|
-
it "_copy with :normal" do
|
439
|
+
it "_copy with :normal => true" do
|
197
440
|
Pa._copy 'dir', 'dir_normal', special: true
|
198
441
|
dir_empty = (Dir.entries('dir_normal').length==2)
|
199
442
|
dir_empty.should be_true
|
200
443
|
end
|
201
|
-
|
202
444
|
end
|
203
445
|
|
204
446
|
describe "#cp" do
|
447
|
+
# file1
|
448
|
+
# file2
|
449
|
+
# file3
|
450
|
+
# dir1/
|
451
|
+
|
452
|
+
before :each do
|
453
|
+
FileUtils.mkdir_p %w[dir1]
|
454
|
+
FileUtils.touch %w[file1 file2 file3]
|
455
|
+
end
|
456
|
+
|
205
457
|
it "cp file destdir/file" do
|
206
|
-
Pa.cp "
|
207
|
-
File.exists?("
|
458
|
+
Pa.cp "file1", "dir1/file2"
|
459
|
+
File.exists?("dir1/file2").should be_true
|
208
460
|
end
|
209
461
|
|
210
462
|
it "cp file destdir/" do
|
211
|
-
Pa.cp "
|
212
|
-
File.exists?("
|
463
|
+
Pa.cp "file1", "dir1"
|
464
|
+
File.exists?("dir1/file1").should be_true
|
213
465
|
end
|
214
466
|
|
215
467
|
it "cp file1 file2 .. dest_file" do
|
216
|
-
lambda{Pa.cp(%w
|
468
|
+
lambda{Pa.cp(%w[file1 file2], "file3")}.should raise_error(Errno::ENOTDIR)
|
217
469
|
end
|
218
470
|
|
219
|
-
it "cp file1 file2 ..
|
220
|
-
|
221
|
-
|
222
|
-
File.exists?("
|
223
|
-
File.exists?("dird/ab").should be_true
|
471
|
+
it "cp file1 file2 .. destdir/" do
|
472
|
+
Pa.cp %w[file1 file2], "dir1"
|
473
|
+
File.exists?("dir1/file1").should be_true
|
474
|
+
File.exists?("dir1/file2").should be_true
|
224
475
|
end
|
225
476
|
end
|
226
477
|
|
@@ -228,11 +479,8 @@ describe Pa do
|
|
228
479
|
# a
|
229
480
|
# dir/ b
|
230
481
|
before :each do
|
231
|
-
FileUtils.mkdir_p
|
232
|
-
FileUtils.touch
|
233
|
-
end
|
234
|
-
after :each do
|
235
|
-
FileUtils.rm_r Dir["*"]-%w(. ..)
|
482
|
+
FileUtils.mkdir_p %w[dir]
|
483
|
+
FileUtils.touch %w[a dir/b]
|
236
484
|
end
|
237
485
|
|
238
486
|
it "mv a dir/a" do
|
@@ -260,11 +508,8 @@ describe Pa do
|
|
260
508
|
# a b c
|
261
509
|
# dir/ aa
|
262
510
|
before :each do
|
263
|
-
FileUtils.mkdir_p
|
264
|
-
FileUtils.touch
|
265
|
-
end
|
266
|
-
after :each do
|
267
|
-
FileUtils.rm_r Dir["*"]-%w(. ..)
|
511
|
+
FileUtils.mkdir_p %w[dir]
|
512
|
+
FileUtils.touch %w[a b c dir/aa]
|
268
513
|
end
|
269
514
|
|
270
515
|
it "mv a dir/" do
|
@@ -283,37 +528,35 @@ describe Pa do
|
|
283
528
|
end
|
284
529
|
end
|
285
530
|
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
path = Pa.mktmpdir("foo")
|
299
|
-
|
300
|
-
path.should =~ %r~#{Regexp.escape(ENV["TEMP"])}/foo~
|
301
|
-
end
|
302
|
-
end
|
531
|
+
describe "#mv_f" do
|
532
|
+
# file1 with foo
|
533
|
+
# file2
|
534
|
+
# dir1/
|
535
|
+
# filea
|
536
|
+
# dir2/
|
537
|
+
# dir1/
|
538
|
+
before :each do
|
539
|
+
FileUtils.mkdir_p %w[dir1 dir2/dir1]
|
540
|
+
FileUtils.touch %w[file1 file2 dir1/filea]
|
541
|
+
open("file1", "w") {|f| f.write("foo")}
|
542
|
+
end
|
303
543
|
|
304
|
-
|
305
|
-
|
306
|
-
|
544
|
+
it "works" do
|
545
|
+
Pa.mv_f "file1", "file2"
|
546
|
+
File.read("file2").should == "foo"
|
307
547
|
|
308
|
-
|
309
|
-
|
310
|
-
|
548
|
+
Pa.mv_f "dir1", "dir2"
|
549
|
+
File.exists?("dir2/dir1/filea").should be_true
|
550
|
+
end
|
551
|
+
end
|
311
552
|
|
312
|
-
describe "
|
553
|
+
describe "class DELEGATE_METHODS" do
|
313
554
|
it "works" do
|
314
|
-
|
555
|
+
Pa.stub(:home2) { "/home/foo" }
|
556
|
+
Pa.home.should == Pa("/home/foo")
|
315
557
|
|
316
|
-
|
558
|
+
Pa.should_receive(:home2).with(1, 2)
|
559
|
+
Pa.home(1, 2)
|
317
560
|
end
|
318
561
|
end
|
319
562
|
end
|
data/spec/pa/directory_spec.rb
CHANGED
@@ -12,14 +12,19 @@ describe Pa do
|
|
12
12
|
before :all do
|
13
13
|
@curdir = Dir.pwd
|
14
14
|
@tmpdir = Dir.mktmpdir
|
15
|
-
Dir.chdir
|
15
|
+
Dir.chdir @tmpdir
|
16
16
|
end
|
17
17
|
|
18
18
|
after :all do
|
19
|
-
Dir.chdir
|
19
|
+
Dir.chdir @curdir
|
20
20
|
FileUtils.rm_r @tmpdir
|
21
21
|
end
|
22
22
|
|
23
|
+
# clean up directory after each run
|
24
|
+
after :each do
|
25
|
+
FileUtils.rm_r Dir.glob("*", File::FNM_DOTMATCH)-%w[. ..]
|
26
|
+
end
|
27
|
+
|
23
28
|
describe ".tmpdir2" do
|
24
29
|
it "works" do
|
25
30
|
Pa.tmpdir2.should == Dir.tmpdir
|
@@ -33,12 +38,10 @@ describe Pa do
|
|
33
38
|
end
|
34
39
|
|
35
40
|
describe ".glob2" do
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
after(:each) do
|
41
|
-
FileUtils.rm @files
|
41
|
+
# filea
|
42
|
+
# .filea
|
43
|
+
before :each do
|
44
|
+
FileUtils.touch %w[filea .filea]
|
42
45
|
end
|
43
46
|
|
44
47
|
it "returns 1 items" do
|
@@ -55,25 +58,19 @@ describe Pa do
|
|
55
58
|
end
|
56
59
|
|
57
60
|
describe ".each2" do
|
58
|
-
#
|
61
|
+
# filea .filea filea~
|
59
62
|
# dira/
|
60
63
|
# dirb/
|
61
64
|
# b
|
62
|
-
before
|
63
|
-
|
64
|
-
|
65
|
-
FileUtils.mkdir_p(@dirs)
|
66
|
-
FileUtils.touch(@files)
|
67
|
-
end
|
68
|
-
after(:each) do
|
69
|
-
FileUtils.rm @files
|
70
|
-
FileUtils.rm_r @dirs
|
65
|
+
before :each do
|
66
|
+
FileUtils.mkdir_p %w[dira/dirb]
|
67
|
+
FileUtils.touch %w[filea .filea filea~ dira/dirb/b]
|
71
68
|
end
|
72
69
|
|
73
70
|
it "works" do
|
74
71
|
ret = []
|
75
72
|
Pa.each2{|pa| ret << pa}
|
76
|
-
ret.sort.should == %w(.
|
73
|
+
ret.sort.should == %w(.filea dira filea filea~)
|
77
74
|
end
|
78
75
|
|
79
76
|
it "return a Enumerator when call without block" do
|
@@ -85,23 +82,23 @@ describe Pa do
|
|
85
82
|
end
|
86
83
|
|
87
84
|
it "raise Errno::ENOTDIDR if path isn't a directory" do
|
88
|
-
lambda { Pa.each2("
|
85
|
+
lambda { Pa.each2("filea"){} }.should raise_error(Errno::ENOTDIR)
|
89
86
|
end
|
90
87
|
|
91
88
|
it "each2(.) return 'foo' not '.foo'" do
|
92
|
-
Pa.each2.with_object([]){|(pa),m| m<<pa}.sort.should == %w(.
|
89
|
+
Pa.each2.with_object([]){|(pa),m| m<<pa}.sort.should == %w(.filea dira filea filea~)
|
93
90
|
end
|
94
91
|
|
95
92
|
it ".each2 with :dot => false -> list all files except dot file" do
|
96
|
-
Pa.each2(:dot => false).with_object([]){|(pa),m|m<<pa}.sort.should == %w[dira
|
93
|
+
Pa.each2(:dot => false).with_object([]){|(pa),m|m<<pa}.sort.should == %w[dira filea filea~]
|
97
94
|
end
|
98
95
|
|
99
96
|
it ".each2 with :backup => false" do
|
100
|
-
Pa.each2(:backup => false).with_object([]){|(pa),m|m<<pa}.sort.should == %w[.
|
97
|
+
Pa.each2(:backup => false).with_object([]){|(pa),m|m<<pa}.sort.should == %w[.filea dira filea]
|
101
98
|
end
|
102
99
|
|
103
100
|
it ".each2 with :absolute => true" do
|
104
|
-
b = %w[.
|
101
|
+
b = %w[.filea dira filea filea~].map{|v| File.join(Dir.pwd, v)}
|
105
102
|
Pa.each2(:absolute => true).with_object([]){|(pa),m|m<<pa}.sort.should == b
|
106
103
|
end
|
107
104
|
|
@@ -114,26 +111,19 @@ describe Pa do
|
|
114
111
|
end
|
115
112
|
|
116
113
|
describe ".each" do
|
117
|
-
#
|
114
|
+
# filea .filea filea~
|
118
115
|
# dira/
|
119
116
|
# dirb/
|
120
117
|
# b
|
121
|
-
before
|
122
|
-
|
123
|
-
|
124
|
-
FileUtils.mkdir_p(@dirs)
|
125
|
-
FileUtils.touch(@files)
|
126
|
-
end
|
127
|
-
|
128
|
-
after(:each) do
|
129
|
-
FileUtils.rm @files
|
130
|
-
FileUtils.rm_r @dirs
|
118
|
+
before :each do
|
119
|
+
FileUtils.mkdir_p %w[dira/dirb]
|
120
|
+
FileUtils.touch %w[filea .filea filea~ dira/dirb/b]
|
131
121
|
end
|
132
122
|
|
133
123
|
it "works" do
|
134
124
|
ret = []
|
135
125
|
Pa.each{|pa| ret << pa.p }
|
136
|
-
ret.sort.should == %w(.
|
126
|
+
ret.sort.should == %w(.filea dira filea filea~)
|
137
127
|
end
|
138
128
|
|
139
129
|
it "return a Enumerator when call without block" do
|
@@ -142,28 +132,22 @@ describe Pa do
|
|
142
132
|
end
|
143
133
|
|
144
134
|
describe ".each2_r" do
|
145
|
-
#
|
135
|
+
# filea .filea filea~
|
146
136
|
# dira/
|
147
137
|
# dirb/
|
148
138
|
# b
|
149
|
-
before
|
150
|
-
|
151
|
-
|
152
|
-
FileUtils.mkdir_p(@dirs)
|
153
|
-
FileUtils.touch(@files)
|
154
|
-
end
|
155
|
-
after(:each) do
|
156
|
-
FileUtils.rm @files
|
157
|
-
FileUtils.rm_r @dirs
|
139
|
+
before :each do
|
140
|
+
FileUtils.mkdir_p %w[dira/dirb]
|
141
|
+
FileUtils.touch %w[filea .filea filea~ dira/dirb/b]
|
158
142
|
end
|
159
143
|
|
160
144
|
it "each2_r -> Enumerator" do
|
161
145
|
Pa.each2_r.should be_an_instance_of Enumerator
|
162
|
-
Pa.each2_r.with_object([]){|(pa,r),m|m<<r}.sort.should == %w[.
|
146
|
+
Pa.each2_r.with_object([]){|(pa,r),m|m<<r}.sort.should == %w[.filea dira dira/dirb dira/dirb/b filea filea~]
|
163
147
|
end
|
164
148
|
|
165
149
|
it "with :absolute => true" do
|
166
|
-
Pa.each2_r(:absolute => true).to_a[0][0].should == File.join(Dir.pwd, "
|
150
|
+
Pa.each2_r(:absolute => true).to_a[0][0].should == File.join(Dir.pwd, "filea~")
|
167
151
|
end
|
168
152
|
|
169
153
|
|
@@ -179,15 +163,9 @@ describe Pa do
|
|
179
163
|
# filea
|
180
164
|
# dira/
|
181
165
|
# fileb
|
182
|
-
before
|
183
|
-
|
184
|
-
|
185
|
-
FileUtils.mkdir_p(@dirs)
|
186
|
-
FileUtils.touch(@files)
|
187
|
-
end
|
188
|
-
after(:each) do
|
189
|
-
FileUtils.rm @files
|
190
|
-
FileUtils.rm_r @dirs
|
166
|
+
before :each do
|
167
|
+
FileUtils.mkdir_p %w[dira]
|
168
|
+
FileUtils.touch %w[filea dira/fileb]
|
191
169
|
end
|
192
170
|
|
193
171
|
it "works" do
|
@@ -208,15 +186,9 @@ describe Pa do
|
|
208
186
|
# filea
|
209
187
|
# dira/
|
210
188
|
# fileb
|
211
|
-
before
|
212
|
-
|
213
|
-
|
214
|
-
FileUtils.mkdir_p(@dirs)
|
215
|
-
FileUtils.touch(@files)
|
216
|
-
end
|
217
|
-
after(:each) do
|
218
|
-
FileUtils.rm @files
|
219
|
-
FileUtils.rm_r @dirs
|
189
|
+
before :each do
|
190
|
+
FileUtils.mkdir_p %w[dira]
|
191
|
+
FileUtils.touch %w[filea dira/fileb]
|
220
192
|
end
|
221
193
|
|
222
194
|
it "works" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -53,18 +53,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
53
53
|
- - ! '>='
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
|
-
segments:
|
57
|
-
- 0
|
58
|
-
hash: -4359841082193627011
|
59
56
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
57
|
none: false
|
61
58
|
requirements:
|
62
59
|
- - ! '>='
|
63
60
|
- !ruby/object:Gem::Version
|
64
61
|
version: '0'
|
65
|
-
segments:
|
66
|
-
- 0
|
67
|
-
hash: -4359841082193627011
|
68
62
|
requirements: []
|
69
63
|
rubyforge_project: xx
|
70
64
|
rubygems_version: 1.8.11
|