unix_utils 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/lib/unix_utils.rb +2 -2
- data/lib/unix_utils/version.rb +1 -1
- data/test/test_unix_utils.rb +13 -13
- metadata +1 -1
data/History.txt
CHANGED
data/lib/unix_utils.rb
CHANGED
@@ -169,8 +169,8 @@ module UnixUtils
|
|
169
169
|
def self.perl(infile, *expr)
|
170
170
|
infile = ::File.expand_path infile
|
171
171
|
outfile = tmp_path infile
|
172
|
-
argv = [ 'perl', expr.map { |e| ['-pe', e] } ].flatten
|
173
|
-
spawn argv, :
|
172
|
+
argv = [ 'perl', expr.map { |e| ['-pe', e] }, infile ].flatten
|
173
|
+
spawn argv, :write_to => outfile
|
174
174
|
outfile
|
175
175
|
end
|
176
176
|
|
data/lib/unix_utils/version.rb
CHANGED
data/test/test_unix_utils.rb
CHANGED
@@ -196,7 +196,7 @@ describe UnixUtils do
|
|
196
196
|
describe :perl do
|
197
197
|
before do
|
198
198
|
@f = Tempfile.new('perl.txt')
|
199
|
-
@f.write "
|
199
|
+
@f.write "badWord\n"*10_000
|
200
200
|
@f.flush
|
201
201
|
@infile = @f.path
|
202
202
|
end
|
@@ -205,7 +205,7 @@ describe UnixUtils do
|
|
205
205
|
end
|
206
206
|
it "processes a file" do
|
207
207
|
outfile = UnixUtils.perl(@infile, 's/bad/good/g')
|
208
|
-
File.read(outfile).must_equal "
|
208
|
+
File.read(outfile).must_equal "goodWord\n"*10_000
|
209
209
|
safe_delete outfile
|
210
210
|
end
|
211
211
|
it "does not touch the infile" do
|
@@ -221,7 +221,7 @@ describe UnixUtils do
|
|
221
221
|
describe :awk do
|
222
222
|
before do
|
223
223
|
@f = Tempfile.new('awk.txt')
|
224
|
-
@f.write "
|
224
|
+
@f.write "badWord\n"*10_000
|
225
225
|
@f.flush
|
226
226
|
@infile = @f.path
|
227
227
|
end
|
@@ -230,7 +230,7 @@ describe UnixUtils do
|
|
230
230
|
end
|
231
231
|
it "processes a file" do
|
232
232
|
outfile = UnixUtils.awk(@infile, '{gsub(/bad/, "good"); print}')
|
233
|
-
File.read(outfile).must_equal "
|
233
|
+
File.read(outfile).must_equal "goodWord\n"*10_000
|
234
234
|
safe_delete outfile
|
235
235
|
end
|
236
236
|
it "does not touch the infile" do
|
@@ -246,8 +246,8 @@ describe UnixUtils do
|
|
246
246
|
describe :unix2dos do
|
247
247
|
before do
|
248
248
|
@f = Tempfile.new('unix2dos.txt')
|
249
|
-
@f.write "unix\n"*
|
250
|
-
@f.write "dos\r\n"*
|
249
|
+
@f.write "unix\n"*5_000
|
250
|
+
@f.write "dos\r\n"*5_000
|
251
251
|
@f.flush
|
252
252
|
@infile = @f.path
|
253
253
|
end
|
@@ -256,7 +256,7 @@ describe UnixUtils do
|
|
256
256
|
end
|
257
257
|
it 'converts newlines' do
|
258
258
|
outfile = UnixUtils.unix2dos @infile
|
259
|
-
File.read(outfile).must_equal("unix\r\n"*
|
259
|
+
File.read(outfile).must_equal("unix\r\n"*5_000 + "dos\r\n"*5_000)
|
260
260
|
safe_delete outfile
|
261
261
|
end
|
262
262
|
end
|
@@ -282,8 +282,8 @@ describe UnixUtils do
|
|
282
282
|
describe :wc do
|
283
283
|
before do
|
284
284
|
@f = Tempfile.new('wc.txt')
|
285
|
-
@f.write "dos line\r\n"*
|
286
|
-
@f.write "unix line\n"*
|
285
|
+
@f.write "dos line\r\n"*5_000
|
286
|
+
@f.write "unix line\n"*5_000
|
287
287
|
@f.flush
|
288
288
|
@infile = @f.path
|
289
289
|
end
|
@@ -291,14 +291,14 @@ describe UnixUtils do
|
|
291
291
|
@f.close
|
292
292
|
end
|
293
293
|
it 'counts lines, words, and bytes' do
|
294
|
-
UnixUtils.wc(@infile).must_equal [
|
294
|
+
UnixUtils.wc(@infile).must_equal [5_000+5_000, 10_000+10_000, 50_000+50_000]
|
295
295
|
end
|
296
296
|
end
|
297
297
|
|
298
298
|
describe :sed do
|
299
299
|
before do
|
300
300
|
@f = Tempfile.new('sed.txt')
|
301
|
-
@f.write "
|
301
|
+
@f.write "badWord\n"*10_000
|
302
302
|
@f.flush
|
303
303
|
@infile = @f.path
|
304
304
|
end
|
@@ -307,7 +307,7 @@ describe UnixUtils do
|
|
307
307
|
end
|
308
308
|
it "processes a file" do
|
309
309
|
outfile = UnixUtils.sed(@infile, 's/bad/good/g')
|
310
|
-
File.read(outfile).must_equal "
|
310
|
+
File.read(outfile).must_equal "goodWord\n"*10_000
|
311
311
|
safe_delete outfile
|
312
312
|
end
|
313
313
|
it "does not touch the infile" do
|
@@ -413,7 +413,7 @@ describe UnixUtils do
|
|
413
413
|
File.extname(UnixUtils.tmp_path("dirname1/dirname2/basename.extname", '.foobar')).must_equal '.foobar'
|
414
414
|
end
|
415
415
|
it "doesn't create excessively long filenames" do
|
416
|
-
File.basename(UnixUtils.tmp_path("a"*5000)).length.
|
416
|
+
100.times { File.basename(UnixUtils.tmp_path("a"*5000)).length.must_be :<, 256 }
|
417
417
|
end
|
418
418
|
it "doesn't include directory part of ancestor" do
|
419
419
|
UnixUtils.tmp_path("dirname1/dirname2/basename.extname").wont_include 'dirname1'
|