rio 0.3.7 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (208) hide show
  1. data/ChangeLog +1273 -1482
  2. data/README +2 -2
  3. data/Rakefile +5 -5
  4. data/VERSION +1 -1
  5. data/{RUNME.1st.rb → build_doc.rb} +4 -10
  6. data/doc/ANNOUNCE +33 -80
  7. data/doc/RELEASE_NOTES +31 -1
  8. data/doc/generators/template/html/rio.rb +3 -3
  9. data/lib/rio/abstract_method.rb +2 -2
  10. data/lib/rio/argv.rb +2 -2
  11. data/lib/rio/arycopy.rb +2 -2
  12. data/lib/rio/assert.rb +2 -2
  13. data/lib/rio/base.rb +2 -2
  14. data/lib/rio/callstr.rb +47 -0
  15. data/lib/rio/const.rb +52 -0
  16. data/lib/rio/construct.rb +6 -24
  17. data/lib/rio/constructor.rb +12 -2
  18. data/lib/rio/context/autoclose.rb +73 -0
  19. data/lib/rio/context/copying.rb +2 -2
  20. data/lib/rio/context/cxx.rb +2 -2
  21. data/lib/rio/context/dir.rb +2 -2
  22. data/lib/rio/context/gzip.rb +2 -2
  23. data/lib/rio/context/methods.rb +6 -34
  24. data/lib/rio/context/skip.rb +2 -2
  25. data/lib/rio/context/stream.rb +2 -2
  26. data/lib/rio/context.rb +17 -2
  27. data/lib/rio/cp.rb +35 -9
  28. data/lib/rio/def.rb +54 -0
  29. data/lib/rio/dir.rb +19 -20
  30. data/lib/rio/doc/HOWTO.rb +23 -7
  31. data/lib/rio/doc/INTRO.rb +57 -23
  32. data/lib/rio/doc/MISC.rb +2 -2
  33. data/lib/rio/doc/OPTIONAL.rb +134 -0
  34. data/lib/rio/doc/SYNOPSIS.rb +11 -4
  35. data/lib/rio/doc.rb +2 -2
  36. data/lib/rio/entrysel.rb +25 -6
  37. data/lib/rio/exception/copy.rb +2 -2
  38. data/lib/rio/exception/notsupported.rb +47 -0
  39. data/lib/rio/exception/open.rb +2 -2
  40. data/lib/rio/exception/state.rb +2 -2
  41. data/lib/rio/exception.rb +2 -2
  42. data/lib/rio/ext/csv.rb +56 -11
  43. data/lib/rio/ext/yaml.rb +2 -2
  44. data/lib/rio/ext/zipfile.rb +91 -0
  45. data/lib/rio/ext.rb +38 -3
  46. data/lib/rio/factory.rb +17 -34
  47. data/lib/rio/file.rb +48 -8
  48. data/lib/rio/filter/closeoneof.rb +36 -16
  49. data/lib/rio/filter/gzip.rb +2 -2
  50. data/lib/rio/filter.rb +2 -2
  51. data/lib/rio/fs/base.rb +42 -0
  52. data/lib/rio/fs/impl.rb +123 -0
  53. data/lib/rio/fs/native.rb +76 -0
  54. data/lib/rio/{record.rb → fs/stream.rb} +21 -18
  55. data/lib/rio/fs/url.rb +64 -0
  56. data/lib/rio/ftp/{ioh.rb → conncache.rb} +38 -39
  57. data/lib/rio/ftp/dir.rb +95 -0
  58. data/lib/rio/ftp/fs.rb +173 -0
  59. data/lib/rio/ftp/ftpfile.rb +20 -0
  60. data/lib/rio/grande.rb +2 -2
  61. data/lib/rio/handle.rb +2 -2
  62. data/lib/rio/if/basic.rb +2 -2
  63. data/lib/rio/if/csv.rb +2 -2
  64. data/lib/rio/if/dir.rb +2 -2
  65. data/lib/rio/if/file.rb +26 -2
  66. data/lib/rio/if/fileordir.rb +44 -49
  67. data/lib/rio/if/grande.rb +32 -10
  68. data/lib/rio/if/grande_entry.rb +12 -2
  69. data/lib/rio/if/grande_stream.rb +17 -28
  70. data/lib/rio/if/internal.rb +2 -2
  71. data/lib/rio/if/path.rb +7 -6
  72. data/lib/rio/if/stream.rb +85 -29
  73. data/lib/rio/if/string.rb +2 -2
  74. data/lib/rio/if/temp.rb +2 -2
  75. data/lib/rio/if/test.rb +37 -4
  76. data/lib/rio/if/yaml.rb +2 -2
  77. data/lib/rio/if.rb +2 -2
  78. data/lib/rio/impl/path.rb +2 -2
  79. data/lib/rio/ioh.rb +17 -6
  80. data/lib/rio/iomode.rb +4 -3
  81. data/lib/rio/ios/fail.rb +107 -0
  82. data/lib/rio/ios/generic.rb +120 -0
  83. data/lib/rio/ios/mode.rb +61 -0
  84. data/lib/rio/ios/null.rb +120 -0
  85. data/lib/rio/iowrap.rb +129 -0
  86. data/lib/rio/kernel.rb +12 -3
  87. data/lib/rio/local.rb +2 -2
  88. data/lib/rio/match.rb +3 -3
  89. data/lib/rio/matchrecord.rb +2 -2
  90. data/lib/rio/no_warn.rb +50 -0
  91. data/lib/rio/{arrayio.rb → nullio.rb} +47 -86
  92. data/lib/rio/open3.rb +2 -2
  93. data/lib/rio/ops/construct.rb +20 -13
  94. data/lib/rio/ops/create.rb +10 -19
  95. data/lib/rio/ops/dir.rb +60 -54
  96. data/lib/rio/ops/either.rb +11 -9
  97. data/lib/rio/ops/file.rb +28 -24
  98. data/lib/rio/ops/path.rb +45 -43
  99. data/lib/rio/ops/stream/input.rb +12 -8
  100. data/lib/rio/ops/stream/output.rb +2 -2
  101. data/lib/rio/ops/stream/read.rb +35 -32
  102. data/lib/rio/ops/stream/write.rb +5 -5
  103. data/lib/rio/ops/stream.rb +7 -3
  104. data/lib/rio/ops/symlink.rb +12 -10
  105. data/lib/rio/path/reset.rb +5 -5
  106. data/lib/rio/path.rb +32 -24
  107. data/lib/rio/piper/cp.rb +2 -2
  108. data/lib/rio/piper.rb +2 -2
  109. data/lib/rio/prompt.rb +2 -2
  110. data/lib/rio/rectype.rb +9 -7
  111. data/lib/rio/rl/base.rb +5 -4
  112. data/lib/rio/rl/builder.rb +17 -5
  113. data/lib/rio/rl/ioi.rb +14 -4
  114. data/lib/rio/rl/path.rb +23 -15
  115. data/lib/rio/rl/pathmethods.rb +12 -2
  116. data/lib/rio/rl/uri.rb +13 -6
  117. data/lib/rio/scheme/aryio.rb +3 -3
  118. data/lib/rio/scheme/cmdio.rb +4 -3
  119. data/lib/rio/scheme/cmdpipe.rb +3 -35
  120. data/lib/rio/scheme/fd.rb +4 -3
  121. data/lib/rio/scheme/ftp.rb +36 -7
  122. data/lib/rio/scheme/http.rb +2 -2
  123. data/lib/rio/{context/closeoneof.rb → scheme/null.rb} +17 -11
  124. data/lib/rio/scheme/path.rb +28 -30
  125. data/lib/rio/scheme/stderr.rb +4 -4
  126. data/lib/rio/scheme/stdio.rb +6 -5
  127. data/lib/rio/scheme/strio.rb +10 -20
  128. data/lib/rio/scheme/sysio.rb +5 -2
  129. data/lib/rio/scheme/tcp.rb +4 -3
  130. data/lib/rio/scheme/temp.rb +14 -1
  131. data/lib/rio/state/error.rb +2 -2
  132. data/lib/rio/state.rb +80 -34
  133. data/lib/rio/stream/base.rb +7 -2
  134. data/lib/rio/stream/duplex.rb +13 -10
  135. data/lib/rio/stream/open.rb +74 -79
  136. data/lib/rio/stream.rb +15 -23
  137. data/lib/rio/symantics.rb +2 -2
  138. data/lib/rio/tempdir.rb +132 -132
  139. data/lib/rio/to_rio/all.rb +40 -0
  140. data/lib/rio/to_rio/array.rb +40 -0
  141. data/lib/rio/to_rio/io.rb +41 -0
  142. data/lib/rio/to_rio/object.rb +43 -0
  143. data/lib/rio/to_rio/string.rb +41 -0
  144. data/lib/rio/to_rio.rb +13 -2
  145. data/lib/rio/uri/file.rb +2 -2
  146. data/lib/rio/util.rb +2 -2
  147. data/lib/rio/version.rb +3 -3
  148. data/lib/rio.rb +16 -25
  149. data/test/bin/count_lines.rb +11 -0
  150. data/test/bin/find_lines.rb +13 -0
  151. data/test/bin/list_dir.rb +14 -0
  152. data/test/ftp/all.rb +9 -0
  153. data/test/ftp/anon_misc.rb +112 -0
  154. data/test/ftp/anon_read.rb +105 -0
  155. data/test/ftp/anon_special.rb +68 -0
  156. data/test/ftp/anon_write.rb +63 -0
  157. data/test/ftp/ftp2ftp.rb +51 -0
  158. data/test/ftp/initftpfiles.rb +14 -0
  159. data/test/ftp/testdef.rb +51 -0
  160. data/test/gem_runtests.rb +15 -15
  161. data/test/runalltests.rb +15 -0
  162. data/test/runftptests.rb +14 -0
  163. data/test/{1.rb → runhttptests.rb} +14 -14
  164. data/test/runtests.rb +14 -14
  165. data/test/tc/all.rb +36 -21
  166. data/test/tc/cmdpipe.rb +18 -15
  167. data/test/tc/copy-from-http.rb +89 -0
  168. data/test/tc/copy-from.rb +1 -52
  169. data/test/tc/copy.rb +19 -17
  170. data/test/tc/csv2.rb +6 -3
  171. data/test/tc/empty.rb +47 -0
  172. data/test/tc/emptyriodir.rb +129 -0
  173. data/test/tc/entsel.rb +110 -0
  174. data/test/tc/files_select.rb +92 -0
  175. data/test/tc/get.rb +7 -6
  176. data/test/tc/getrec.rb +2 -5
  177. data/test/tc/gzip.rb +82 -0
  178. data/test/tc/io_each_byte.rb +60 -0
  179. data/test/tc/io_read.rb +80 -0
  180. data/test/tc/iometh.rb +149 -0
  181. data/test/tc/likeio.rb +112 -0
  182. data/test/tc/methods.rb +10 -9
  183. data/test/tc/misc.rb +1 -37
  184. data/test/tc/null.rb +45 -0
  185. data/test/tc/pid.rb +31 -0
  186. data/test/tc/piper.rb +34 -37
  187. data/test/tc/programs_util.rb +24 -0
  188. data/test/tc/readline.rb +30 -0
  189. data/test/tc/rename.rb +12 -0
  190. data/test/tc/tempfile.rb +14 -0
  191. data/test/tc/testcase.rb +6 -0
  192. data/test/tc/tonl.rb +37 -0
  193. metadata +181 -144
  194. data/ex/colx.rb +0 -8
  195. data/ex/findinruby +0 -16
  196. data/ex/findruby +0 -15
  197. data/ex/passwd_report.rb +0 -8
  198. data/ex/prompt.rb +0 -25
  199. data/ex/rgb.txt.gz +0 -0
  200. data/ex/riocat +0 -35
  201. data/ex/riogunzip +0 -31
  202. data/ex/riogzip +0 -24
  203. data/ex/rioprompt.rb +0 -6
  204. data/ex/targz2zip +0 -17
  205. data/ex/tolf +0 -11
  206. data/lib/rio/ftp/conn.rb +0 -167
  207. data/lib/rio/ftp.rb +0 -275
  208. data/test/once.rb +0 -7
