@@ -7,23 +7,27 @@ class YouPlotCommandTest < Test::Unit::TestCase
77 class << self
88 def startup
99 @stdin = $stdin. dup
10+ @stdout = $stdout. dup
1011 @stderr = $stderr. dup
1112 end
1213
1314 def shutdown
1415 $stdin = @stdin
16+ $stdout = @stdout
1517 $stderr = @stderr
1618 end
1719 end
1820
1921 def setup
2022 $stdin = File . open ( File . expand_path ( '../fixtures/iris.csv' , __dir__ ) , 'r' )
21- @tmp_file = Tempfile . new
22- $stderr = @tmp_file
23+ @stderr_file = Tempfile . new
24+ @stdout_file = Tempfile . new
25+ $stderr = @stderr_file
26+ $stdout = @stdout_file
2327 end
2428
2529 def teardown
26- @tmp_file . close
30+ @stderr_file . close
2731 end
2832
2933 def fixture ( fname )
@@ -32,71 +36,82 @@ def fixture(fname)
3236
3337 test :bar do
3438 YouPlot ::Command . new ( [ 'bar' , '-H' , '-d,' , '-t' , 'IRIS-BARPLOT' ] ) . run
35- assert_equal fixture ( 'iris-barplot.txt' ) , @tmp_file . read
39+ assert_equal fixture ( 'iris-barplot.txt' ) , @stderr_file . read
3640 end
3741
3842 test :barplot do
3943 YouPlot ::Command . new ( [ 'barplot' , '-H' , '-d,' , '-t' , 'IRIS-BARPLOT' ] ) . run
40- assert_equal fixture ( 'iris-barplot.txt' ) , @tmp_file . read
44+ assert_equal fixture ( 'iris-barplot.txt' ) , @stderr_file . read
4145 end
4246
4347 test :hist do
4448 YouPlot ::Command . new ( [ 'hist' , '-H' , '-d,' , '-t' , 'IRIS-HISTOGRAM' ] ) . run
45- assert_equal fixture ( 'iris-histogram.txt' ) , @tmp_file . read
49+ assert_equal fixture ( 'iris-histogram.txt' ) , @stderr_file . read
4650 end
4751
4852 test :histogram do
4953 YouPlot ::Command . new ( [ 'histogram' , '-H' , '-d,' , '-t' , 'IRIS-HISTOGRAM' ] ) . run
50- assert_equal fixture ( 'iris-histogram.txt' ) , @tmp_file . read
54+ assert_equal fixture ( 'iris-histogram.txt' ) , @stderr_file . read
5155 end
5256
5357 test :line do
5458 YouPlot ::Command . new ( [ 'line' , '-H' , '-d,' , '-t' , 'IRIS-LINEPLOT' ] ) . run
55- assert_equal fixture ( 'iris-lineplot.txt' ) , @tmp_file . read
59+ assert_equal fixture ( 'iris-lineplot.txt' ) , @stderr_file . read
5660 end
5761
5862 test :lineplot do
5963 YouPlot ::Command . new ( [ 'lineplot' , '-H' , '-d,' , '-t' , 'IRIS-LINEPLOT' ] ) . run
60- assert_equal fixture ( 'iris-lineplot.txt' ) , @tmp_file . read
64+ assert_equal fixture ( 'iris-lineplot.txt' ) , @stderr_file . read
6165 end
6266
6367 test :lines do
6468 YouPlot ::Command . new ( [ 'lines' , '-H' , '-d,' , '-t' , 'IRIS-LINEPLOTS' ] ) . run
65- assert_equal fixture ( 'iris-lineplots.txt' ) , @tmp_file . read
69+ assert_equal fixture ( 'iris-lineplots.txt' ) , @stderr_file . read
6670 end
6771
6872 test :lineplots do
6973 YouPlot ::Command . new ( [ 'lineplots' , '-H' , '-d,' , '-t' , 'IRIS-LINEPLOTS' ] ) . run
70- assert_equal fixture ( 'iris-lineplots.txt' ) , @tmp_file . read
74+ assert_equal fixture ( 'iris-lineplots.txt' ) , @stderr_file . read
7175 end
7276
7377 test :s do
7478 YouPlot ::Command . new ( [ 's' , '-H' , '-d,' , '-t' , 'IRIS-SCATTER' ] ) . run
75- assert_equal fixture ( 'iris-scatter.txt' ) , @tmp_file . read
79+ assert_equal fixture ( 'iris-scatter.txt' ) , @stderr_file . read
7680 end
7781
7882 test :scatter do
7983 YouPlot ::Command . new ( [ 'scatter' , '-H' , '-d,' , '-t' , 'IRIS-SCATTER' ] ) . run
80- assert_equal fixture ( 'iris-scatter.txt' ) , @tmp_file . read
84+ assert_equal fixture ( 'iris-scatter.txt' ) , @stderr_file . read
8185 end
8286
8387 test :d do
8488 YouPlot ::Command . new ( [ 'd' , '-H' , '-d,' , '-t' , 'IRIS-DENSITY' ] ) . run
85- assert_equal fixture ( 'iris-density.txt' ) , @tmp_file . read
89+ assert_equal fixture ( 'iris-density.txt' ) , @stderr_file . read
8690 end
8791
8892 test :density do
8993 YouPlot ::Command . new ( [ 'density' , '-H' , '-d,' , '-t' , 'IRIS-DENSITY' ] ) . run
90- assert_equal fixture ( 'iris-density.txt' ) , @tmp_file . read
94+ assert_equal fixture ( 'iris-density.txt' ) , @stderr_file . read
9195 end
9296
9397 test :box do
9498 YouPlot ::Command . new ( [ 'box' , '-H' , '-d,' , '-t' , 'IRIS-BOXPLOT' ] ) . run
95- assert_equal fixture ( 'iris-boxplot.txt' ) , @tmp_file . read
99+ assert_equal fixture ( 'iris-boxplot.txt' ) , @stderr_file . read
96100 end
97101
98102 test :boxplot do
99103 YouPlot ::Command . new ( [ 'boxplot' , '-H' , '-d,' , '-t' , 'IRIS-BOXPLOT' ] ) . run
100- assert_equal fixture ( 'iris-boxplot.txt' ) , @tmp_file . read
104+ assert_equal fixture ( 'iris-boxplot.txt' ) , @stderr_file . read
105+ end
106+
107+ test :plot_output_stdout do
108+ YouPlot ::Command . new ( [ 'bar' , '-o' , '-H' , '-d,' , '-t' , 'IRIS-BARPLOT' ] ) . run
109+ assert_equal "" , @stderr_file . read
110+ end
111+
112+ test :data_output_stdout do
113+ YouPlot ::Command . new ( [ 'bar' , '-O' , '-H' , '-d,' , '-t' , 'IRIS-BARPLOT' ] ) . run
114+ assert_equal fixture ( 'iris-barplot.txt' ) , @stderr_file . read
115+ assert_equal File . read ( File . expand_path ( '../fixtures/iris.csv' , __dir__ ) ) , @stdout_file . read
101116 end
102117end
0 commit comments