File: 14_eh_die.t

package info (click to toggle)
libwx-perl 1%3A0.9909-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,912 kB
  • sloc: cpp: 9,728; perl: 8,182; ansic: 626; makefile: 41
file content (51 lines) | stat: -rwxr-xr-x 1,175 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/perl -w

use strict;
use Wx;
use lib './t';
use Tests_Helper qw(test_app);
use Test::More Wx::wxMAC() ? ( 'skip_all' => 'Hangs on wxMac' ) :
                             ( 'tests'    => 6 );

use Wx::Event qw(EVT_TIMER);

my $app = test_app(
    sub {
        Wx::Frame->new( undef, -1, 'X' )->Show( 1 ); # to appease wxGTK
    } );

my $timer = Wx::Timer->new($app, 123);

sub onTimer0 {
    ok( 1, 'Timer fired' );
    eval 'BEGIN { die "Fatal!" }';
    ok( $@, 'Error was generated and trapped' );

    EVT_TIMER( $app, 123, undef ); # disconnect
    EVT_TIMER( $app, 123, \&onTimer1 );
    $timer->Start( 20, 1 );
}

sub onTimer1 {
    ok( 1, 'Second timer fired' );
    eval 'use ThisModuleDoesNotExist';
    ok( $@, 'Error was generated and trapped' );

    EVT_TIMER( $app, 123, undef ); # disconnect
    EVT_TIMER( $app, 123, \&onTimer2 );
    $timer->Start( 20, 1 );
}

sub onTimer2 {
    ok( 1, 'Third timer fired' );
    die "I am going away...";
    fail( 'panic: die() did not work' );
}

EVT_TIMER( $app, 123, \&onTimer0 );
$timer->Start( 10, 1 );

eval { $app->MainLoop };

like( $@, qr/^I am going away\.\.\./, 'Exception correctly propagated' );