data/test/tc/likeio.rb ADDED
@@ -0,0 +1,112 @@
1
+ #!/usr/local/bin/ruby
2
+ if $0 == __FILE__
3
+ Dir.chdir File.dirname(__FILE__)+'/../'
4
+ $:.unshift File.expand_path('../lib/')
5
+ end
6
+
7
+ require 'rio'
8
+ require 'tc/testcase'
9
+
10
+ class TestData
11
+ attr_reader :fn_ruby,:fn_rio,:data
12
+ def initialize(prefix,data)
13
+ @data = data
14
+ @fn_ruby = prefix + 'ruby.dat'
15
+ @fn_rio = prefix + 'rio.dat'
16
+ rio(@fn_ruby) < @data
17
+ rio(@fn_rio) < @data
18
+ end
19
+ end
20
+
21
+ class TC_likeio < Test::RIO::TestCase
22
+ @@once = false
23
+ @@data = {}
24
+ def self.once
25
+ @@once = true
26
+ @@data['bytes'] = TestData.new('bytes_',"012")
27
+ @@data['lines'] = TestData.new('lines_',"Line0\nLine1\n")
28
+ end
29
+ def setup
30
+ super
31
+ self.class.once unless @@once
32
+ end
33
+ def open_data(td,&block)
34
+ begin
35
+ fruby = ::File.open(td.fn_ruby)
36
+ frio = rio(td.fn_rio)
37
+ yield(fruby,frio)
38
+ ensure
39
+ fruby.close
40
+ frio.close
41
+ end
42
+ end
43
+
44
+ def check_read_method(fruby,frio,n,sym,*args)
45
+ n.times {
46
+ assert_equal(fruby.__send__(sym,*args),frio.__send__(sym,*args))
47
+ assert_equal(fruby.eof?,frio.eof?)
48
+ }
49
+ end
50
+
51
+ def check_read_method_raises_eof(fruby,frio,n,sym,*args)
52
+ n.times {
53
+ ruby_raises = false
54
+ rio_raises = false
55
+ ruby_returns = nil
56
+ rio_returns = nil
57
+ begin
58
+ ruby_returns = fruby.__send__(sym,*args)
59
+ rescue EOFError
60
+ ruby_raises = true
61
+ end
62
+ begin
63
+ rio_returns = frio.__send__(sym,*args)
64
+ rescue EOFError
65
+ rio_raises = true
66
+ end
67
+ assert_equal(ruby_raises,rio_raises)
68
+ assert_equal(ruby_returns,rio_returns)
69
+ }
70
+ end
71
+
72
+ def check_iter(fruby,frio,sym,*args)
73
+ ans_ruby = []
74
+ ans_rio = []
75
+ fruby.__send__(sym,*args) { |el|
76
+ ans_ruby << el
77
+ }
78
+ frio.__send__(sym,*args) { |el|
79
+ ans_rio << el
80
+ }
81
+ assert_equal(ans_ruby,ans_rio)
82
+ end
83
+ def test_each_byte
84
+ open_data(@@data['bytes']) { |fruby,frio|
85
+ check_iter(fruby,frio,:each_byte)
86
+ }
87
+ end
88
+ def test_each_line
89
+ open_data(@@data['lines']) { |fruby,frio|
90
+ check_iter(fruby,frio,:each_line)
91
+ }
92
+ end
93
+ def test_gets
94
+ open_data(@@data['lines']) { |fruby,frio|
95
+ check_read_method(fruby,frio,3,:gets)
96
+ }
97
+ open_data(@@data['lines']) { |fruby,frio|
98
+ check_read_method(fruby,frio,4,:gets,'e')
99
+ }
100
+ end
101
+ def test_getc
102
+ open_data(@@data['bytes']) { |fruby,frio|
103
+ check_read_method(fruby,frio,4,:getc)
104
+ }
105
+ end
106
+ def test_readchar
107
+ testdata = @@data['bytes']
108
+ open_data(testdata) { |fruby,frio|
109
+ check_read_method_raises_eof(fruby,frio,testdata.data.size+1,:readchar)
110
+ }
111
+ end
112
+ end
data/test/tc/methods.rb CHANGED
@@ -21,12 +21,12 @@ class TC_RIO_methods < Test::Unit::TestCase
21
21
 
22
22
  cexp << ioc.gets
23
23
  oexp << ios.gets
24
- until ioc.eof?
25
- cexp << ioc.gets
24
+ while ans = ioc.gets
25
+ cexp << ans
26
26
  end
27
27
 
28
- until ios.eof?
29
- oexp << ios.gets
28
+ while ans = ios.gets
29
+ oexp << ans
30
30
  end
31
31
  return ioc,oexp,cexp
32
32
  end
@@ -40,12 +40,12 @@ class TC_RIO_methods < Test::Unit::TestCase
40
40
  assert_not_nil(ioc,"dup returns nil")
41
41
  cexp << ioc.gets
42
42
  oexp << ios.gets
43
- until ioc.eof?
44
- cexp << ioc.gets
43
+ while ans = ioc.gets
44
+ cexp << ans
45
45
  end
46
46
 
47
- until ios.eof?
48
- oexp << ios.gets
47
+ while ans = ios.gets
48
+ oexp << ans
49
49
  end
50
50
  return ioc,oexp,cexp
51
51
  end
@@ -67,6 +67,7 @@ class TC_RIO_methods < Test::Unit::TestCase
67
67
  assert(ios.closed?,"now original closed")
68
68
  end
69
69
  def setup
70
+ #$trace_states = true
70
71
  @cwd = rio(::Dir.getwd)
