tagged release 0.6.4
[parrot.git] / t / tools / ops2cutils / 07-make_incdir.t
blobc24b396418d44daff42e2d42ff4aebcb671879ed
1 #! perl
2 # Copyright (C) 2007, The Perl Foundation.
3 # $Id$
4 # 07-make_incdir.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 => 7;
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", "./lib" );
29 use GenerateCore qw|
30     generate_core
31     @srcopsfiles
32     $num
33     $skip
36 ok( chdir $main::topdir, "Positioned at top-level Parrot directory" );
37 my $cwd = cwd();
40     my $tdir = tempdir( CLEANUP => 1 );
41     ok( chdir $tdir, 'changed to temp directory for testing' );
43     mkdir qq{$tdir/src};
44     mkdir qq{$tdir/src/ops};
45     mkdir qq{$tdir/src/dynoplibs};
47     foreach my $f (@srcopsfiles) {
48         copy( qq{$cwd/$f}, qq{$tdir/$f} );
49     }
50     copy( qq{$cwd/$num},  qq{$tdir/$num} );
51     copy( qq{$cwd/$skip}, qq{$tdir/$skip} );
52     my @opsfiles = glob("./src/ops/*.ops");
54     mkdir qq{$tdir/lib};
55     mkdir qq{$tdir/lib/Parrot};
56     mkdir qq{$tdir/lib/Parrot/Ops2c};
57     mkdir qq{$tdir/include};
58     mkdir qq{$tdir/include/parrot};
60     my $o2p = Parrot::Ops2pm::Utils->new(
61         {
62             argv   => [@opsfiles],
63             script => "tools/build/ops2pm.pl",
64             moddir => "lib/Parrot/OpLib",
65             module => "core.pm",
66         }
67     );
69     $o2p->prepare_ops();
70     $o2p->load_op_map_files();
71     $o2p->sort_ops();
72     $o2p->prepare_real_ops();
73     $o2p->print_module();
75     croak "Temporary core.pm file not written"
76         unless ( -f qq|$tdir/$o2p->{moddir}/$o2p->{module}| );
78     my $tlib = qq{$tdir/lib};
79     ok( -d $tlib, "lib directory created under tempdir" );
80     unshift @INC, $tlib;
81     require Parrot::Ops2c::Utils;
83     {
84         local @ARGV = qw( C CGoto CGP CSwitch CPrederef );
85         my $self = Parrot::Ops2c::Utils->new(
86             {
87                 argv => [@ARGV],
88                 flag => { core => 1 },
89             }
90         );
91         ok( defined $self,
92             "Constructor correctly returned even though include/parrot/oplib had to be created" );
93     }
94     ok( chdir($cwd), "returned to starting directory" );
97 pass("Completed all tests in $0");
99 sub test_single_trans {
100     my $trans = shift;
101     my %available = map { $_, 1 } qw( C CGoto CGP CSwitch CPrederef );
102     croak "Bad argument $trans to test_single_trans()"
103         unless $available{$trans};
105     my $self = Parrot::Ops2c::Utils->new(
106         {
107             argv => [$trans],
108             flag => { core => 1 },
109         }
110     );
111     ok( defined $self, "Constructor correct when provided with single argument $trans" );
114 ################### DOCUMENTATION ###################
116 =head1 NAME
118 07-make_incdir.t - test C<Parrot::Ops2c::Utils::new()>
120 =head1 SYNOPSIS
122     % prove t/tools/ops2cutils/07-make_incdir.t
124 =head1 DESCRIPTION
126 The files in this directory test the publicly callable subroutines of
127 F<lib/Parrot/Ops2c/Utils.pm> and F<lib/Parrot/Ops2c/Auxiliary.pm>.
128 By doing so, they test the functionality of the F<ops2c.pl> utility.
129 That functionality has largely been extracted
130 into the methods of F<Utils.pm>.
132 All the files in this directory are intended to be run B<after>
133 F<Configure.pl> has been run but before F<make> has been called.  Hence, they
134 are B<not> part of the test suite run by F<make test>.   Once you have run
135 F<Configure.pl>, however, you may run these tests as part of F<make
136 buildtools_tests>.
138 F<07-make_incdir.t> tests whether C<Parrot::Ops2c::Utils::new()>
139 works properly when F<include/parrot/oplib> was not previously created..
141 =head1 AUTHOR
143 James E Keenan
145 =head1 SEE ALSO
147 Parrot::Ops2c::Auxiliary, F<ops2c.pl>.
149 =cut
151 # Local Variables:
152 #   mode: cperl
153 #   cperl-indent-level: 4
154 #   fill-column: 100
155 # End:
156 # vim: expandtab shiftwidth=4: