This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Enable Perl compile-time warnings at all places
[perl5.git] / dist / Devel-PPPort / t / Sv_set.t
1 ################################################################################
2 #
3 #            !!!!!   Do NOT edit this file directly!   !!!!!
4 #
5 #            Edit mktests.PL and/or parts/inc/Sv_set instead.
6 #
7 #  This file was automatically generated from the definition files in the
8 #  parts/inc/ subdirectory by mktests.PL. To learn more about how all this
9 #  works, please read the F<HACKERS> file that came with this distribution.
10 #
11 ################################################################################
12
13 BEGIN {
14   if ($ENV{'PERL_CORE'}) {
15     chdir 't' if -d 't';
16     @INC = ('../lib', '../ext/Devel-PPPort/t') if -d '../lib' && -d '../ext';
17     require Config; import Config;
18     use vars '%Config';
19     if (" $Config{'extensions'} " !~ m[ Devel/PPPort ]) {
20       print "1..0 # Skip -- Perl configured without Devel::PPPort module\n";
21       exit 0;
22     }
23   }
24   else {
25     unshift @INC, 't';
26   }
27
28   sub load {
29     eval "use Test";
30     require 'testutil.pl' if $@;
31   }
32
33   if (15) {
34     load();
35     plan(tests => 15);
36   }
37 }
38
39 use Devel::PPPort;
40 use strict;
41 BEGIN { $^W = 1; }
42
43 package Devel::PPPort;
44 use vars '@ISA';
45 require DynaLoader;
46 @ISA = qw(DynaLoader);
47 bootstrap Devel::PPPort;
48
49 package main;
50
51 my $foo = 5;
52 ok(&Devel::PPPort::TestSvUV_set($foo, 12345), 42);
53 ok(&Devel::PPPort::TestSvPVX_const("mhx"), 43);
54 ok(&Devel::PPPort::TestSvPVX_mutable("mhx"), 44);
55
56 my $bar = [];
57
58 bless $bar, 'foo';
59 ok($bar->x(), 'foobar');
60
61 Devel::PPPort::TestSvSTASH_set($bar, 'bar');
62 ok($bar->x(), 'hacker');
63
64 if ( "$]" lt '5.007003' ) {
65     skip 'skip: no SV_NOSTEAL support', 0 for 1..10;
66 } else {
67     ok(Devel::PPPort::Test_sv_setsv_SV_NOSTEAL());
68
69     tie my $scalar, 'TieScalarCounter', 'string';
70
71     ok tied($scalar)->{fetch}, 0;
72     ok tied($scalar)->{store}, 0;
73     my $copy = Devel::PPPort::newSVsv_nomg($scalar);
74     ok tied($scalar)->{fetch}, 0;
75     ok tied($scalar)->{store}, 0;
76
77     my $fetch = $scalar;
78     ok tied($scalar)->{fetch}, 1;
79     ok tied($scalar)->{store}, 0;
80     my $copy2 = Devel::PPPort::newSVsv_nomg($scalar);
81     ok tied($scalar)->{fetch}, 1;
82     ok tied($scalar)->{store}, 0;
83     ok $copy2, 'string';
84 }
85
86 package TieScalarCounter;
87
88 sub TIESCALAR {
89     my ($class, $value) = @_;
90     return bless { fetch => 0, store => 0, value => $value }, $class;
91 }
92
93 sub FETCH {
94     my ($self) = @_;
95     $self->{fetch}++;
96     return $self->{value};
97 }
98
99 sub STORE {
100     my ($self, $value) = @_;
101     $self->{store}++;
102     $self->{value} = $value;
103 }
104
105 package foo;
106
107 sub x { 'foobar' }
108
109 package bar;
110
111 sub x { 'hacker' }
112