71
72
  @dir = rio('qp/methods')
72
73
  # $trace_states = true
@@ -82,10 +83,10 @@ class TC_RIO_methods < Test::Unit::TestCase
82
83
  end
83
84
  def teardown
84
85
  @cwd.chdir
86
+ $trace_states = false
85
87
  end
86
88
 
87
89
  def test_clone_like_IO
88
-
89
90
  ios = ::File.open('lines')
90
91
  ioc,oexp,cexp = check_clone(ios)
91
92
  check_clone_close(ios,ioc)
data/test/tc/misc.rb CHANGED
@@ -5,6 +5,7 @@ if $0 == __FILE__
5
5
  end
6
6
  require 'rio'
7
7
  require 'tc/testcase'
8
+ #require 'dev-utils/debug'
8
9
 
9
10
  #require 'tc_myfirsttests'
10
11
  #require 'tc_moretestsbyme'
@@ -25,28 +26,6 @@ class TC_RIO_misc < Test::Unit::TestCase
25
26
  got = f.a.puts("Line 5").readlines
26
27
  assert_equal(exp,got)
27
28
 
28
- f = rio('qp/rwlines.txt').nocloseoneof.autorewind.chomp.mode('w+')
29
- 0.upto(4) do |n|
30
- f.puts("Line #{n}")
31
- end
32
- got = f.puts("Line 5").readlines
33
- assert_equal(exp,got)
34
-
35
- f = rio('qp/rwlines.txt').nocloseoneof.autorewind.chomp.mode('w+')
36
- 0.upto(4) do |n|
37
- f.puts("Line #{n}")
38
- end
39
- got = f.puts!("line 5").readlines
40
- assert_equal([],got)
41
-
42
- f = rio('qp/rwlines.txt').nocloseoneof.autorewind.chomp.mode('w+')
43
- 0.upto(4) do |n|
44
- f.puts("Line #{n}")
45
- end
46
- f.close
47
- got = rio('qp/rwlines.txt').a.nocloseoneof.autorewind.chomp.puts!("Line 5").readlines
48
- assert_equal(exp,got)
49
-
50
29
  f = rio('qp/rwlines.txt').mode('w')
