File: 44sub-attrs.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 (55 lines) | stat: -rw-r--r-- 1,132 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
#!/usr/bin/perl

use v5.14;
use warnings;

use Test2::V0;
use attributes;

use Future::AsyncAwait;

# :method
{
   async sub is_method :method { }

   my $cvf_method = grep { m/^method$/ } attributes::get( \&is_method );
   ok( $cvf_method, '&is_method has :method' );
}

# :lvalue - accepted but should warn
{
   my $warning;
   BEGIN { $SIG{__WARN__} = sub { $warning++ } }

   async sub is_lvalue :lvalue { }

   my $cvf_lvalue = grep { m/^lvalue$/ } attributes::get( \&is_lvalue );
   ok( $cvf_lvalue, '&is_lvalue has :lvalue' );
   ok( $warning, 'async sub :lvalue produces a warning' );

   BEGIN { undef $SIG{__WARN__} }
}

# :const happens to break currently, but it would be meaningless anyway

# some custom ones
{
   package TestCustomAttrs;

   my $modify_invoked;

   sub MODIFY_CODE_ATTRIBUTES
   {
      my ( $pkg, $sub, $attr ) = @_;

      $modify_invoked++;
      ::is( $attr, "MyCustomAttribute(value here)", 'MODIFY_CODE_ATTRIBUTES takes attr' );

      return ();
   }

   async sub is_attributed :MyCustomAttribute(value here) { }
   ::ok( $modify_invoked, 'MODIFY_CODE_ATTRIBUTES invoked' );
}

done_testing;