This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Magic flags harmonization.
[perl5.git] / t / lib / universal.t
CommitLineData
80b6a949
AB
1#!./perl
2
3# Test the Internal::* functions and other tibits in universal.c
4
5BEGIN {
6 chdir 't' if -d 't';
7 @INC = '../lib';
8 require './test.pl';
3a482d8d 9 plan( tests => 13 );
80b6a949
AB
10}
11
12for my $arg ('', 'q[]', qw( 1 undef )) {
13 fresh_perl_is(<<"----", <<'====', "Internals::* functions check their argument under func() AND &func() [perl #77776]");
14sub tryit { eval shift or warn \$@ }
15tryit "&Internals::SvREADONLY($arg)";
16tryit "&Internals::SvREFCNT($arg)";
17tryit "&Internals::hv_clear_placeholders($arg)";
18tryit "&Internals::HvREHASH($arg)";
19----
20Usage: Internals::SvREADONLY(SCALAR[, ON]) at (eval 1) line 1.
21Usage: Internals::SvREFCNT(SCALAR[, REFCOUNT]) at (eval 2) line 1.
22Usage: Internals::hv_clear_placeholders(hv) at (eval 3) line 1.
23Internals::HvREHASH $hashref at (eval 4) line 1.
24====
25}
21690b72
FC
26
27# Various conundrums with SvREADONLY
28
29$x = *foo;
30Internals::SvREADONLY $x, 1;
3e89ba19
FC
31ok Internals::SvREADONLY($x),
32 'read-only glob copies are read-only acc. to Internals::';
21690b72
FC
33eval { $x = [] };
34like $@, qr/Modification of a read-only value attempted at/,
35 'read-only glob copies';
3e89ba19
FC
36Internals::SvREADONLY($x,0);
37$x = 42;
38is $x, 42, 'Internals::SvREADONLY can turn off readonliness on globs';
39
3a482d8d
FC
40# Same thing with regexps
41$x = ${qr//};
42Internals::SvREADONLY $x, 1;
43ok Internals::SvREADONLY($x),
44 'read-only regexps are read-only acc. to Internals::';
45eval { $x = [] };
46like $@, qr/Modification of a read-only value attempted at/,
47 'read-only regexps';
48Internals::SvREADONLY($x,0);
49$x = 42;
50is $x, 42, 'Internals::SvREADONLY can turn off readonliness on regexps';
51
3e89ba19
FC
52$h{a} = __PACKAGE__;
53Internals::SvREADONLY $h{a}, 1;
54eval { $h{a} = 3 };
55like $@, qr/Modification of a read-only value attempted at/,
56 'making a COW scalar into a read-only one';
57
58$h{b} = __PACKAGE__;
59ok !Internals::SvREADONLY($h{b}),
60 'cows are not read-only acc. to Internals::';
61Internals::SvREADONLY($h{b},0);
62$h{b} =~ y/ia/ao/;
63is __PACKAGE__, 'main',
64 'turning off a cow’s readonliness did not affect sharers of the same PV';