51
30
  0.upto(4) { |n| f.puts("Line #{n}") }
52
31
  assert_raise(IOError) {
@@ -121,21 +100,6 @@ class TC_RIO_misc < Test::Unit::TestCase
121
100
  got = f.a.puts("Line 5").readlines
122
101
  assert_equal(exp,got)
123
102
 
124
- f = rio('rwlines.txt').nocloseoneof.autorewind.chomp.mode('w+')
125
- 0.upto(4) { |n| f.puts("Line #{n}") }
126
- got = f.puts("Line 5").readlines
127
- assert_equal(exp,got)
128
-
129
- f = rio('rwlines.txt').nocloseoneof.autorewind.chomp.mode('w+')
130
- 0.upto(4) { |n| f.puts("Line #{n}") }
131
- got = f.puts!("line 5").readlines
132
- assert_equal([],got)
133
-
134
- f = rio('rwlines.txt').nocloseoneof.autorewind.chomp.mode('w+')
135
- 0.upto(4) { |n| f.puts("Line #{n}") }
136
- f.close
137
- got = rio('rwlines.txt').a.nocloseoneof.autorewind.chomp.puts!("Line 5").readlines
138
- assert_equal(exp,got)
139
103
 
140
104
  f = rio('rwlines.txt').a
141
105
  assert_equal_s('a',f.outputmode?)
data/test/tc/null.rb ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/local/bin/ruby
2
+ if $0 == __FILE__
3
+ Dir.chdir File.dirname(__FILE__)+'/../'
4
+ $:.unshift File.expand_path('../lib/')
5
+ end
6
+
7
+ require 'rio'
8
+ require 'tc/testcase'
9
+
10
+ class TC_null < Test::RIO::TestCase
11
+ @@once = false
12
+ def self.once
13
+ @@once = true
14
+ end
15
+ def setup
16
+ super
17
+ self.class.once unless @@once
18
+ end
19
+ def compare_rtn(sym,*args)
20
+ r1 = rio('/dev/null')
21
+ r2 = rio(nil)
22
+ rtn1 = r1.__send__(sym,*args)
23
+ rtn2 = r2.__send__(sym,*args)
24
+ assert_equal(rtn1,rtn2)
25
+ end
26
+
27
+ def compare_raiseeof(sym,*args)
28
+ r1 = rio('/dev/null')
29
+ r2 = rio(nil)
30
+ assert_raise(EOFError) { r1.__send__(sym,*args) }
31
+ assert_raise(EOFError) { r2.__send__(sym,*args) }
32
+ end
33
+
34
+ def test_gets() compare_rtn(:gets) end
35
+ def test_lineno() compare_rtn(:lineno) end
36
+ def test_lineno_assign() compare_rtn(:lineno=,20) end
37
+ def test_pos() compare_rtn(:pos) end
38
+ def test_pos_assign() compare_rtn(:pos=,20) end
39
+ def test_read() compare_rtn(:read) end
40
+ def test_readl() compare_rtn(:read,1) end
41
+ def test_readline() compare_raiseeof(:readline) end
42
+ def test_readlines() compare_rtn(:readlines) end
43
+ def test_readchar() compare_raiseeof(:readchar) end
44
+
45
+ end
data/test/tc/pid.rb ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/local/bin/ruby
2
+ if $0 == __FILE__
3
+ Dir.chdir File.dirname(__FILE__)+'/../'
4
+ $:.unshift File.expand_path('../lib/')
5
+ end
6
+
7
+ require 'rio'
8
+ require 'tc/testcase'
9
+
10
+ class TC_pid < Test::RIO::TestCase
11
+ @@once = false
12
+ def self.once
13
+ @@once = true
14
+ end
15
+ def setup
16
+ super
17
+ end
18
+ def test_likeio
19
+ cmd = 'ruby -v'
20
+ ios = File.popen(cmd)
21
+ assert(ios.pid)
22
+ ios_lines = ios.readlines
23
+
24
+ ior = rio(?-,cmd)
25
+ assert(ior.pid)
26
+ ior_lines = ior.readlines
27
+
28
+ assert_equal(ios_lines,ior_lines)
29
+ end
30
+
31
+ end
data/test/tc/piper.rb CHANGED
@@ -13,6 +13,9 @@ class TC_piper < Test::RIO::TestCase
13
13
  @@dname = 'd'
14
14
  @@fnames = ['f0','f1','f2','g0','g1']
15
15
 
16
+ require 'tc/programs_util'
17
+ include Test::RIO::Programs
18
+
16
19
  def self.once
17
20
  @@once = true
18
21
  rio(@@dname).rmtree.mkpath.chdir {
@@ -39,64 +42,64 @@ class TC_piper < Test::RIO::TestCase
39
42
  end
40
43
 
41
44
  def test_cmd_out
42
- ls = rio(?-,'ls')
45
+ ls = rio(?-,PROG['list_dir'])
43
46
  checkit([@@dname],ls)
44
47
  end
45
48
 
46
49
  def test_cmd_out2
47
- ls = rio(?-,'ls d')
50
+ ls = rio(?-,PROG['list_dir']+' d')
48
51
  checkit(@@fnames,ls)
49
52
  end
50
53
 
51
54
  def test_cmd_cmd_out
52
- ls = rio(?-,'ls d')
53
- grep = rio(?-,'grep 1').w!
55
+ ls = rio(?-,PROG['list_dir']+' d')
56
+ grep = rio(?-,PROG['find_lines']+' 1').w!
54
57
  checkit(@@fnames.select { |s| s =~ /1/ },ls,grep)
55
58
  end
56
59
 
57
60
  def test_cmd_cmd_cmd_out
58
- ls = rio(?-,'ls d')
59
- grep = rio(?-,'grep 1').w!
60
- grep2 = rio(?-,'grep g').w!
61
+ ls = rio(?-,PROG['list_dir']+' d')
62
+ grep = rio(?-,PROG['find_lines']+' 1').w!
63
+ grep2 = rio(?-,PROG['find_lines']+' g').w!
61
64
  checkit(@@fnames.select { |s| s =~ /g1/ },ls,grep,grep2)
62
65
  end
63
66
 
64
67
  def test_cmd_cmd_cmd_cmd_out
65
- ls = rio(?-,'ls d')
66
- grep = rio(?-,'grep 1').w!
67
- grep2 = rio(?-,'grep g').w!
68
- wc = rio(?-,'wc -l').w!
68
+ ls = rio(?-,PROG['list_dir']+' d')
69
+ grep = rio(?-,PROG['find_lines']+' 1').w!
70
+ grep2 = rio(?-,PROG['find_lines']+' g').w!
71
+ wc = rio(?-,PROG['count_lines']).w!
69
72
 
70
73
  checkit(["1"],ls,grep,grep2,wc)
71
74
  end
72
75
  def test_piper_out
73
- ls = rio(?-,'ls d')
74
- grep = rio(?-,'grep 1').w!
76
+ ls = rio(?-,PROG['list_dir']+' d')
77
+ grep = rio(?-,PROG['find_lines']+' 1').w!
75
78
  rp1 = RIO::Piper::Base.new(ls,grep)
76
79
  checkit(@@fnames.select { |s| s =~ /1/ },rp1)
77
80
  end
78
81
 
79
82
  def test_piper_cmd_out
80
- ls = rio(?-,'ls d')
81
- grep = rio(?-,'grep 1').w!
83
+ ls = rio(?-,PROG['list_dir']+' d')
84
+ grep = rio(?-,PROG['find_lines']+' 1').w!
82
85
  rp1 = RIO::Piper::Base.new(ls,grep)
83
- grep2 = rio(?-,'grep g').w!
86
+ grep2 = rio(?-,PROG['find_lines']+' g').w!
84
87
  checkit(@@fnames.select { |s| s =~ /g1/ },rp1,grep2)
85
88
  end
86
89
 
87
90
  def test_cmd_piper_out
88
- ls = rio(?-,'ls d')
89
- grep = rio(?-,'grep 1').w!
90
- grep2 = rio(?-,'grep g').w!
91
+ ls = rio(?-,PROG['list_dir']+' d')
92
+ grep = rio(?-,PROG['find_lines']+' 1').w!
93
+ grep2 = rio(?-,PROG['find_lines']+' g').w!
91
94
  rp1 = RIO::Piper::Base.new(grep,grep2)
92
95
  checkit(@@fnames.select { |s| s =~ /g1/ },ls,rp1)
93
96
  end
94
97
 
95
98
  def test_piper_piper_out
96
- ls = rio(?-,'ls d')
97
- grep = rio(?-,'grep 1').w!
98
- grep2 = rio(?-,'grep g').w!
99
- wc = rio(?-,'wc -l').w!
99
+ ls = rio(?-,PROG['list_dir']+' d')
100
+ grep = rio(?-,PROG['find_lines']+' 1').w!
101
+ grep2 = rio(?-,PROG['find_lines']+' g').w!
102
+ wc = rio(?-,PROG['count_lines']).w!
100
103
  rp1 = RIO::Piper::Base.new(ls,grep)
101
104
  rp2 = RIO::Piper::Base.new(grep2,wc)
102
105
  checkit(["1"],rp1,rp2)
@@ -109,36 +112,30 @@ class TC_piper < Test::RIO::TestCase
109
112
 
110
113
  def test_file_cmd_out
111
114
  f = rio('d/f2')
112
- grep = rio(?-,'grep 2').w!
115
+ grep = rio(?-,PROG['find_lines']+' 2').w!
113
116
  checkit(rio('d/f2').chomp[/2/],f,grep)
114
117
  end
115
118
 
116
119
  def test_file_cmd_cmd_out
117
120
  f = rio('d/f2')
118
- grep = rio(?-,'grep 2').w!
119
- grep2 = rio(?-,'grep 0').w!
121
+ grep = rio(?-,PROG['find_lines']+' 2').w!
122
+ grep2 = rio(?-,PROG['find_lines']+' 0').w!
120
123
  checkit(rio('d/f2').chomp[/0/],f,grep,grep2)
121
124
  end
122
125
 
123
126
  def test_file_cmd_cmd_cmd_out
124
127
  f = rio('d/f2')
125
- grep = rio(?-,'grep 2').w!
126
- grep2 = rio(?-,'grep 0').w!
127
- wc = rio(?-,'wc -l').w!
128
+ grep = rio(?-,PROG['find_lines']+' 2').w!
129
+ grep2 = rio(?-,PROG['find_lines']+' 0').w!
130
+ wc = rio(?-,PROG['count_lines']).w!
128
131
  checkit(["1"],f,grep,grep2,wc)
129
132
  end
130
133
 
131
- def test_piper_out
132
- ls = rio(?-,'ls d')
133
- grep = rio(?-,'grep 1').w!
134
- rp1 = RIO::Piper::Base.new(ls,grep)
135
- checkit(@@fnames.select { |s| s =~ /1/ },rp1)
136
- end
137
134
 
138
135
  def test_file_piper_out
139
136
  f = rio('d/f2')
140
- grep = rio(?-,'grep 2').w!
141
- grep2 = rio(?-,'grep 0').w!
137
+ grep = rio(?-,PROG['find_lines']+' 2').w!
138
+ grep2 = rio(?-,PROG['find_lines']+' 0').w!
142
139
  rp1 = RIO::Piper::Base.new(grep,grep2)
143
140
  checkit(rio('d/f2').chomp[/0/],f,rp1)
144
141
  end
@@ -0,0 +1,24 @@
1
+
2
+ module Test
3
+ module RIO
4
+ module Programs
5
+ TEST_BIN_DIR = File.expand_path(Dir.pwd+'/bin')
6
+
7
+ XPROGS = {
8
+ 'count_lines' => 'wc -l',
9
+ 'find_lines' => 'grep',
10
+ 'list_dir' => 'ls',
11
+ }
12
+ RPROGS = {
13
+ 'count_lines' => "ruby #{TEST_BIN_DIR}/count_lines.rb",
14
+ 'find_lines' => "ruby #{TEST_BIN_DIR}/find_lines.rb",
15
+ 'list_dir' => "ruby #{TEST_BIN_DIR}/list_dir.rb",
16
+ }
17
+ PROG = {
18
+ 'count_lines' => XPROGS['count_lines'],
19
+ 'find_lines' => XPROGS['find_lines'],
20
+ 'list_dir' => XPROGS['list_dir'],
21
+ }
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,30 @@
1
+ #!/usr/local/bin/ruby
2
+ if $0 == __FILE__
3
+ Dir.chdir File.dirname(__FILE__)+'/../'
4
+ $:.unshift File.expand_path('../lib/')
5
+ end
6
+
7
+ require 'rio'
8
+ require 'tc/testcase'
9
+
10
+ class TC_readline < Test::RIO::TestCase
11
+ @@once = false
12
+ def self.once
13
+ @@once = true
14
+ end
15
+ def setup
16
+ super
17
+ self.class.once unless @@once
18
+ end
19
+ def test_readline_like_IO
20
+ frio = rio('frio') < (0..1).map{ |i| "Line #{i}\n" }
21
+ rio('fruby') < frio
22
+ fruby = File.open('fruby');
23
+ assert_equal(fruby.readline,frio.readline)
24
+ assert_equal(fruby.readline,frio.readline)
25
+ assert_raise(EOFError) { fruby.readline }
26
+ assert_raise(EOFError) { frio.readline }
27
+
28
+
29
+ end
30
+ end
data/test/tc/rename.rb CHANGED
@@ -141,6 +141,18 @@ class TC_rename < Test::RIO::TestCase
141
141
  assert_array_equal(expf,rio('qdir').files[])
142
142
  assert_array_equal([],rio('tdir').files[])
143
143
 
144
+ end
145
+ def test_rename_dirname_deep
146
+ indir = rio('dir1/dir2/dir3/tdir').delete!.mkpath < rio(@d[1]).to_a
147
+ oldf = indir.files[].map { |f| f.to_s }
148
+ expf = oldf.map { |f| f.sub(indir.to_s,'shallow') }
149
+ rio('shallow').delete!.mkpath
150
+ indir.rename.files do |ent|
151
+ ent.dirname = 'shallow'
152
+ end
153
+ assert_array_equal(expf,rio('shallow').files[])
154
+ assert_array_equal([],rio(indir.to_s).files[])
155
+
144
156
  end
145
157
  def test_rename_basename_wext
146
158
  indir = rio('tdir').delete!.mkpath < rio(@d[1]).to_a
data/test/tc/tempfile.rb CHANGED
@@ -48,5 +48,19 @@ class TC_tempfile < Test::RIO::TestCase
48
48
  assert_equal(str,tmp.rewind.chomp.gets)
49
49
  end
50
50
 
51
+ def test_copy
52
+ str = "Hello World\n"
53
+
54
+ src = rio(?").print!(str)
55
+ ans = rio(?")
56
+
57
+ tmp = rio(??)
58
+ tmp < src
59
+ tmp.rewind
60
+ assert_equal(str,tmp.contents)
61
+ tmp.rewind
62
+ tmp > ans
63
+ assert_equal(str,ans.contents)
64
+ end
51
65
 
52
66
  end
data/test/tc/testcase.rb CHANGED
@@ -90,8 +90,10 @@ end
90
90
  module Test
91
91
  module RIO
92
92
  class TestCase < Unit::TestCase
93
+ include RIO_TestCase::Util
93
94
  def setup()
94
95
  return if self.class == Test::RIO::TestCase
96
+ #p self.class
95
97
  @cwd = ::Dir.getwd
96
98
  tdir.mkpath.chdir
97
99
  end
@@ -99,9 +101,13 @@ module Test
99
101
  return if self.class == Test::RIO::TestCase
100
102
  ::Dir.chdir @cwd
101
103
  end
104
+ def rios2str(a) a.map { |el| el.to_s } end
105
+
102
106
  def assert!(a,msg="negative assertion")
103
107
  assert((!(a)),msg)
104
108
  end
109
+
110
+ def smap(a) a.map { |el| el.to_s } end
105
111
  def assert_array_equal(a,b,msg="array same regardless of order")
106
112
  if a.nil?
107
113
  assert_nil(b)
data/test/tc/tonl.rb ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/local/bin/ruby
2
+ if $0 == __FILE__
3
+ Dir.chdir File.dirname(__FILE__)+'/../'
4
+ $:.unshift File.expand_path('../lib/')
5
+ end
6
+
7
+ require 'rio'
8
+ require 'tc/testcase'
9
+
10
+ class TC_tonl < Test::RIO::TestCase
11
+ @@once = false
12
+ CRNLFILE = 'hw.crnl.txt'
13
+ NLFILE = 'hw.nl.txt'
14
+ STR = "Hello World\r\n"
15
+ require 'tc/programs_util'
16
+ include Test::RIO::Programs
17
+
18
+ def self.once
19
+ @@once = true
20
+ rio(CRNLFILE) < STR * 2
21
+ end
22
+ def setup
23
+ super
24
+ self.class.once unless @@once
25
+ end
26
+
27
+ def test_1
28
+ out = rio.strio
29
+ rio(CRNLFILE) > out
30
+ lines = rio(CRNLFILE).to_a
31
+ assert_equal(13,lines[0].length)
32
+ rio(NLFILE) < rio(CRNLFILE).chomp.map{ |l| "#{l}\n" }
33
+ lines = rio(NLFILE).to_a
34
+ assert_equal(12,lines[0].length)
35
+ end
36
+
37
+ end