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 / call.t
1 ################################################################################
2 #
3 #            !!!!!   Do NOT edit this file directly!   !!!!!
4 #
5 #            Edit mktests.PL and/or parts/inc/call 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 (52) {
34     load();
35     plan(tests => 52);
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 sub eq_array
52 {
53   my($a, $b) = @_;
54   join(':', @$a) eq join(':', @$b);
55 }
56
57 sub f
58 {
59   shift;
60   unshift @_, 'b';
61   pop @_;
62   @_, defined wantarray ? wantarray ? 'x' : 'y' : 'z';
63 }
64
65 my $obj = bless [], 'Foo';
66
67 sub Foo::meth
68 {
69   return 'bad_self' unless @_ && ref $_[0] && ref($_[0]) eq 'Foo';
70   shift;
71   shift;
72   unshift @_, 'b';
73   pop @_;
74   @_, defined wantarray ? wantarray ? 'x' : 'y' : 'z';
75 }
76
77 my $test;
78
79 for $test (
80     # flags                      args           expected         description
81     [ &Devel::PPPort::G_SCALAR,  [ ],           [ qw(y 1) ],     '0 args, G_SCALAR'  ],
82     [ &Devel::PPPort::G_SCALAR,  [ qw(a p q) ], [ qw(y 1) ],     '3 args, G_SCALAR'  ],
83     [ &Devel::PPPort::G_ARRAY,   [ ],           [ qw(x 1) ],     '0 args, G_ARRAY'   ],
84     [ &Devel::PPPort::G_ARRAY,   [ qw(a p q) ], [ qw(b p x 3) ], '3 args, G_ARRAY'   ],
85     [ &Devel::PPPort::G_DISCARD, [ ],           [ qw(0) ],       '0 args, G_DISCARD' ],
86     [ &Devel::PPPort::G_DISCARD, [ qw(a p q) ], [ qw(0) ],       '3 args, G_DISCARD' ],
87 )
88 {
89     my ($flags, $args, $expected, $description) = @$test;
90     print "# --- $description ---\n";
91     ok(eq_array( [ &Devel::PPPort::call_sv(\&f, $flags, @$args) ], $expected));
92     ok(eq_array( [ &Devel::PPPort::call_sv(*f,  $flags, @$args) ], $expected));
93     ok(eq_array( [ &Devel::PPPort::call_sv('f', $flags, @$args) ], $expected));
94     ok(eq_array( [ &Devel::PPPort::call_pv('f', $flags, @$args) ], $expected));
95     ok(eq_array( [ &Devel::PPPort::call_argv('f', $flags, @$args) ], $expected));
96     ok(eq_array( [ &Devel::PPPort::eval_sv("f(qw(@$args))", $flags) ], $expected));
97     ok(eq_array( [ &Devel::PPPort::call_method('meth', $flags, $obj, @$args) ], $expected));
98     ok(eq_array( [ &Devel::PPPort::call_sv_G_METHOD('meth', $flags, $obj, @$args) ], $expected));
99 };
100
101 ok(&Devel::PPPort::eval_pv('f()', 0), 'y');
102 ok(&Devel::PPPort::eval_pv('f(qw(a b c))', 0), 'y');
103
104 ok(!defined $::{'less::'}, 1, "Hadn't loaded less yet");
105 Devel::PPPort::load_module(0, "less", undef);
106 ok(defined $::{'less::'}, 1, "Have now loaded less");
107