tb 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. data/README +62 -50
  2. data/bin/tb +22 -18
  3. data/lib/tb.rb +35 -19
  4. data/lib/tb/basic.rb +85 -86
  5. data/lib/tb/catreader.rb +33 -116
  6. data/lib/tb/cmd_cat.rb +31 -27
  7. data/lib/tb/cmd_consecutive.rb +45 -35
  8. data/lib/tb/cmd_crop.rb +86 -52
  9. data/lib/tb/cmd_cross.rb +113 -71
  10. data/lib/tb/cmd_cut.rb +49 -44
  11. data/lib/tb/cmd_git_log.rb +193 -0
  12. data/lib/tb/cmd_grep.rb +43 -32
  13. data/lib/tb/cmd_group.rb +63 -39
  14. data/lib/tb/cmd_gsub.rb +53 -43
  15. data/lib/tb/cmd_help.rb +51 -24
  16. data/lib/tb/cmd_join.rb +32 -35
  17. data/lib/tb/cmd_ls.rb +233 -205
  18. data/lib/tb/cmd_mheader.rb +47 -37
  19. data/lib/tb/cmd_nest.rb +94 -0
  20. data/lib/tb/cmd_newfield.rb +29 -33
  21. data/lib/tb/cmd_rename.rb +40 -32
  22. data/lib/tb/cmd_shape.rb +31 -24
  23. data/lib/tb/cmd_sort.rb +46 -25
  24. data/lib/tb/cmd_svn_log.rb +47 -28
  25. data/lib/tb/cmd_tar_tvf.rb +447 -0
  26. data/lib/tb/cmd_to_csv.rb +60 -0
  27. data/lib/tb/cmd_to_json.rb +60 -0
  28. data/lib/tb/cmd_to_pnm.rb +48 -0
  29. data/lib/tb/cmd_to_pp.rb +71 -0
  30. data/lib/tb/cmd_to_tsv.rb +48 -0
  31. data/lib/tb/cmd_to_yaml.rb +52 -0
  32. data/lib/tb/cmd_unnest.rb +118 -0
  33. data/lib/tb/cmdmain.rb +24 -20
  34. data/lib/tb/cmdtop.rb +33 -25
  35. data/lib/tb/cmdutil.rb +26 -66
  36. data/lib/tb/csv.rb +46 -34
  37. data/lib/tb/enum.rb +294 -0
  38. data/lib/tb/enumerable.rb +198 -7
  39. data/lib/tb/enumerator.rb +73 -0
  40. data/lib/tb/fieldset.rb +27 -19
  41. data/lib/tb/fileenumerator.rb +365 -0
  42. data/lib/tb/json.rb +50 -0
  43. data/lib/tb/pager.rb +6 -6
  44. data/lib/tb/pairs.rb +227 -0
  45. data/lib/tb/pnm.rb +23 -22
  46. data/lib/tb/reader.rb +52 -49
  47. data/lib/tb/record.rb +48 -19
  48. data/lib/tb/revcmp.rb +38 -0
  49. data/lib/tb/ropen.rb +74 -57
  50. data/lib/tb/search.rb +25 -21
  51. data/lib/tb/tsv.rb +31 -34
  52. data/sample/excel2csv +24 -20
  53. data/sample/poi-xls2csv.rb +24 -20
  54. data/sample/poi-xls2csv.sh +22 -18
  55. data/sample/tbplot +185 -127
  56. data/test-all-cov.rb +3 -3
  57. data/test-all.rb +1 -1
  58. data/test/test_basic.rb +26 -10
  59. data/test/test_catreader.rb +7 -6
  60. data/test/test_cmd_cat.rb +32 -0
  61. data/test/test_cmd_consecutive.rb +10 -0
  62. data/test/test_cmd_crop.rb +4 -4
  63. data/test/test_cmd_cross.rb +16 -4
  64. data/test/test_cmd_git_log.rb +46 -0
  65. data/test/test_cmd_help.rb +17 -12
  66. data/test/test_cmd_join.rb +21 -1
  67. data/test/test_cmd_ls.rb +3 -4
  68. data/test/test_cmd_mheader.rb +17 -11
  69. data/test/test_cmd_nest.rb +49 -0
  70. data/test/test_cmd_sort.rb +15 -0
  71. data/test/test_cmd_tar_tvf.rb +281 -0
  72. data/test/{test_cmd_csv.rb → test_cmd_to_csv.rb} +35 -21
  73. data/test/{test_cmd_json.rb → test_cmd_to_json.rb} +31 -3
  74. data/test/{test_cmd_pnm.rb → test_cmd_to_pnm.rb} +2 -2
  75. data/test/{test_cmd_pp.rb → test_cmd_to_pp.rb} +4 -4
  76. data/test/{test_cmd_tsv.rb → test_cmd_to_tsv.rb} +4 -4
  77. data/test/{test_cmd_yaml.rb → test_cmd_to_yaml.rb} +3 -3
  78. data/test/test_cmd_unnest.rb +89 -0
  79. data/test/test_cmdtty.rb +19 -13
  80. data/test/test_enumerable.rb +83 -1
  81. data/test/test_fileenumerator.rb +265 -0
  82. data/test/test_json.rb +15 -0
  83. data/test/test_pager.rb +3 -4
  84. data/test/test_pairs.rb +122 -0
  85. data/test/test_pnm.rb +24 -24
  86. data/test/test_reader.rb +35 -13
  87. data/test/test_revcmp.rb +10 -0
  88. data/test/test_tbenum.rb +173 -0
  89. metadata +51 -23
  90. data/lib/tb/cmd_csv.rb +0 -42
  91. data/lib/tb/cmd_json.rb +0 -60
  92. data/lib/tb/cmd_pnm.rb +0 -43
  93. data/lib/tb/cmd_pp.rb +0 -70
  94. data/lib/tb/cmd_tsv.rb +0 -43
  95. data/lib/tb/cmd_yaml.rb +0 -47
