@@ -24,38 +24,30 @@ my $name = catfile($tmpdir, "tmp0");
2424
2525# Set up the working filename and make sure we're working with a clean slate:
2626
27- # **TEST 2** save an ndarray to disk
2827my $x = pdl [2,3],[4,5],[6,7];
29- my $header = eval { writeflex($name , $x ) } ;
28+ my $header = writeflex($name , $x );
3029ok((-f $name ), " writeflex should create a file" );
3130
3231my $header_bis = [ { %{$header -> [0]}, Dims => [2, undef ] } ];
3332eval { readflex($name , [@$header_bis , @$header_bis ]) };
3433like $@ , qr / >1 header/ , ' readflex only allows undef dim when only one hash' ;
35- my $x_bis = readflex($name , $header_bis );
36- is_pdl $x_bis , $x , " read back with undef highest dim correct" ;
34+ is_pdl readflex($name , $header_bis ), $x , " read back with undef highest dim correct" ;
3735
38- # **TEST 3** save a header to disk
39- eval { writeflexhdr($name , $header ) };
36+ writeflexhdr($name , $header );
4037ok(-f " $name .hdr" , " writeflexhdr should create a header file" );
4138
42- # **TEST 4** read it back, and make sure it gives the same ndarray
43- my $y = eval { readflex($name ) };
44- is_pdl $x , $y , " A ndarray and its saved copy should be about equal" ;
39+ is_pdl readflex($name ), $x , " A ndarray and its saved copy should be about equal" ;
4540
46- # **TEST 5** save two ndarrays to disk
4741my ($c1 , $c2 ) = ([0,0,0,0],[0,0,0,0]);
4842my $c = pdl [$c1 ,$c2 ];
4943my $d = pdl [1,1,1];
5044my $cdname = $name . ' cd' ;
51- $header = eval { writeflex($cdname , $c , $d ) };
52- ok((-f $cdname ), " writeflex saves 2 pdls to a file" );
53- # **TEST 6** save a header to disk
54- eval { writeflexhdr($cdname , $header ) };
55- ok(-f " $cdname .hdr" , " writeflexhdr create a header file" );
56- # **TEST 7** read it back, and make sure it gives the same ndarray
45+ $header = writeflex($cdname , $c , $d );
46+ ok -f $cdname , " writeflex saves 2 pdls to a file" ;
47+ writeflexhdr($cdname , $header );
48+ ok -f " $cdname .hdr" , " writeflexhdr create a header file" ;
5749# This is sf.net bug #3375837 "_read_flexhdr state machine fails"
58- my ( @cd ) = eval { no warnings; readflex($cdname ) };
50+ my @cd = do { no warnings; readflex($cdname ) };
5951is 0+@cd , 2, ' sf.net bug 3375837' ;
6052is_pdl $cd [0], $c , ' sf.net bug 3375837' ;
6153is_pdl $cd [1], $d , ' sf.net bug 3375837' ;
@@ -65,14 +57,13 @@ unlink $cdname, $cdname . '.hdr'; # just to be absolutely sure
6557{
6658my $gname = $name .' g' ;
6759local $PDL::IO::FlexRaw::writeflexhdr = 1;
68- eval { writeflex($gname , $d , $c ) } ; # 2D last so can append
69- my @dc = eval { readflex($gname ) } ;
60+ writeflex($gname , $d , $c ); # 2D last so can append
61+ my @dc = readflex($gname );
7062is_pdl $dc [0], $d ;
7163is_pdl $dc [1], $c ;
7264my $e = pdl(2,2,2,2);
73- eval { glueflex($gname , $e ) };
74- is $@ , ' ' , ' no error glueflex' ;
75- @dc = eval { readflex($gname ) };
65+ glueflex($gname , $e );
66+ @dc = readflex($gname );
7667is_pdl $dc [0], $d ;
7768is_pdl $dc [1], pdl($c1 ,$c2 ,$e );
7869}
@@ -88,18 +79,11 @@ SKIP: {
8879 }
8980 }
9081
91- # **TEST 8** compare mapfraw ndarray with original ndarray
9282 is_pdl $x , $c , " An ndarray and its mapflex representation should be about equal" ;
9383
94- # **TEST 9** modifications should be saved when $c goes out of scope
95- # THIS TEST FAILS.
96- # This failure is recorded in sf.net bug 3031068.
97- # Presently, making $c go out of scope does not free the memory
98- # mapping associated with mapflex, so this modification is never
99- # saved to the file (or at least it's not saved immediately).
10084 $c += 1;
10185 undef $c ;
102- $y = readflex($name );
86+ my $y = readflex($name );
10387 is_pdl $x +1, $y , " Modifications to mapfraw should be saved to disk no later than when the ndarray ceases to exist" ;
10488
10589 # We're starting a new test, so we'll remove the files we've created so far
@@ -108,7 +92,6 @@ SKIP: {
10892 undef $x ;
10993 undef $y ;
11094
111- # **TEST 10** test creating a pdl via mapfraw
11295 # First create and modify the ndarray
11396 $header = [{NDims => 2, Dims => [3,2], Type => ' float' }];
11497 # Fix this specification.
@@ -123,19 +106,16 @@ SKIP: {
123106 undef $x ;
124107 # Load it back up and see if the values are what we expect
125108 $y = readflex($name );
126- # **TEST 11**
127109 is_pdl $y , float([[0,1,2],[0.1,1.1,2.1]]),
128110 " mapfraw should be able to create new ndarrays" ;
129111
130112 undef $x ; undef $y ; # cleanup
131113 # test for bug mentioned in https://perlmonks.org/?node_id=387256
132114 my $p1 = sequence(5);
133- my $header1 = eval { writeflex($cdname , $p1 ) };
134- is $@ , ' ' , ' no error' ;
115+ my $header1 = writeflex($cdname , $p1 );
135116 writeflexhdr($cdname , $header1 );
136117 my $p2 = sequence(5) + 8;
137- my $header2 = eval { writeflex($name , $p2 ) };
138- is $@ , ' ' , ' no error' ;
118+ my $header2 = writeflex($name , $p2 );
139119 writeflexhdr($name , $header2 );
140120 $p1 = mapflex($cdname );
141121 is $p1 .' ' , ' [0 1 2 3 4]' , ' right value before second mapflex' ;
0 commit comments