Skip to content

Commit

Permalink
TestTool::init: properly handle SDL::init errors
Browse files Browse the repository at this point in the history
So far TestTool::init was just capturing stdout and stderr of SDL::init,
using stderr to check whether SDL::init failed. This, other than being
fragile, misses the init errors.

Switch from checking stderr to checking the actual result code of
SDL::init.
  • Loading branch information
pinotree committed May 1, 2015
1 parent e1fbc93 commit 39f3db9
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions t/lib/SDL/TestTool.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ sub init {
my ( $self, $init ) = @_;
my $stdout = '';
my $stderr = '';
my $result = 0;

if ( $init == SDL_INIT_VIDEO ) {
if ( $^O !~ /win/i && !$ENV{DISPLAY} && !$ENV{SDL_VIDEODRIVER} ) {
Expand All @@ -36,12 +37,12 @@ sub init {
SDL::quit();
}

($stdout, $stderr ) = capture { SDL::init($init) };
if ( $stderr ne '' ) {
($stdout, $stderr, $result ) = capture { SDL::init($init) };
if ( $result != 0 ) {
warn 'Init ' . $inits{$init} . ' failed with SDL error: ' . SDL::get_error() . "\nand stderr $stderr\n";
}

return !( $stderr ne '' );
return $result == 0;
}

sub test_audio_open {
Expand Down

0 comments on commit 39f3db9

Please sign in to comment.