Add libwx-perl
[pkg-perl] / deb-src / libwx-perl / libwx-perl-0.96 / t / 14_eh_die.t
1 #!/usr/bin/perl -w
2
3 use strict;
4 use Wx;
5 use lib './t';
6 use Tests_Helper qw(test_app);
7 use Test::More Wx::wxMAC() ? ( 'skip_all' => 'Hangs on wxMac' ) :
8                              ( 'tests'    => 6 );
9
10 use Wx::Event qw(EVT_TIMER);
11
12 my $app = test_app(
13     sub {
14         Wx::Frame->new( undef, -1, 'X' )->Show( 1 ); # to appease wxGTK
15     } );
16
17 my $timer = Wx::Timer->new($app, 123);
18
19 sub onTimer0 {
20     ok( 1, 'Timer fired' );
21     eval 'BEGIN { die "Fatal!" }';
22     ok( $@, 'Error was generated and trapped' );
23
24     EVT_TIMER( $app, 123, undef ); # disconnect
25     EVT_TIMER( $app, 123, \&onTimer1 );
26     $timer->Start( 20, 1 );
27 }
28
29 sub onTimer1 {
30     ok( 1, 'Second timer fired' );
31     eval 'use ThisModuleDoesNotExist';
32     ok( $@, 'Error was generated and trapped' );
33
34     EVT_TIMER( $app, 123, undef ); # disconnect
35     EVT_TIMER( $app, 123, \&onTimer2 );
36     $timer->Start( 20, 1 );
37 }
38
39 sub onTimer2 {
40     ok( 1, 'Third timer fired' );
41     die "I am going away...";
42     fail( 'panic: die() did not work' );
43 }
44
45 EVT_TIMER( $app, 123, \&onTimer0 );
46 $timer->Start( 10, 1 );
47
48 eval { $app->MainLoop };
49
50 like( $@, qr/^I am going away\.\.\./, 'Exception correctly propagated' );
51