File: 32compile-errors.t

package info (click to toggle)
libfuture-asyncawait-perl 0.70-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 528 kB
  • sloc: perl: 2,647; ansic: 118; pascal: 34; makefile: 3
file content (94 lines) | stat: -rw-r--r-- 2,008 bytes parent folder | download
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/perl

use v5.14;
use warnings;

use Test2::V0;

use Future::AsyncAwait;

use constant HAVE_XPK_0_09 => ( $XS::Parse::Keyword::VERSION >= 0.09 );

# All of these should fail to compile but not SEGV. If we get to the end of
# the script without segfaulting, we've passed.

# RT129987
ok( !defined eval q'
   async sub foo {
   ',
   'RT129987 test case 1 does not segfault' );

SKIP: {
   eval { require Syntax::Keyword::Try } or skip "No Syntax::Keyword::Try", 1;

   ok( !defined eval q'
      use Syntax::Keyword::Try;

      my $pending = Future->new;
      my $pending2 = Future->new;
      my $final = (async sub {
         my ($f) = @_;
         try {
            await $f;
            my $nested = async sub {
               await shift;
            })->($pending2);
            return await $nested;
         } catch {
         }
      })->($pending);
      ',
      'RT129987 test case 2 does not segfault' );
}

# RT129987
ok( !defined eval q'
   (async sub { my $x = async sub { await 1; })
   ',
   'RT129987 test case 3 does not segfault' );

# RT130417
{
   local $@;

   ok( !defined eval q'
      package segfault;
      use strict;
      use warnings;

      use Future::AsyncAwait;

      async sub example {
         $x
      }
      ',
      'RT130417 strict-failing code fails to compile' );
   like( "$@", qr/^Global symbol "\$x" requires explicit package name/,
      'Failure message complains about undeclared $x' );
}

# RT131487
{
   local $@;

   my $err = HAVE_XPK_0_09 ?
      qr/^parse failed--compilation aborted / :
      qr/^Global symbol "\$api" requires explicit package name/;

   ok( !defined eval q'
      package segfault;
      use strict;
      use warnings;

      use Future::AsyncAwait;
      (async sub {
         for my $i (1..5) {
            await $api->method;
         }
      })->()->get;
      ',
      'RT131487 strict-failing code fails to compile' );
   like( "$@", $err, 'Failure message complains about undeclared $api' );
}

done_testing;