Ticket #76: pipp.t

File pipp.t, 1.6 KB (added by szabgab, 6 years ago)

ext/Parrot-Embed/t/pipp.t

Line 
1#!perl
2
3# Copyright (C) 2006-2008, The Perl Foundation.
4# $Id: $
5
6use strict;
7use warnings;
8
9use Test::More;
10use File::Spec;
11
12my $pipp_pbc = File::Spec->catfile( '..', '..', 'languages', 'pipp', 'pipp.pbc' );
13plan skip_all => "Need to first run make in languages/pipp" if not -e $pipp_pbc;
14
15plan tests => 14;
16
17use_ok('Parrot::Embed') or exit;
18
19my $module = 'Parrot::Interpreter';
20my $interp = $module->new();
21ok( $interp, 'new() should return a valid interpreter' );
22isa_ok( $interp, $module );
23
24my $result = eval { $interp->load_file($pipp_pbc) };
25my $except = $@;
26ok( $result, '... returning true if it could load the file' );
27is( $except, '', '... throwing no exeption if so' );
28
29my $pipp_x = $interp->find_global( 'Pipp' );
30isa_ok( $pipp_x, 'Parrot::PMC' );
31#can_ok($pipp_x, 'invoke');
32#???
33
34my $pipp = $interp->find_global( 'pipp', 'Pipp' );
35isa_ok( $pipp, 'Parrot::PMC' );
36can_ok($pipp, 'invoke');
37
38
39my $code = <<'END_CODE';
40<?php
41function add($a, $b) {
42        return $a+$b;
43}
44?>
45END_CODE
46
47# compile some PHP code
48{
49        my $pmc = $pipp->invoke( 'PS', $code );
50        ok( $pmc, 'invoke() should return a PMC, given that signature' );
51        is( $pmc->get_string(), 1, 'string returned in the PMC should be true?' );
52}
53
54
55# invoke a built-in php function
56{
57        my $pmc = $pipp->invoke( 'PS', 'strlen', 'some string' );
58        ok( $pmc, 'invoke() should return a PMC, given that signature' );
59        is( $pmc->get_string(), 11, 'value returned in the PMC' );
60}
61
62# invoke a php function
63{
64        my $pmc = $pipp->invoke( 'PS', 'add', 23, 19 );
65        ok( $pmc, 'invoke() should return a PMC, given that signature' );
66        is( $pmc->get_string(), 42, 'value returned in the PMC' );
67}