File: exception.t

package info (click to toggle)
webauth 4.7.0-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 7,932 kB
  • sloc: ansic: 28,341; sh: 12,031; perl: 8,361; xml: 6,856; makefile: 459; php: 7
file content (43 lines) | stat: -rwxr-xr-x 1,431 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/perl -w
#
# Test suite for WebAuth::Exception.
#
# Written by Russ Allbery <eagle@eyrie.org>
# Copyright 2012, 2014
#     The Board of Trustees of the Leland Stanford Junior University
#
# See LICENSE for licensing terms.

use strict;

use Test::More tests => 13;

BEGIN {
    use_ok ('WebAuth', '3.02', qw/WA_ERR_UNIMPLEMENTED/);
    use_ok ('WebAuth::Exception', '3.01');
}

# Create a WebAuth context and do something that produces an exception.
my $wa = WebAuth->new;
eval { $wa->key_create (42, 1) };
ok ($@, 'key_create produces an exception as expected');
my $exception = $@;
isa_ok ($exception, 'WebAuth::Exception', 'Exception object');
is ($exception->status, WA_ERR_UNIMPLEMENTED, 'Status');
my $message = 'operation not supported (unsupported key type 42)';
is ($exception->error_message, $message, 'Error message');
is ($exception->detail_message, 'webauth_key_create', 'Detail message');
like ($exception->verbose_message, qr/^webauth_key_create: \Q$message\E at /,
      'Verbose message');
like ("$@", qr/^webauth_key_create: \Q$message\E at /, 'Stringification');
my $string = "$@";
is ($@ cmp $string, 0, 'cmp');

is ($@ cmp 'Test', 1, 'cmp inequal');
is ('Test' cmp $@, -1, 'cmp inequal swapped');

# Test an exception with undefined detail and line.
$exception->{detail} = undef;
$exception->{line}   = undef;
is ($exception->verbose_message, $message,
    'Verbose message with no detail or line');