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
|
#!/usr/bin/perl -w
use strict;
use warnings;
use Fatal;
use Test::More 'no_plan';
# Tests to determine if Fatal's internal interfaces remain backwards
# compatible.
#
# WARNING: This file contains a lot of very ugly code, hard-coded
# strings, and nasty API calls. It may frighten small children.
# Viewer discretion is advised.
# fill_protos. This hasn't been changed since the original Fatal,
# and so should always be the same.
my %protos = (
'$' => [ [ 1, '$_[0]' ] ],
'$$' => [ [ 2, '$_[0]', '$_[1]' ] ],
'$$@' => [ [ 3, '$_[0]', '$_[1]', '@_[2..$#_]' ] ],
'\$' => [ [ 1, '${$_[0]}' ] ],
'\%' => [ [ 1, '%{$_[0]}' ] ],
'\%;$*' => [ [ 1, '%{$_[0]}' ], [ 2, '%{$_[0]}', '$_[1]' ],
[ 3, '%{$_[0]}', '$_[1]', '$_[2]' ] ],
);
while (my ($proto, $code) = each %protos) {
is_deeply( [ Fatal::fill_protos($proto) ], $code, $proto);
}
# write_invocation tests
no warnings 'qw';
# Technically the outputted code varies from the classical Fatal.
# However the changes are mostly whitespace. Those that aren't are
# improvements to error messages or bug fixes.
my @write_invocation_calls = (
[
# Core # Call # Name # Void # Args
[ 1, 'CORE::open', 'open', 0, [ 1, qw($_[0]) ],
[ 2, qw($_[0] $_[1]) ],
[ 3, qw($_[0] $_[1] @_[2..$#_])]
],
q{ if (@_ == 1) {
return CORE::open($_[0]) || Carp::croak("Can't open(@_): $!") } elsif (@_ == 2) {
return CORE::open($_[0], $_[1]) || Carp::croak("Can't open(@_): $!") } elsif (@_ >= 3) {
return CORE::open($_[0], $_[1], @_[2..$#_]) || Carp::croak("Can't open(@_): $!")
}
die "Internal error: open(@_): Do not expect to get ", scalar(@_), " arguments";
}
]
);
foreach my $test (@write_invocation_calls) {
is(Fatal::write_invocation( @{ $test->[0] } ), $test->[1], 'write_inovcation');
}
# one_invocation tests.
my @one_invocation_calls = (
# Core # Call # Name # Void # Args
[
[ 1, 'CORE::open', 'open', 0, qw($_[0] $_[1] @_[2..$#_]) ],
q{return CORE::open($_[0], $_[1], @_[2..$#_]) || Carp::croak("Can't open(@_): $!")},
],
[
[ 1, 'CORE::open', 'open', 1, qw($_[0] $_[1] @_[2..$#_]) ],
q{return (defined wantarray)?CORE::open($_[0], $_[1], @_[2..$#_]):
CORE::open($_[0], $_[1], @_[2..$#_]) || Carp::croak("Can't open(@_): $!")},
],
);
foreach my $test (@one_invocation_calls) {
is(Fatal::one_invocation( @{ $test->[0] } ), $test->[1], 'one_inovcation');
}
# TODO: _make_fatal
# Since this subroutine has always started with an underscore,
# I think it's pretty clear that it's internal-only. I'm not
# testing it here, and it doesn't yet have backcompat.
|