Skip to content

Commit c7ff3ed

Browse files
committed
fixups for Windows - fix #89
1 parent 03a68b6 commit c7ff3ed

File tree

3 files changed

+27
-59
lines changed

3 files changed

+27
-59
lines changed

CHANGES

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
- Split version checking from `use Alien::Gnuplot` line for easier downstream
22
packaging. Fixes #98.
3+
- fixes for Windows (#89)
34

45
2.024 2023-03-30
56
- Add Alien::Gnuplot as a configure-time dependency. Fixes #92 - thanks @zmughal

lib/PDL/Graphics/Gnuplot.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -2302,7 +2302,7 @@ sub output {
23022302
# Check that, if there is at least one more argument, it is recognizable as a terminal
23032303
my $terminal;
23042304
$terminal = lc(shift);
2305-
2305+
$terminal = 'windows' if $^O =~ /mswin32/i and $terminal eq 'unknown';
23062306
##############################
23072307
# Check the terminal list here!
23082308
if(!exists($this->{valid_terms}->{$terminal})) {

t/plot.t

+25-58
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,15 @@ do {
9191
"xr sets xrange option properly in options call";
9292
$w->plot($x);
9393

94-
open FOO, "<$testoutput";
95-
my @lines = <FOO>;
94+
my @lines = do { open my $fh, "<", $testoutput or die "$testoutput: $!"; <$fh> };
9695
is( 0+@lines, 24, "setting 79x24 character dumb output yields 24 lines of output");
9796
like $lines[-2], qr/.*\s30\s*$/,
9897
"xrange option generates proper X axis (and dumb terminal behaves as expected)";
9998

99+
$w->{options}{output} = "${testoutput}2";
100100
$w->plot($x,{xr=>[0,5]});
101101

102-
open FOO, "<$testoutput";
103-
@lines = <FOO>;
102+
@lines = do { open my $fh, "<", "${testoutput}2" or die "${testoutput}2: $!"; <$fh> };
104103
like $lines[-2], qr/.*\s5\s*$/,
105104
"inline xrange option overrides stored xrange option (and dumb terminal behaves as expected)";
106105

@@ -109,9 +108,11 @@ do {
109108

110109
is_deeply $w->{last_plot}{options}{xrange}, [0, 5],
111110
"inline xrange is stored in last_plot options";
111+
undef $w;
112112
};
113113

114-
unlink($testoutput) or warn "\$!: $!";
114+
unlink("${testoutput}2") or warn "\$!: $! for '${testoutput}2'";
115+
unlink($testoutput) or warn "\$!: $! for '$testoutput'";
115116

116117
##############################
117118
# Test manual reset in multiplots
@@ -127,8 +128,7 @@ unlink($testoutput) or warn "\$!: $!";
127128
$w->line(xvals(5)**2); # no xlabel -- should not print one
128129
$w->end_multi;
129130
undef $w;
130-
open FOO,"<$testoutput";
131-
my @lines = grep m/FOO BAR BAZ/,(<FOO>);
131+
my @lines = grep m/FOO BAR BAZ/, do { open my $fh, "<", $testoutput or die "$testoutput: $!"; <$fh> };
132132
is 0+@lines, 1, "xlabel gets reset on multiplots";
133133
}
134134

@@ -157,9 +157,7 @@ ok($w,"re-opened window");
157157
eval { $w->plot({xr=>[0,30]},xvals(50),xvals(50)**2); };
158158
is($@, ''," plot works");
159159

160-
open FOO,"<$testoutput";
161-
my @lines = <FOO>;
162-
close FOO;
160+
my @lines = do { open my $fh, "<", $testoutput or die "$testoutput: $!"; <$fh> };
163161
is(0+@lines, 24, "test plot made 24 lines");
164162

165163
eval { $w->restart(); };
@@ -171,9 +169,7 @@ ok(!(-e $testoutput), "test file got deleted");
171169
eval { $w->replot(); };
172170
is($@, '', "replot works");
173171

174-
open FOO,"<$testoutput";
175-
my @l2 = <FOO>;
176-
close FOO;
172+
my @l2 = do { open my $fh, "<", $testoutput or die "$testoutput: $!"; <$fh> };
177173
$w->restart;
178174
unlink($testoutput) or warn "\$!: $!";
179175
is(0+@l2, 24, "test replot made 24 lines");
@@ -185,9 +181,7 @@ is($@, '', "replotting and adding a line works");
185181

186182
# lame test - just make sure the plots include at least two lines
187183
# and that one is higher than the other.
188-
open FOO,"<$testoutput";
189-
my @l3 = <FOO>;
190-
close FOO;
184+
my @l3 = do { open my $fh, "<", $testoutput or die "$testoutput: $!"; <$fh> };
191185
$w->restart;
192186
unlink($testoutput) or warn "\$!: $!";
193187
is(0+@l3, 24, "test replot again made 24 lines");
@@ -208,9 +202,7 @@ if($w->{gp_version} == 5.0 && $Alien::Gnuplot::pl==0
208202
eval { $w->options(yrange=>[200,400]); $w->replot(); };
209203
is($@, '', "options set and replot don't crash");
210204

211-
open FOO,"<$testoutput";
212-
my @l4 = <FOO>;
213-
close FOO;
205+
my @l4 = do { open my $fh, "<", $testoutput or die "$testoutput: $!"; <$fh> };
214206
$w->restart;
215207
unlink($testoutput) or warn "\$!: $!";
216208
is 0+@l4, 24, "replot made 24 lines after option set";
@@ -230,14 +222,8 @@ like($@, qr/No curve option found that matches \'xmin\'/, "xmin after a curve op
230222

231223
eval { $w->plot(xmin=>3,xrange=>[4,5],xvals(10),xvals(10)) };
232224
is($@, '', "plot works when curve options are given after plot options");
233-
234-
do {
235-
open FOO,"<$testoutput";
236-
my @lines = <FOO>;
237-
like($lines[22], qr/^\s*4\s+.*\s+5\s+$/, "curve option range overrides plot option range");
238-
close FOO;
239-
};
240-
225+
my @l5 = do { open my $fh, "<", $testoutput or die "$testoutput: $!"; <$fh> };
226+
like($l5[22], qr/^\s*4\s+.*\s+5\s+$/, "curve option range overrides plot option range");
241227

242228
##############################
243229
# Test parsing of plot options as arrays and/or PDLs, mixed.
@@ -373,8 +359,7 @@ is($@, '', "gnuplot reset works");
373359

374360
sub get_axis_testoutput {
375361
my $file = shift;
376-
open FOO,"<$file";
377-
my @lines = <FOO>;
362+
my @lines = do { open my $fh, "<", $file or die "$file: $!"; <$fh> };
378363
chomp for @lines;
379364
for my $i(0..$#lines) {
380365
last if( $lines[$#lines] =~ m/[^\s]/ );
@@ -664,21 +649,15 @@ my $dates = pdl(@dates);
664649

665650
eval { $w->plot( {xdata=>'time'}, with=>'points', $dates->clip(0), xvals($dates) ); };
666651
is($@, '', "time plotting didn't fail");
667-
open FOO,"<$testoutput";
668-
my $lines1 = join("",(<FOO>));
669-
close FOO;
652+
my $lines1 = join '', do { open my $fh, "<", $testoutput or die "$testoutput: $!"; <$fh> };
670653

671654
eval { $w->plot( {xr=>[0,$dates->max],xdata=>'time'}, with=>'points', $dates, xvals($dates) ); };
672655
is($@, '', "time plotting with range didn't fail");
673-
open FOO,"<$testoutput";
674-
my $lines2 = join("",(<FOO>));
675-
close FOO;
656+
my $lines2 = join '', do { open my $fh, "<", $testoutput or die "$testoutput: $!"; <$fh> };
676657

677658
eval { $w->plot( {xr=>[$dates->at(3),$dates->at(4)], xdata=>'time'}, with=>'points', $dates, xvals($dates));};
678659
is($@, '', "time plotting with a different range didn't fail");
679-
open FOO,"<$testoutput";
680-
my $lines3 = join("",(<FOO>));
681-
close FOO;
660+
my $lines3 = join '', do { open my $fh, "<", $testoutput or die "$testoutput: $!"; <$fh> };
682661

683662
print "lines1:\n$lines1\n\nlines2:\n$lines2\n\nlines3:\n$lines3\n\n";
684663
SKIP: {
@@ -693,9 +672,7 @@ isnt($lines2, $lines3, "Modifying the time range modifies the graph");
693672
eval { $w->reset; $w->plot({title=>"This is a plot title"},with=>'points',xvals(5));};
694673
is($@, '', "Title plotting works, no error");
695674

696-
open FOO,"<$testoutput";
697-
@lines = <FOO>;
698-
close FOO;
675+
@lines = do { open my $fh, "<", $testoutput or die "$testoutput: $!"; <$fh> };
699676

700677
SKIP:{
701678
skip "Skipping title tests due to obsolete version of gnuplot (BSD uses 4.2, which fails these)",3
@@ -707,9 +684,7 @@ SKIP:{
707684
eval { $w->plot({title=>""},with=>'points',xvals(5));};
708685
is($@, '', "Non-title plotting works, no error");
709686

710-
open FOO,"<$testoutput";
711-
@lines = <FOO>;
712-
close FOO;
687+
@lines = do { open my $fh, "<", $testoutput or die "$testoutput: $!"; <$fh> };
713688
if($w->{gp_version} < 5.2) {
714689
like($lines[1], qr/^\s*$/, "Setting empty plot title sets an empty title");
715690
} else {
@@ -726,15 +701,11 @@ SKIP:{
726701

727702
eval { $w->plot({trid=>1,title=>""},with=>'lines',sequence(3,3)); };
728703
is($@, '', "3-d grid plot with single column succeeded");
729-
open FOO,"<$testoutput";
730-
my $lines = join("",<FOO>);
731-
close FOO;
704+
my $lines = join '', do { open my $fh, "<", $testoutput or die "$testoutput: $!"; <$fh> };
732705

733706
eval { $w->plot({trid=>1,title=>"",yr=>[-1,1]},with=>'lines',cdim=>1,sequence(3,3));};
734707
is($@, '', "3-d threaded plot with single column succeeded");
735-
open FOO,"<$testoutput";
736-
my $lines2 = join("",<FOO>);
737-
close FOO;
708+
my $lines2 = join '', do { open my $fh, "<", $testoutput or die "$testoutput: $!"; <$fh> };
738709

739710
isnt( $lines2, $lines, "the two 3-D plots differ");
740711

@@ -855,32 +826,28 @@ $b = pdl(1,4,9,16,25)->sqrt; # 1,2,3,4,5
855826
$w->plot(with=>'lines',$a,{binary=>1});
856827
$w->close;
857828

858-
open FOO, "<$testoutput";
859-
@lines = <FOO>;
829+
@lines = do { open my $fh, "<", $testoutput or die "$testoutput: $!"; <$fh> };
860830
isnt $lines[12], '';
861831
like substr($lines[12],20,40), qr/^\s+$/, "NaN makes a blank in a plot";
862832

863833
$w->restart;
864834
$w->plot(with=>'lines',$b,{binary=>1});
865835
$w->close;
866-
open FOO, "<$testoutput";
867-
@lines = <FOO>;
836+
@lines = do { open my $fh, "<", $testoutput or die "$testoutput: $!"; <$fh> };
868837
isnt $lines[12], '';
869838
unlike substr($lines[12],20,40), qr/^\s+$/, "No NaN makes a nonblank in a plot";
870839

871840
$w->restart;
872841
$w->plot(with=>'lines',$b,{binary=>0});
873842
$w->close;
874-
open FOO, "<$testoutput";
875-
@lines = <FOO>;
843+
@lines = do { open my $fh, "<", $testoutput or die "$testoutput: $!"; <$fh> };
876844
isnt $lines[12], '';
877845
unlike substr($lines[12],20,40), qr/^\s+$/, "No NaN makes a nonblank in a plot even with ASCII";
878846

879847
$w->restart;
880848
$w->plot(with=>'lines',$a,{binary=>0});
881849
$w->close;
882-
open FOO, "<$testoutput";
883-
@lines = <FOO>;
850+
@lines = do { open my $fh, "<", $testoutput or die "$testoutput: $!"; <$fh> };
884851
isnt $lines[12], '';
885852
like substr($lines[12],20,40), qr/^\s+$/, "NaN makes a blank in a plot even with ASCII";
886853

0 commit comments

Comments
 (0)