@@ -0,0 +1,49 @@
1
+ require 'test/unit'
2
+ require 'tb/cmdtop'
3
+ require 'tmpdir'
4
+
5
+ class TestTbCmdNest < Test::Unit::TestCase
6
+ def setup
7
+ Tb::Cmd.reset_option
8
+ @curdir = Dir.pwd
9
+ @tmpdir = Dir.mktmpdir
10
+ Dir.chdir @tmpdir
11
+ end
12
+ def teardown
13
+ Tb::Cmd.reset_option
14
+ Dir.chdir @curdir
15
+ FileUtils.rmtree @tmpdir
16
+ end
17
+
18
+ def test_basic
19
+ File.open(i="i.csv", "w") {|f| f << <<-"End".gsub(/^[ \t]+/, '') }
20
+ a,b,c
21
+ 0,1,2
22
+ 0,3,4
23
+ 4,5,6
24
+ End
25
+ Tb::Cmd.main_nest(['-o', o="o.csv", 'z,b,c', i])
26
+ assert_equal(<<-"End".gsub(/^[ \t]+/, ''), File.read(o))
27
+ a,z
28
+ 0,"b,c
29
+ 1,2
30
+ 3,4
31
+ "
32
+ 4,"b,c
33
+ 5,6
34
+ "
35
+ End
36
+ end
37
+
38
+ def test_field_not_found
39
+ File.open(i="i.csv", "w") {|f| f << <<-"End".gsub(/^[ \t]+/, '') }
40
+ a,b,c
41
+ 0,1,2
42
+ 0,3,4
43
+ 4,5,6
44
+ End
45
+ exc = assert_raise(SystemExit) { Tb::Cmd.main_nest(['-o', "o.csv", 'z,b,d', i]) }
46
+ assert(!exc.success?)
47
+ end
48
+
49
+ end
@@ -102,4 +102,19 @@ class TestTbCmdSort < Test::Unit::TestCase
102
102
  End
