Changeset 8249


Ignore:
Timestamp:
07/20/10 03:29:41 (3 years ago)
Author:
SvenDowideit
Message:

Item9349: add try, finally to the capturing of STDERR and STDOUT so that when an exception is thrown in the code being tested, we actually do close those captures.
Additionally, put those captured outputs into testcase members so they can be retrived in that situation.

Note: it is possible that this breaks on some versions of Perl / Error.pm - please report any such failures ASAP

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UnitTestContrib/lib/Unit/TestCase.pm

    r8112 r8249  
    544544    my $result; 
    545545 
    546     { 
     546    undef $this->{stdout}; 
     547    undef $this->{stderr}; 
     548    try { 
    547549        local *STDOUT; 
    548550        local *STDERR; 
     
    551553        open STDERR, ">", $stderrfile 
    552554          or die "Can't open temporary STDERR file $stderrfile: $!"; 
     555 
    553556        $result = &$proc(@params); 
    554     } 
    555  
    556     my $f; 
    557     open($f, '<', $stdoutfile) || die "Capture failed to reopen $stdoutfile"; 
    558     local $/; 
    559     my $stdout = <$f>; 
    560     close($f); 
    561     open($f, '<', $stderrfile) || die "Capture failed to reopen $stderrfile"; 
    562     local $/; 
    563     my $stderr = <$f>; 
    564     close($f); 
    565  
    566     return ( $stdout, $stderr, $result ); 
     557    } finally { 
     558        my $f; 
     559        open($f, '<', $stdoutfile) || die "Capture failed to reopen $stdoutfile"; 
     560        local $/; 
     561        $this->{stdout} = <$f>; 
     562        close($f); 
     563        open($f, '<', $stderrfile) || die "Capture failed to reopen $stderrfile"; 
     564        local $/; 
     565        $this->{stderr} = <$f>; 
     566        close($f); 
     567    }; 
     568    return ( $this->{stdout}, $this->{stderr}, $result ); 
    567569} 
    568570 
Note: See TracChangeset for help on using the changeset viewer.