This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Devel;:PPPort: Skip tests invalid on EBCDIC
[perl5.git] / dist / Devel-PPPort / t / magic.t
1 ################################################################################
2 #
3 #            !!!!!   Do NOT edit this file directly!   !!!!!
4 #
5 #            Edit mktests.PL and/or parts/inc/magic 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 (23) {
34     load();
35     plan(tests => 23);
36   }
37 }
38
39 use Devel::PPPort;
40 use strict;
41 $^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 # Find proper magic
52 ok(my $obj1 = Devel::PPPort->new_with_mg());
53 ok(Devel::PPPort::as_string($obj1), 'hello');
54
55 # Find with no magic
56 my $obj = bless {}, 'Fake::Class';
57 ok(Devel::PPPort::as_string($obj), "Sorry, your princess is in another castle.");
58
59 # Find with other magic (not the magic we are looking for)
60 ok($obj = Devel::PPPort->new_with_other_mg());
61 ok(Devel::PPPort::as_string($obj), "Sorry, your princess is in another castle.");
62
63 # Okay, attempt to remove magic that isn't there
64 Devel::PPPort::remove_other_magic($obj1);
65 ok(Devel::PPPort::as_string($obj1), 'hello');
66
67 # Remove magic that IS there
68 Devel::PPPort::remove_null_magic($obj1);
69 ok(Devel::PPPort::as_string($obj1), "Sorry, your princess is in another castle.");
70
71 # Removing when no magic present
72 Devel::PPPort::remove_null_magic($obj1);
73 ok(Devel::PPPort::as_string($obj1), "Sorry, your princess is in another castle.");
74
75 use Tie::Hash;
76 my %h;
77 tie %h, 'Tie::StdHash';
78 $h{foo} = 'foo';
79 $h{bar} = '';
80
81 &Devel::PPPort::sv_catpv_mg($h{foo}, 'bar');
82 ok($h{foo}, 'foobar');
83
84 &Devel::PPPort::sv_catpvn_mg($h{bar}, 'baz');
85 ok($h{bar}, 'baz');
86
87 &Devel::PPPort::sv_catsv_mg($h{foo}, '42');
88 ok($h{foo}, 'foobar42');
89
90 &Devel::PPPort::sv_setiv_mg($h{bar}, 42);
91 ok($h{bar}, 42);
92
93 &Devel::PPPort::sv_setnv_mg($h{PI}, 3.14159);
94 ok(abs($h{PI} - 3.14159) < 0.01);
95
96 &Devel::PPPort::sv_setpv_mg($h{mhx}, 'mhx');
97 ok($h{mhx}, 'mhx');
98
99 &Devel::PPPort::sv_setpvn_mg($h{mhx}, 'Marcus');
100 ok($h{mhx}, 'Marcus');
101
102 &Devel::PPPort::sv_setsv_mg($h{sv}, 'SV');
103 ok($h{sv}, 'SV');
104
105 &Devel::PPPort::sv_setuv_mg($h{sv}, 4711);
106 ok($h{sv}, 4711);
107
108 &Devel::PPPort::sv_usepvn_mg($h{sv}, 'Perl');
109 ok($h{sv}, 'Perl');
110
111 # v1 is treated as a bareword in older perls...
112 my $ver = do { local $SIG{'__WARN__'} = sub {}; eval qq[v1.2.0] };
113 ok($] < 5.009 || $@ eq '');
114 ok($] < 5.009 || Devel::PPPort::SvVSTRING_mg($ver));
115 ok(!Devel::PPPort::SvVSTRING_mg(4711));
116
117 my $foo = 'bar';
118 ok(Devel::PPPort::sv_magic_portable($foo));
119 ok($foo eq 'bar');
120