91
91
" xr sets xrange option properly in options call" ;
92
92
$w -> plot($x );
93
93
94
- open FOO, " <$testoutput " ;
95
- my @lines = <FOO>;
94
+ my @lines = do { open my $fh , " <" , $testoutput or die " $testoutput : $! " ; <$fh > };
96
95
is( 0+@lines , 24, " setting 79x24 character dumb output yields 24 lines of output" );
97
96
like $lines [-2], qr / .*\s 30\s *$ / ,
98
97
" xrange option generates proper X axis (and dumb terminal behaves as expected)" ;
99
98
99
+ $w -> {options }{output } = " ${testoutput} 2" ;
100
100
$w -> plot($x ,{xr => [0,5]});
101
101
102
- open FOO, " <$testoutput " ;
103
- @lines = <FOO>;
102
+ @lines = do { open my $fh , " <" , " ${testoutput} 2" or die " ${testoutput} 2: $! " ; <$fh > };
104
103
like $lines [-2], qr / .*\s 5\s *$ / ,
105
104
" inline xrange option overrides stored xrange option (and dumb terminal behaves as expected)" ;
106
105
@@ -109,9 +108,11 @@ do {
109
108
110
109
is_deeply $w -> {last_plot }{options }{xrange }, [0, 5],
111
110
" inline xrange is stored in last_plot options" ;
111
+ undef $w ;
112
112
};
113
113
114
- unlink ($testoutput ) or warn " \$ !: $! " ;
114
+ unlink (" ${testoutput} 2" ) or warn " \$ !: $! for '${testoutput} 2'" ;
115
+ unlink ($testoutput ) or warn " \$ !: $! for '$testoutput '" ;
115
116
116
117
# #############################
117
118
# Test manual reset in multiplots
@@ -127,8 +128,7 @@ unlink($testoutput) or warn "\$!: $!";
127
128
$w -> line(xvals(5)**2); # no xlabel -- should not print one
128
129
$w -> end_multi;
129
130
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 > };
132
132
is 0+@lines , 1, " xlabel gets reset on multiplots" ;
133
133
}
134
134
@@ -157,9 +157,7 @@ ok($w,"re-opened window");
157
157
eval { $w -> plot({xr => [0,30]},xvals(50),xvals(50)**2); };
158
158
is($@ , ' ' ," plot works" );
159
159
160
- open FOO," <$testoutput " ;
161
- my @lines = <FOO>;
162
- close FOO;
160
+ my @lines = do { open my $fh , " <" , $testoutput or die " $testoutput : $! " ; <$fh > };
163
161
is(0+@lines , 24, " test plot made 24 lines" );
164
162
165
163
eval { $w -> restart(); };
@@ -171,9 +169,7 @@ ok(!(-e $testoutput), "test file got deleted");
171
169
eval { $w -> replot(); };
172
170
is($@ , ' ' , " replot works" );
173
171
174
- open FOO," <$testoutput " ;
175
- my @l2 = <FOO>;
176
- close FOO;
172
+ my @l2 = do { open my $fh , " <" , $testoutput or die " $testoutput : $! " ; <$fh > };
177
173
$w -> restart;
178
174
unlink ($testoutput ) or warn " \$ !: $! " ;
179
175
is(0+@l2 , 24, " test replot made 24 lines" );
@@ -185,9 +181,7 @@ is($@, '', "replotting and adding a line works");
185
181
186
182
# lame test - just make sure the plots include at least two lines
187
183
# 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 > };
191
185
$w -> restart;
192
186
unlink ($testoutput ) or warn " \$ !: $! " ;
193
187
is(0+@l3 , 24, " test replot again made 24 lines" );
@@ -208,9 +202,7 @@ if($w->{gp_version} == 5.0 && $Alien::Gnuplot::pl==0
208
202
eval { $w -> options(yrange => [200,400]); $w -> replot(); };
209
203
is($@ , ' ' , " options set and replot don't crash" );
210
204
211
- open FOO," <$testoutput " ;
212
- my @l4 = <FOO>;
213
- close FOO;
205
+ my @l4 = do { open my $fh , " <" , $testoutput or die " $testoutput : $! " ; <$fh > };
214
206
$w -> restart;
215
207
unlink ($testoutput ) or warn " \$ !: $! " ;
216
208
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
230
222
231
223
eval { $w -> plot(xmin => 3,xrange => [4,5],xvals(10),xvals(10)) };
232
224
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" );
241
227
242
228
# #############################
243
229
# Test parsing of plot options as arrays and/or PDLs, mixed.
@@ -373,8 +359,7 @@ is($@, '', "gnuplot reset works");
373
359
374
360
sub get_axis_testoutput {
375
361
my $file = shift ;
376
- open FOO," <$file " ;
377
- my @lines = <FOO>;
362
+ my @lines = do { open my $fh , " <" , $file or die " $file : $! " ; <$fh > };
378
363
chomp for @lines ;
379
364
for my $i (0..$#lines ) {
380
365
last if ( $lines [$#lines ] =~ m /[^\s ] / );
@@ -664,21 +649,15 @@ my $dates = pdl(@dates);
664
649
665
650
eval { $w -> plot( {xdata => ' time' }, with => ' points' , $dates -> clip(0), xvals($dates ) ); };
666
651
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 > };
670
653
671
654
eval { $w -> plot( {xr => [0,$dates -> max],xdata => ' time' }, with => ' points' , $dates , xvals($dates ) ); };
672
655
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 > };
676
657
677
658
eval { $w -> plot( {xr => [$dates -> at(3),$dates -> at(4)], xdata => ' time' }, with => ' points' , $dates , xvals($dates ));};
678
659
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 > };
682
661
683
662
print " lines1:\n $lines1 \n\n lines2:\n $lines2 \n\n lines3:\n $lines3 \n\n " ;
684
663
SKIP: {
@@ -693,9 +672,7 @@ isnt($lines2, $lines3, "Modifying the time range modifies the graph");
693
672
eval { $w -> reset ; $w -> plot({title => " This is a plot title" },with => ' points' ,xvals(5));};
694
673
is($@ , ' ' , " Title plotting works, no error" );
695
674
696
- open FOO," <$testoutput " ;
697
- @lines = <FOO>;
698
- close FOO;
675
+ @lines = do { open my $fh , " <" , $testoutput or die " $testoutput : $! " ; <$fh > };
699
676
700
677
SKIP:{
701
678
skip " Skipping title tests due to obsolete version of gnuplot (BSD uses 4.2, which fails these)" ,3
@@ -707,9 +684,7 @@ SKIP:{
707
684
eval { $w -> plot({title => " " },with => ' points' ,xvals(5));};
708
685
is($@ , ' ' , " Non-title plotting works, no error" );
709
686
710
- open FOO," <$testoutput " ;
711
- @lines = <FOO>;
712
- close FOO;
687
+ @lines = do { open my $fh , " <" , $testoutput or die " $testoutput : $! " ; <$fh > };
713
688
if ($w -> {gp_version } < 5.2) {
714
689
like($lines [1], qr / ^\s *$ / , " Setting empty plot title sets an empty title" );
715
690
} else {
@@ -726,15 +701,11 @@ SKIP:{
726
701
727
702
eval { $w -> plot({trid => 1,title => " " },with => ' lines' ,sequence(3,3)); };
728
703
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 > };
732
705
733
706
eval { $w -> plot({trid => 1,title => " " ,yr => [-1,1]},with => ' lines' ,cdim => 1,sequence(3,3));};
734
707
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 > };
738
709
739
710
isnt( $lines2 , $lines , " the two 3-D plots differ" );
740
711
@@ -855,32 +826,28 @@ $b = pdl(1,4,9,16,25)->sqrt; # 1,2,3,4,5
855
826
$w -> plot(with => ' lines' ,$a ,{binary => 1});
856
827
$w -> close ;
857
828
858
- open FOO, " <$testoutput " ;
859
- @lines = <FOO>;
829
+ @lines = do { open my $fh , " <" , $testoutput or die " $testoutput : $! " ; <$fh > };
860
830
isnt $lines [12], ' ' ;
861
831
like substr ($lines [12],20,40), qr / ^\s +$ / , " NaN makes a blank in a plot" ;
862
832
863
833
$w -> restart;
864
834
$w -> plot(with => ' lines' ,$b ,{binary => 1});
865
835
$w -> close ;
866
- open FOO, " <$testoutput " ;
867
- @lines = <FOO>;
836
+ @lines = do { open my $fh , " <" , $testoutput or die " $testoutput : $! " ; <$fh > };
868
837
isnt $lines [12], ' ' ;
869
838
unlike substr ($lines [12],20,40), qr / ^\s +$ / , " No NaN makes a nonblank in a plot" ;
870
839
871
840
$w -> restart;
872
841
$w -> plot(with => ' lines' ,$b ,{binary => 0});
873
842
$w -> close ;
874
- open FOO, " <$testoutput " ;
875
- @lines = <FOO>;
843
+ @lines = do { open my $fh , " <" , $testoutput or die " $testoutput : $! " ; <$fh > };
876
844
isnt $lines [12], ' ' ;
877
845
unlike substr ($lines [12],20,40), qr / ^\s +$ / , " No NaN makes a nonblank in a plot even with ASCII" ;
878
846
879
847
$w -> restart;
880
848
$w -> plot(with => ' lines' ,$a ,{binary => 0});
881
849
$w -> close ;
882
- open FOO, " <$testoutput " ;
883
- @lines = <FOO>;
850
+ @lines = do { open my $fh , " <" , $testoutput or die " $testoutput : $! " ; <$fh > };
884
851
isnt $lines [12], ' ' ;
885
852
like substr ($lines [12],20,40), qr / ^\s +$ / , " NaN makes a blank in a plot even with ASCII" ;
886
853
0 commit comments