2 # Copyright (C) 2007, The Perl Foundation.
11 use Cwd qw(cwd realpath);
12 realpath($Bin) =~ m{^(.*\/parrot)\/[^/]*\/[^/]*\/[^/]*$};
14 if ( defined $topdir ) {
15 print "\nOK: Parrot top directory located\n";
18 $topdir = realpath($Bin) . "/../../..";
20 unshift @INC, qq{$topdir/lib};
22 use Test::More tests => 43;
26 use File::Temp (qw| tempdir |);
27 use_ok('Parrot::Ops2pm::Utils');
28 use lib ("$main::topdir/t/tools/ops2cutils/testlib");
35 use IO::CaptureOutput qw | capture |;
37 my @dynopsfiles = qw( src/dynoplibs/dan.ops src/dynoplibs/myops.ops );
39 ok( chdir $main::topdir, "Positioned at top-level Parrot directory" );
44 my $tdir = tempdir( CLEANUP => 1 );
45 ok( chdir $tdir, 'changed to temp directory for testing' );
47 my $tlib = generate_core( $cwd, $tdir, \@srcopsfiles, $num, $skip );
49 ok( -d $tlib, "lib directory created under tempdir" );
51 require Parrot::Ops2c::Utils;
53 foreach my $f (@dynopsfiles) {
54 copy( qq{$cwd/$f}, qq{$tdir/$f} );
56 chdir "src/dynoplibs" or croak "Unable to change to src/dynoplibs: $!";
58 test_dynops( [qw( CGoto myops.ops )] );
59 test_dynops( [qw( CGP myops.ops )] );
60 test_dynops( [qw( C myops.ops )] );
61 test_dynops( [qw( CSwitch myops.ops )] );
62 test_dynops( [qw( CGoto dan.ops )] );
63 test_dynops( [qw( CGP dan.ops )] );
64 test_dynops( [qw( C dan.ops )] );
65 test_dynops( [qw( CSwitch dan.ops )] );
68 my ($self, $stdout, $stderr);
70 sub { $self = Parrot::Ops2c::Utils->new( {
71 argv => [qw( CSwitch dan.ops dan.ops )],
72 flag => { dynamic => 1 },
78 "Constructor correctly returned when provided >= 1 arguments" );
80 qr/Ops file 'dan\.ops' mentioned more than once!/, "Error message is correct" );
82 my $c_header_file = $self->print_c_header_file();
83 ok( -e $c_header_file, "$c_header_file created" );
84 ok( -s $c_header_file, "$c_header_file has non-zero size" );
86 my $source = IO::File->new('>' . $$self{source});
87 $self->print_c_source_top($source);
88 $self->print_c_source_bottom($source);
90 ok( -s $$self{source}, "file was written" );
93 ok( chdir($cwd), "returned to starting directory" );
97 my $local_argv_ref = shift;
99 my $self = Parrot::Ops2c::Utils->new(
101 argv => $local_argv_ref,
102 flag => { dynamic => 1 },
105 ok( defined $self, "Constructor correctly returned when provided >= 1 arguments" );
107 my $c_header_file = $self->print_c_header_file();
108 ok( -e $c_header_file, "$c_header_file created" );
109 ok( -s $c_header_file, "$c_header_file has non-zero size" );
111 my $source = IO::File->new('>' . $$self{source});
112 $self->print_c_source_top($source);
113 $self->print_c_source_bottom($source);
115 ok( -s $$self{source}, "file was written" );
119 pass("Completed all tests in $0");
121 ################### DOCUMENTATION ###################
125 06-dynamic.t - test C<--dynamic> flag to F<tools/build/ops2c.pl>
129 % prove t/tools/ops2cutils/06-dynamic.t
133 The files in this directory test the publicly callable subroutines of
134 F<lib/Parrot/Ops2c/Utils.pm> and F<lib/Parrot/Ops2c/Auxiliary.pm>.
135 By doing so, they test the functionality of the F<ops2c.pl> utility.
136 That functionality has largely been extracted
137 into the methods of F<Utils.pm>.
139 All the files in this directory are intended to be run B<after>
140 F<Configure.pl> has been run but before F<make> has been called. Hence, they
141 are B<not> part of the test suite run by F<make test>. Once you have run
142 F<Configure.pl>, however, you may run these tests as part of F<make
145 F<06-dynamic.t> tests how well
146 C<Parrot::Ops2c::Utils()> works when the C<--dynamic> flag is passed to
147 F<tools/build/ops2c.pl>.
155 Parrot::Ops2c::Auxiliary, F<ops2c.pl>.
161 # cperl-indent-level: 4
164 # vim: expandtab shiftwidth=4: