tagged release 0.6.4
[parrot.git] / t / tools / ops2cutils / 06-dynamic.t
blob86a48aa2c3c1c0c9f016c16de30c706496be2264
1 #! perl
2 # Copyright (C) 2007, The Perl Foundation.
3 # $Id$
4 # 06-dynamic.t
6 use strict;
7 use warnings;
9 BEGIN {
10     use FindBin qw($Bin);
11     use Cwd qw(cwd realpath);
12     realpath($Bin) =~ m{^(.*\/parrot)\/[^/]*\/[^/]*\/[^/]*$};
13     our $topdir = $1;
14     if ( defined $topdir ) {
15         print "\nOK:  Parrot top directory located\n";
16     }
17     else {
18         $topdir = realpath($Bin) . "/../../..";
19     }
20     unshift @INC, qq{$topdir/lib};
22 use Test::More tests => 43;
23 use Carp;
24 use Cwd;
25 use File::Copy;
26 use File::Temp (qw| tempdir |);
27 use_ok('Parrot::Ops2pm::Utils');
28 use lib ("$main::topdir/t/tools/ops2cutils/testlib");
29 use GenerateCore qw|
30     generate_core
31     @srcopsfiles
32     $num
33     $skip
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" );
40 my $cwd = cwd();
41 my ( $msg, $tie );
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" );
50     unshift @INC, $tlib;
51     require Parrot::Ops2c::Utils;
53     foreach my $f (@dynopsfiles) {
54         copy( qq{$cwd/$f}, qq{$tdir/$f} );
55     }
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 )] );
67     {
68         my ($self, $stdout, $stderr);
69         capture(
70             sub { $self = Parrot::Ops2c::Utils->new( {
71                         argv => [qw( CSwitch  dan.ops dan.ops )],
72                         flag => { dynamic => 1 },
73                 } ); },
74             \$stdout,
75             \$stderr,
76         );
77         ok( defined $self,
78             "Constructor correctly returned when provided >= 1 arguments" );
79         like( $stderr,
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);
89         $source->close();
90         ok( -s $$self{source}, "file was written" );
91     }
93     ok( chdir($cwd), "returned to starting directory" );
96 sub test_dynops {
97     my $local_argv_ref = shift;
98     {
99         my $self = Parrot::Ops2c::Utils->new(
100             {
101                 argv => $local_argv_ref,
102                 flag => { dynamic => 1 },
103             }
104         );
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);
114         $source->close();
115         ok( -s $$self{source}, "file was written" );
116     }
119 pass("Completed all tests in $0");
121 ################### DOCUMENTATION ###################
123 =head1 NAME
125 06-dynamic.t - test C<--dynamic> flag to F<tools/build/ops2c.pl>
127 =head1 SYNOPSIS
129     % prove t/tools/ops2cutils/06-dynamic.t
131 =head1 DESCRIPTION
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
143 buildtools_tests>.
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>.
149 =head1 AUTHOR
151 James E Keenan
153 =head1 SEE ALSO
155 Parrot::Ops2c::Auxiliary, F<ops2c.pl>.
157 =cut
159 # Local Variables:
160 #   mode: cperl
161 #   cperl-indent-level: 4
162 #   fill-column: 100
163 # End:
164 # vim: expandtab shiftwidth=4: