summaryrefslogtreecommitdiff
path: root/ext/XS-APItest/t/newCONSTSUB.t
blob: 286f9a23755b4f18be80c04c960fb5d9b83428eb (plain)
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
#!perl

use strict;
use warnings;
use utf8;
use open qw( :utf8 :std );
use Test::More tests => 9;

use XS::APItest;

my ($const, $glob) = XS::APItest::newCONSTSUB_type(\%::, "sanity_check", 0, 0);

ok $const;
ok *{$glob}{CODE};

($const, $glob) = XS::APItest::newCONSTSUB_type(\%::, "\x{30cb}", 0, 0);
ok $const, "newCONSTSUB generates the constant,";
ok *{$glob}{CODE}, "..and the glob,";
ok !$::{"\x{30cb}"}, "...but not the right one";

($const, $glob) = XS::APItest::newCONSTSUB_type(\%::, "\x{30cd}", 0, 1);
ok $const, "newCONSTSUB_flags generates the constant,";
ok *{$glob}{CODE}, "..and the glob,";
ok $::{"\x{30cd}"}, "...the right one!";

eval q{
 BEGIN {
  no warnings;
  my $w;
  local $SIG{__WARN__} = sub { $w .= shift };
  *foo = sub(){123};
  newCONSTSUB_type(\%::, "foo", 0, 1);
  is $w, undef, 'newCONSTSUB uses calling scope for redefinition warnings';
 }
};