mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-05-05 22:31:11 +08:00
Changes the default value to stdout if no argument is specified with the -o
option
#9
This commit is contained in:
parent
b368dc44b4
commit
1b666038bb
@ -35,12 +35,13 @@ module YouPlot
|
||||
opt.on_tail('') # Add a blank line at the end
|
||||
opt.separator('')
|
||||
opt.on('Common options:')
|
||||
opt.on('-O', '--pass [VAL]', 'file to output standard input data to [stdout]',
|
||||
opt.on('-O', '--pass [FILE]', 'file to output input data to [stdout]',
|
||||
'for inserting YouPlot in the middle of Unix pipes') do |v|
|
||||
@options[:pass] = v || $stdout
|
||||
end
|
||||
opt.on('-o', '--output VAL', 'file to output results to [stderr]') do |v|
|
||||
@options[:output] = v
|
||||
opt.on('-o', '--output [FILE]', 'file to output plots to [stdout]',
|
||||
'If no option is specified, plot will print to stderr') do |v|
|
||||
@options[:output] = v || $stdout
|
||||
end
|
||||
opt.on('-d', '--delimiter VAL', String, 'use DELIM instead of TAB for field delimiter') do |v|
|
||||
@options[:delimiter] = v
|
||||
|
@ -7,23 +7,27 @@ class YouPlotCommandTest < Test::Unit::TestCase
|
||||
class << self
|
||||
def startup
|
||||
@stdin = $stdin.dup
|
||||
@stdout = $stdout.dup
|
||||
@stderr = $stderr.dup
|
||||
end
|
||||
|
||||
def shutdown
|
||||
$stdin = @stdin
|
||||
$stdout = @stdout
|
||||
$stderr = @stderr
|
||||
end
|
||||
end
|
||||
|
||||
def setup
|
||||
$stdin = File.open(File.expand_path('../fixtures/iris.csv', __dir__), 'r')
|
||||
@tmp_file = Tempfile.new
|
||||
$stderr = @tmp_file
|
||||
@stderr_file = Tempfile.new
|
||||
@stdout_file = Tempfile.new
|
||||
$stderr = @stderr_file
|
||||
$stdout = @stdout_file
|
||||
end
|
||||
|
||||
def teardown
|
||||
@tmp_file.close
|
||||
@stderr_file.close
|
||||
end
|
||||
|
||||
def fixture(fname)
|
||||
@ -32,71 +36,82 @@ class YouPlotCommandTest < Test::Unit::TestCase
|
||||
|
||||
test :bar do
|
||||
YouPlot::Command.new(['bar', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run
|
||||
assert_equal fixture('iris-barplot.txt'), @tmp_file.read
|
||||
assert_equal fixture('iris-barplot.txt'), @stderr_file.read
|
||||
end
|
||||
|
||||
test :barplot do
|
||||
YouPlot::Command.new(['barplot', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run
|
||||
assert_equal fixture('iris-barplot.txt'), @tmp_file.read
|
||||
assert_equal fixture('iris-barplot.txt'), @stderr_file.read
|
||||
end
|
||||
|
||||
test :hist do
|
||||
YouPlot::Command.new(['hist', '-H', '-d,', '-t', 'IRIS-HISTOGRAM']).run
|
||||
assert_equal fixture('iris-histogram.txt'), @tmp_file.read
|
||||
assert_equal fixture('iris-histogram.txt'), @stderr_file.read
|
||||
end
|
||||
|
||||
test :histogram do
|
||||
YouPlot::Command.new(['histogram', '-H', '-d,', '-t', 'IRIS-HISTOGRAM']).run
|
||||
assert_equal fixture('iris-histogram.txt'), @tmp_file.read
|
||||
assert_equal fixture('iris-histogram.txt'), @stderr_file.read
|
||||
end
|
||||
|
||||
test :line do
|
||||
YouPlot::Command.new(['line', '-H', '-d,', '-t', 'IRIS-LINEPLOT']).run
|
||||
assert_equal fixture('iris-lineplot.txt'), @tmp_file.read
|
||||
assert_equal fixture('iris-lineplot.txt'), @stderr_file.read
|
||||
end
|
||||
|
||||
test :lineplot do
|
||||
YouPlot::Command.new(['lineplot', '-H', '-d,', '-t', 'IRIS-LINEPLOT']).run
|
||||
assert_equal fixture('iris-lineplot.txt'), @tmp_file.read
|
||||
assert_equal fixture('iris-lineplot.txt'), @stderr_file.read
|
||||
end
|
||||
|
||||
test :lines do
|
||||
YouPlot::Command.new(['lines', '-H', '-d,', '-t', 'IRIS-LINEPLOTS']).run
|
||||
assert_equal fixture('iris-lineplots.txt'), @tmp_file.read
|
||||
assert_equal fixture('iris-lineplots.txt'), @stderr_file.read
|
||||
end
|
||||
|
||||
test :lineplots do
|
||||
YouPlot::Command.new(['lineplots', '-H', '-d,', '-t', 'IRIS-LINEPLOTS']).run
|
||||
assert_equal fixture('iris-lineplots.txt'), @tmp_file.read
|
||||
assert_equal fixture('iris-lineplots.txt'), @stderr_file.read
|
||||
end
|
||||
|
||||
test :s do
|
||||
YouPlot::Command.new(['s', '-H', '-d,', '-t', 'IRIS-SCATTER']).run
|
||||
assert_equal fixture('iris-scatter.txt'), @tmp_file.read
|
||||
assert_equal fixture('iris-scatter.txt'), @stderr_file.read
|
||||
end
|
||||
|
||||
test :scatter do
|
||||
YouPlot::Command.new(['scatter', '-H', '-d,', '-t', 'IRIS-SCATTER']).run
|
||||
assert_equal fixture('iris-scatter.txt'), @tmp_file.read
|
||||
assert_equal fixture('iris-scatter.txt'), @stderr_file.read
|
||||
end
|
||||
|
||||
test :d do
|
||||
YouPlot::Command.new(['d', '-H', '-d,', '-t', 'IRIS-DENSITY']).run
|
||||
assert_equal fixture('iris-density.txt'), @tmp_file.read
|
||||
assert_equal fixture('iris-density.txt'), @stderr_file.read
|
||||
end
|
||||
|
||||
test :density do
|
||||
YouPlot::Command.new(['density', '-H', '-d,', '-t', 'IRIS-DENSITY']).run
|
||||
assert_equal fixture('iris-density.txt'), @tmp_file.read
|
||||
assert_equal fixture('iris-density.txt'), @stderr_file.read
|
||||
end
|
||||
|
||||
test :box do
|
||||
YouPlot::Command.new(['box', '-H', '-d,', '-t', 'IRIS-BOXPLOT']).run
|
||||
assert_equal fixture('iris-boxplot.txt'), @tmp_file.read
|
||||
assert_equal fixture('iris-boxplot.txt'), @stderr_file.read
|
||||
end
|
||||
|
||||
test :boxplot do
|
||||
YouPlot::Command.new(['boxplot', '-H', '-d,', '-t', 'IRIS-BOXPLOT']).run
|
||||
assert_equal fixture('iris-boxplot.txt'), @tmp_file.read
|
||||
assert_equal fixture('iris-boxplot.txt'), @stderr_file.read
|
||||
end
|
||||
|
||||
test :plot_output_stdout do
|
||||
YouPlot::Command.new(['bar', '-o', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run
|
||||
assert_equal "", @stderr_file.read
|
||||
end
|
||||
|
||||
test :data_output_stdout do
|
||||
YouPlot::Command.new(['bar', '-O', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run
|
||||
assert_equal fixture('iris-barplot.txt'), @stderr_file.read
|
||||
assert_equal File.read(File.expand_path('../fixtures/iris.csv', __dir__)), @stdout_file.read
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user