File: 43failure.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 (68 lines) | stat: -rw-r--r-- 1,756 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
#!/usr/bin/perl

use v5.14;
use warnings;

use Test2::V0;

use Future;

use Future::AsyncAwait;

async sub identity
{
   return await $_[0];
}

# die in async is transparent to thrown objects
{
   my $fret = (async sub {
      die bless [qw( a b c )], "TestException";
   })->();

   ok( $fret->is_failed, '$fret failed after die in async' );
   is( ref $fret->failure, "TestException", 'die in async preserves object' );
   is( [ @{ $fret->failure } ], [qw( a b c )],
      'die in async preserves object contents' );
}

# await is transparent to thrown objects
{
   my $f1 = Future->new;
   my $fret = (async sub {
      eval { await $f1 } or return $@;
   })->();

   $f1->fail( bless [qw( d e f )], "TestException" );

   is( ref $fret->get, "TestException", 'await failure preserves object' );
   is( [ @{ $fret->get } ], [qw( d e f )],
      'await failure preserves object contents' );
}

# async/await is transparent to thrown objects
{
   my $f1 = Future->new;
   my $fret = identity( $f1 );

   $f1->fail( bless [qw( g h i )], "TestException" );

   ok( $fret->is_failed, '$fret failed after die in async/await' );
   is( ref $fret->failure, "TestException", 'die in async/await preserves object' );
   is( [ @{ $fret->failure } ], [qw( g h i )],
      'die in async/await preserves object contents' );
}

# async/await is transparent to failures
SKIP: {
   skip "This test requires Future version 0.40", 1 unless $Future::VERSION >= 0.40;
   my $f1 = Future->new;
   my $fret = identity( $f1 );

   $f1->fail( "message\n", category => qw( details here ) );
   ok( $fret->is_failed, '$fret failed after ->fail' );
   is( [ $fret->failure ], [ "message\n", category => qw( details here ) ],
      '$fret->failure after ->fail' );
}

done_testing;