use Test::More tests => 5;
use Gnuplot::Simple qw(:all);
use Cwd;
{
#this dataset contains some whitespace to test that case too
my $D = [ [ 1, "3 " ], [ 2, 4 ] ];
write_data( "./t/temp/gnuplot_test.csv", $D );
is(
read_file( "./t/temp/gnuplot_test.csv", { binmode => ":utf8" } ),
"1\t\"3 \"\n2\t4",
'Writes gnuplot file correctly'
);
#test exception
my $d = [ ['"a'] ];
dies_ok { write_data( "./t/temp/gnuplot_test.csv", $d ) } 'Does not accept "';
throws_ok { write_data( "./t/temp/gnuplot_test.csv", [] ) } qr/Non-empty/,
'Must contain data';
throws_ok { write_data( "./t/temp/gnuplot_test.csv", [ [] ] ) } qr/more than one/,
'Must contain labels';
}
#exec_commands
{
my $d = [ [ 1, 1 ], [ 2, 2 ], [ 3, 3 ] ];
my $f = dirname(__FILE__) . "/test.png";
exec_commands(
qq{
set terminal png
set output "$f"
plot __DATA__ u 1:2
}, $d
);
ok( -e $f, 'Creates an image file' );
`rm -f $f`;
}