103
103
  end
104
104
 
105
+ def test_reverse
106
+ File.open(i="i.csv", "w") {|f| f << <<-"End".gsub(/^[ \t]+/, '') }
107
+ a,b
108
+ 1,4
109
+ 0,3
110
+ 3,2
111
+ End
112
+ Tb::Cmd.main_sort(['-o', o="o.csv", '-r', i])
113
+ assert_equal(<<-"End".gsub(/^[ \t]+/, ''), File.read(o))
114
+ a,b
115
+ 3,2
116
+ 1,4
117
+ 0,3
118
+ End
119
+ end
105
120
  end
@@ -0,0 +1,281 @@
1
+ require 'test/unit'
2
+ require 'tb/cmdtop'
3
+ require 'tmpdir'
4
+
5
+ class TestTbCmdTarTvf < Test::Unit::TestCase
6
+ def setup
7
+ Tb::Cmd.reset_option
8
+ @curdir = Dir.pwd
9
+ @tmpdir = Dir.mktmpdir
10
+ Dir.chdir @tmpdir
11
+ end
12
+ def teardown
13
+ Tb::Cmd.reset_option
14
+ Dir.chdir @curdir
15
+ FileUtils.rmtree @tmpdir
16
+ end
17
+
18
+ def tar_with_format_option
19
+ return @@tar_with_format_option if defined? @@tar_with_format_option
20
+ commands = %w[tar gtar]
21
+ commands.each {|c|
22
+ msg = IO.popen("exec 2>&1; LC_ALL=C #{c} --help") {|f| f.read }
23
+ if / --format \{(.*)\}/ =~ msg # bsdtar 2.7.0 (FreeBSD 8.2)
24
+ format_desc = $1
25
+ formats = []
26
+ formats << 'ustar' if /\bustar\b/ =~ format_desc
27
+ formats << 'pax' if /\bpax\b/ =~ format_desc
28
+ @@tar_with_format_option = [c, formats]
29
+ return @@tar_with_format_option
30
+ elsif / --format=FORMAT / =~ msg # GNU tar 1.23
31
+ formats = []
32
+ formats << 'gnu' if /\bgnu\b.*\bformat\b/ =~ msg
33
+ formats << 'oldgnu' if /\boldgnu\b.*\bformat\b/ =~ msg
34
+ formats << 'pax' if /\bpax\b.*\bformat\b/ =~ msg
35
+ formats << 'ustar' if /\bustar\b.*\bformat\b/ =~ msg
36
+ formats << 'v7' if /\bv7\b.*\bformat\b/ =~ msg
37
+ @@tar_with_format_option = [c, formats]
38
+ return @@tar_with_format_option
39
+ end
40
+ }
41
+ @@tar_with_format_option = nil
42
+ end
43
+
44
+ def with_stdin(io)
45
+ save = $stdin
46
+ $stdin = io
47
+ begin
48
+ yield
49
+ ensure
50
+ $stdin = save
51
+ end
52
+ end
53
+
54
+ def test_basic
55
+ open('foo', 'w') {|f| }
56
+ assert(system('tar cf bar.tar foo'))
57
+ Tb::Cmd.main_tar_tvf(['-o', o='o.csv', 'bar.tar'])
58
+ assert_match(/,foo,/, File.read(o))
59
+ end
60
+
61
+ def test_stdin
62
+ open('foo', 'w') {|f| }
63
+ assert(system('tar cf bar.tar foo'))
64
+ o = nil
65
+ open('bar.tar') {|f|
66
+ with_stdin(f) {
67
+ Tb::Cmd.main_tar_tvf(['-o', o='o.csv'])
68
+ }
69
+ }
70
+ assert_match(/,foo,/, File.read(o))
71
+ end
72
+
73
+ def test_pipe_stdin
74
+ return unless Process.respond_to? :spawn
75
+ open('foo', 'w') {|f| }
76
+ assert(system('tar cf bar.tar foo'))
77
+ o = nil
78
+ IO.popen('cat bar.tar') {|f|
79
+ with_stdin(f) {
80
+ Tb::Cmd.main_tar_tvf(['-o', o='o.csv'])
81
+ }
82
+ }
83
+ assert_match(/,foo,/, File.read(o))
84
+ end
85
+
86
+ def test_gzip
87
+ return unless Process.respond_to? :spawn
88
+ open('foo', 'w') {|f| }
89
+ assert(system('tar cf bar.tar foo'))
90
+ assert(system('gzip bar.tar'))
91
+ Tb::Cmd.main_tar_tvf(['-o', o='o.csv', 'bar.tar.gz'])
92
+ assert_match(/,foo,/, File.read(o))
93
+ end
94
+
95
+ def test_gzip_stdin
96
+ return unless Process.respond_to? :spawn
97
+ open('foo', 'w') {|f| }
98
+ assert(system('tar cf bar.tar foo'))
99
+ assert(system('gzip bar.tar'))
100
+ o = nil
101
+ open('bar.tar.gz') {|f|
102
+ with_stdin(f) {
103
+ Tb::Cmd.main_tar_tvf(['-o', o='o.csv'])
104
+ }
105
+ }
106
+ assert_match(/,foo,/, File.read(o))
107
+ end
108
+
109
+ def test_gzip_pipe_stdin
110
+ return unless Process.respond_to? :spawn
111
+ open('foo', 'w') {|f| f << "oooo" }
112
+ assert(system('tar cf bar.tar foo'))
113
+ assert(system('gzip bar.tar'))
114
+ o = nil
115
+ IO.popen('cat bar.tar.gz') {|f|
116
+ with_stdin(f) {
117
+ Tb::Cmd.main_tar_tvf(['-o', o='o.csv'])
118
+ }
119
+ }
120
+ assert_match(/,foo,/, File.read(o))
121
+ end
122
+
123
+ def test_directory
124
+ Dir.mkdir("d")
125
+ open('d/foo', 'w') {|f| f << "hahaha" }
126
+ assert(system('tar cf bar.tar d'))
127
+ Tb::Cmd.main_tar_tvf(['-o', o='o.csv', '-l', 'bar.tar'])
128
+ result = File.read(o)
129
+ assert_match(%r{,d/,}, result)
130
+ assert_match(%r{,d/foo,}, result)
131
+ end
132
+
133
+ def test_hardlink
134
+ open('foo', 'w') {|f| f << "hahaha" }
135
+ File.link('foo', 'baz')
136
+ assert(system('tar cf bar.tar foo baz'))
137
+ Tb::Cmd.main_tar_tvf(['-o', o='o.csv', '-l', 'bar.tar'])
138
+ result = File.read(o)
139
+ assert_match(/,foo,/, result)
140
+ assert_match(/,h/, result)
141
+ assert_match(/,baz,foo,/, result)
142
+ end
143
+
144
+ def test_ustar_longpath
145
+ return unless tar_and_formats = tar_with_format_option
146
+ name = 'ABC' + 'a' * 90 + 'DEF/GHI' + 'b' * 90 + 'IJK'
147
+ Dir.mkdir(File.dirname(name))
148
+ open(name, 'w') {|f| }
149
+ %w[ustar gnu oldgnu pax].each {|format|
150
+ next unless tar_and_formats.last.include? format
151
+ tar = tar_and_formats.first
152
+ assert(system("#{tar} cf bar.tar --format=#{format} #{name}"))
153
+ Tb::Cmd.main_tar_tvf(['-o', o='o.csv', '-l', 'bar.tar'])
154
+ result = File.read(o)
155
+ assert_equal(2, result.count("\n"), "tar format: #{format}")
156
+ assert_match(/,#{name},/, result)
157
+ }
158
+ end
159
+
160
+ def test_ext_longname
161
+ return unless tar_and_formats = tar_with_format_option
162
+ name = 'ABC' + 'a' * 200 + 'XYZ'
163
+ open(name, 'w') {|f| }
164
+ %w[gnu oldgnu pax].each {|format|
165
+ next unless tar_and_formats.last.include? format
166
+ tar = tar_and_formats.first
167
+ assert(system("#{tar} cf bar.tar --format=#{format} #{name}"))
168
+ Tb::Cmd.main_tar_tvf(['-o', o='o.csv', '-l', 'bar.tar'])
169
+ result = File.read(o)
170
+ assert_equal(2, result.count("\n"), "tar format: #{format}")
171
+ assert_match(/,#{name},/, result)
172
+ }
173
+ end
174
+
175
+ def test_ext_longlink
176
+ return unless tar_and_formats = tar_with_format_option
177
+ link = 'ABC' + 'a' * 200 + 'XYZ'
178
+ File.symlink(link, 'foo')
179
+ %w[gnu oldgnu pax].each {|format|
180
+ next unless tar_and_formats.last.include? format
181
+ tar = tar_and_formats.first
182
+ assert(system("#{tar} cf bar.tar --format=#{format} foo"))
183
+ Tb::Cmd.main_tar_tvf(['-o', o='o.csv', '-l', 'bar.tar'])
184
+ result = File.read(o)
185
+ assert_equal(2, result.count("\n"), "tar format: #{format}")
186
+ assert_match(/,#{link},/, result)
187
+ }
188
+ end
189
+
190
+ def test_ext_longname_and_longlink
191
+ return unless tar_and_formats = tar_with_format_option
192
+ name = 'ABC' + 'a' * 200 + 'XYZ'
193
+ link = 'ABC' + 'b' * 200 + 'XYZ'
194
+ File.symlink(link, name)
195
+ %w[gnu oldgnu pax].each {|format|
196
+ next unless tar_and_formats.last.include? format
197
+ tar = tar_and_formats.first
198
+ assert(system("#{tar} cf bar.tar --format=#{format} #{name}"))
199
+ Tb::Cmd.main_tar_tvf(['-o', o='o.csv', '-l', 'bar.tar'])
200
+ result = File.read(o)
201
+ assert_equal(2, result.count("\n"))
202
+ assert_match(/,#{name},/, result)
203
+ assert_match(/,#{link},/, result)
204
+ }
205
+ end
206
+
207
+ def test_mtime
208
+ return unless tar_and_formats = tar_with_format_option
209
+ name = 'foo'
210
+ open(name, 'w') {|f| }
211
+ mtime_from_epoch = 730479600
212
+ mtime = Time.at(mtime_from_epoch)
213
+ File.utime(0, mtime, name)
214
+ %w[v7 ustar oldgnu gnu pax].each {|format|
215
+ next unless tar_and_formats.last.include? format
216
+ tar = tar_and_formats.first
217
+ assert(system("#{tar} cf bar.tar --format=#{format} #{name}"))
218
+ Tb::Cmd.main_tar_tvf(['-o', o='o.csv', '-l', 'bar.tar'])
219
+ result = File.read(o)
220
+ assert_equal(2, result.count("\n"), "tar format: #{format}")
221
+ assert_match(/,#{Regexp.escape mtime.iso8601(9)},/, result, "tar format: #{format}")
222
+ }
223
+ end
224
+
225
+ def test_atime
226
+ return unless tar_and_formats = tar_with_format_option
227
+ name = 'foo'
228
+ open(name, 'w') {|f| }
229
+ atime_from_epoch = 730479600
230
+ atime = Time.at(atime_from_epoch)
231
+ File.utime(atime, 0, name)
232
+ %w[pax].each {|format|
233
+ next unless tar_and_formats.last.include? format
234
+ tar = tar_and_formats.first
235
+ assert(system("#{tar} cf bar.tar --format=#{format} #{name}"))
236
+ Tb::Cmd.main_tar_tvf(['-o', o='o.csv', '-l', 'bar.tar'])
237
+ result = File.read(o)
238
+ assert_equal(2, result.count("\n"), "tar format: #{format}")
239
+ assert_match(/,#{Regexp.escape atime.iso8601(9)},/, result, "tar format: #{format}")
240
+ }
241
+ end
242
+
243
+ def test_mtime_subsec
244
+ return unless tar_and_formats = tar_with_format_option
245
+ name = 'foo'
246
+ open(name, 'w') {|f| }
247
+ mtime_from_epoch = 730479600
248
+ mtime = Time.at(mtime_from_epoch, 100000)
249
+ File.utime(0, mtime, name)
250
+ return if File.stat(name).mtime.usec != 100000
251
+ %w[pax].each {|format|
252
+ next unless tar_and_formats.last.include? format
253
+ tar = tar_and_formats.first
254
+ assert(system("#{tar} cf bar.tar --format=#{format} #{name}"))
255
+ Tb::Cmd.main_tar_tvf(['-o', o='o.csv', '-l', 'bar.tar'])
256
+ result = File.read(o)
257
+ assert_equal(2, result.count("\n"), "tar format: #{format}")
258
+ assert_match(/,#{Regexp.escape mtime.iso8601(9)},/, result, "tar format: #{format}")
259
+ }
260
+ end
261
+
262
+ def test_atime_subsec
263
+ return unless tar_and_formats = tar_with_format_option
264
+ name = 'foo'
265
+ open(name, 'w') {|f| }
266
+ atime_from_epoch = 730479600
267
+ atime = Time.at(atime_from_epoch, 100000)
268
+ File.utime(atime, 0, name)
269
+ return if File.stat(name).atime.usec != 100000
270
+ %w[pax].each {|format|
271
+ next unless tar_and_formats.last.include? format
272
+ tar = tar_and_formats.first
273
+ assert(system("#{tar} cf bar.tar --format=#{format} #{name}"))
274
+ Tb::Cmd.main_tar_tvf(['-o', o='o.csv', '-l', 'bar.tar'])
275
+ result = File.read(o)
276
+ assert_equal(2, result.count("\n"), "tar format: #{format}")
277
+ assert_match(/,#{Regexp.escape atime.iso8601(9)},/, result, "tar format: #{format}")
278
+ }
279
+ end
280
+
281
+ end
@@ -2,7 +2,7 @@ require 'test/unit'
2
2
  require 'tb/cmdtop'
3
3
  require 'tmpdir'
4
4
 
5
- class TestTbCmdCSV < Test::Unit::TestCase
5
+ class TestTbCmdToCSV < Test::Unit::TestCase
6
6
  def setup
7
7
  Tb::Cmd.reset_option
8
8
  @curdir = Dir.pwd
@@ -15,13 +15,33 @@ class TestTbCmdCSV < Test::Unit::TestCase
15
15
  FileUtils.rmtree @tmpdir
16
16
  end
17
17
 
18
+ def with_stdin(io)
19
+ save = $stdin
20
+ $stdin = io
21
+ begin
22
+ yield
23
+ ensure
24
+ $stdin = save
25
+ end
26
+ end
27
+
28
+ def with_stdout(io)
29
+ save = $stdout
30
+ $stdout = io
31
+ begin
32
+ yield
33
+ ensure
34
+ $stdout = save
35
+ end
36
+ end
37
+
18
38
  def test_basic
19
39
  File.open(i="i.tsv", "w") {|f| f << <<-"End".gsub(/^[ \t]+/, '') }
20
40
  a\tb\tc
21
41
  0\t1\t2
22
42
  4\t5\t6
23
43
  End
24
- Tb::Cmd.main_csv(['-o', o="o.csv", i])
44
+ Tb::Cmd.main_to_csv(['-o', o="o.csv", i])
25
45
  assert_equal(<<-"End".gsub(/^[ \t]+/, ''), File.read(o))
26
46
  a,b,c
27
47
  0,1,2
@@ -35,7 +55,7 @@ class TestTbCmdCSV < Test::Unit::TestCase
35
55
  0,1,2
36
56
  4,5,6
37
57
  End
38
- Tb::Cmd.main_csv(['-o', o="o.csv", i])
58
+ Tb::Cmd.main_to_csv(['-o', o="o.csv", i])
39
59
  assert_equal(<<-"End".gsub(/^[ \t]+/, ''), File.read(o))
40
60
  a,b,1
41
61
  0,1,2
@@ -49,7 +69,7 @@ class TestTbCmdCSV < Test::Unit::TestCase
49
69
  0,1,2
50
70
  4,5,6
51
71
  End
52
- Tb::Cmd.main_csv(['-o', o="o.csv", '-N', i])
72
+ Tb::Cmd.main_to_csv(['-o', o="o.csv", '-N', i])
53
73
  assert_equal(<<-"End".gsub(/^[ \t]+/, ''), File.read(o))
54
74
  a,,
55
75
  0,1,2
@@ -63,20 +83,17 @@ class TestTbCmdCSV < Test::Unit::TestCase
63
83
  0,1,2
64
84
  4,5,6
65
85
  End
66
- save = STDIN.dup
67
- input = File.open(i)
68
- STDIN.reopen(input)
69
- Tb::Cmd.main_csv(['-o', o="o.csv"])
70
- STDIN.reopen(save)
71
- save.close
86
+ o = nil
87
+ File.open(i) {|input|
88
+ with_stdin(input) {
89
+ Tb::Cmd.main_to_csv(['-o', o="o.csv"])
90
+ }
91
+ }
72
92
  assert_equal(<<-"End".gsub(/^[ \t]+/, ''), File.read(o))
73
93
  a,b,c
74
94
  0,1,2
75
95
  4,5,6
76
96
  End
77
- ensure
78
- save.close if save && !save.closed?
79
- input.close if input && !input.closed?
80
97
  end
81
98
 
82
99
  def test_pipeout
@@ -87,12 +104,10 @@ class TestTbCmdCSV < Test::Unit::TestCase
87
104
  End
88
105
  r, w = IO.pipe
89
106
  th = Thread.new { r.read }
90
- save = STDOUT.dup
91
- STDOUT.reopen(w)
92
- w.close
93
- Tb::Cmd.main_csv([i])
94
- STDOUT.reopen(save)
95
- save.close
107
+ with_stdout(w) {
108
+ Tb::Cmd.main_to_csv([i])
109
+ w.close
110
+ }
96
111
  result = th.value
97
112
  assert_equal(<<-"End".gsub(/^[ \t]+/, ''), result)
98
113
  a,b,c
@@ -102,7 +117,6 @@ class TestTbCmdCSV < Test::Unit::TestCase
102
117
  ensure
103
118
  r.close if r && !r.closed?
104
119
  w.close if w && !w.closed?
105
- save.close if save && !save.closed?
106
120
  end
107
121
 
108
122
  def test_twofile
@@ -116,7 +130,7 @@ class TestTbCmdCSV < Test::Unit::TestCase
116
130
  5,6
117
131
  7,8
118
132
  End
119
- Tb::Cmd.main_csv(['-o', o="o.csv", i1, i2])
133
+ Tb::Cmd.main_to_csv(['-o', o="o.csv", i1, i2])
120
134
  assert_equal(<<-"End".gsub(/^[ \t]+/, ''), File.read(o))
121
135
  a,b
122
136
  1,2