tagged release 0.6.4
[parrot.git] / t / tools / ops2cutils / testlib / GenerateCore.pm
blob5a75cdf37a0d2a06f21e6947a980bcf20b569493
1 # Copyright (C) 2007, The Perl Foundation.
2 # $Id$
3 package GenerateCore;
4 use strict;
5 use warnings;
6 our ( @ISA, @EXPORT_OK );
7 @ISA = qw(Exporter);
9 our @srcopsfiles = qw( src/ops/core.ops src/ops/bit.ops src/ops/cmp.ops
10 src/ops/debug.ops src/ops/experimental.ops src/ops/io.ops src/ops/math.ops
11 src/ops/object.ops src/ops/pic.ops src/ops/pmc.ops src/ops/set.ops
12 src/ops/stack.ops src/ops/stm.ops src/ops/string.ops src/ops/sys.ops
13 src/ops/var.ops );
14 our $num = "src/ops/ops.num";
15 our $skip = "src/ops/ops.skip";
17 @EXPORT_OK = qw(
18 generate_core
19 @srcopsfiles
20 $num
21 $skip
23 use Carp;
24 use File::Copy;
25 use lib ("./lib");
26 use Parrot::Ops2pm::Utils;
29 sub generate_core {
30 my ( $cwd, $tdir, $srcopsref, $num_file, $skip_file ) = @_;
31 my @srcopsfiles = @$srcopsref;
32 mkdir qq{$tdir/src};
33 mkdir qq{$tdir/src/ops};
34 mkdir qq{$tdir/src/dynoplibs};
36 foreach my $f (@srcopsfiles) {
37 copy( qq{$cwd/$f}, qq{$tdir/$f} );
39 copy( qq{$cwd/$num}, qq{$tdir/$num} );
40 copy( qq{$cwd/$skip}, qq{$tdir/$skip} );
41 my @opsfiles = glob("./src/ops/*.ops");
43 mkdir qq{$tdir/lib};
44 mkdir qq{$tdir/lib/Parrot};
45 mkdir qq{$tdir/lib/Parrot/Ops2c};
46 mkdir qq{$tdir/include};
47 mkdir qq{$tdir/include/parrot};
48 mkdir qq{$tdir/include/parrot/oplib};
50 my $o2p = Parrot::Ops2pm::Utils->new(
52 argv => [@opsfiles],
53 script => "tools/build/ops2pm.pl",
54 moddir => "lib/Parrot/OpLib",
55 module => "core.pm",
59 $o2p->prepare_ops();
60 $o2p->load_op_map_files();
61 $o2p->sort_ops();
62 $o2p->prepare_real_ops();
63 $o2p->print_module();
65 croak "Temporary core.pm file not written"
66 unless ( -f qq|$tdir/$o2p->{moddir}/$o2p->{module}| );
67 return qq{$tdir/lib};
72 ################### DOCUMENTATION ###################
74 =head1 NAME
76 GenerateCore - functionality used in testing Parrot::Ops2c::Utils
78 =head1 SYNOPSIS
80 use lib ("t/tools/ops2cutils/testlib");
81 use GenerateCore qw| generate_core |;
83 @srcopsfiles = qw(
84 src/ops/core.ops src/ops/bit.ops src/ops/cmp.ops
85 src/ops/debug.ops src/ops/experimental.ops src/ops/io.ops
86 src/ops/math.ops src/ops/object.ops src/ops/pic.ops
87 src/ops/pmc.ops src/ops/set.ops src/ops/stack.ops
88 src/ops/stm.ops src/ops/string.ops src/ops/sys.ops
89 src/ops/var.ops
92 $num = "src/ops/ops.num";
93 $skip = "src/ops/ops.skip";
95 $cwd = cwd();
96 $tdir = tempdir( CLEANUP => 1 );
98 $tlib = generate_core(
99 $cwd, $tdir, \@srcopsfiles, $num, $skip);
101 =head1 DESCRIPTION
103 =head2 Purpose
105 The test suite found in F<t/tools/ops2cutils/> tests the methods of
106 Parrot::Ops2c::Utils. Those methods are invoked by Parrot build tool
107 F<tools/build/ops2c.pl>, which in turn is invoked several times by F<make>.
108 Parrot::Ops2c::Utils has as a prerequisite Parrot::OpLib::core. But
109 Parrot::OpLib::core is not part of the Parrot distribution, nor does it exist
110 at the point F<make> is called. Rather, it is created
111 during the Parrot build process prior to the first call to F<ops2c.pl>.
113 To test Parrot::Ops2c::Utils therefore requires a module which does not exist
114 'pre-F<make>'. The tests in this suite, however, are designed to be run when
115 your filesystem is in a 'post-F<Configure.pl>, pre-F<make>' state. The
116 solution to this conundrum is to create a copy of Parrot::OpLib::core which
117 exists only for the duration of a single test file.
119 This package, GenerateCore, exports upon request a single subroutine,
120 C<generate_core>, which (a) creates subdirectories needed underneath a
121 temporary directory created solely for testing purposes; then
122 (b) creates a temporary copy of Parrot::OpLib::core such that
123 C<Parrot::Ops2c::Utils::new()> can successfully execute.
125 =head2 C<generate_core()>
127 =over 4
129 =item * B<Purpose:> (See above.)
131 =item * B<Arguments:> Five scalar arguments, in this order:
133 cwd : String with full path of directory from which
134 tests are invoked (generally, the top-level
135 Parrot directory).
136 tdir : String holding full path of temporary
137 directory into which you have changed for
138 testing.
139 \@srcopsfiles : Reference to an array of F<.ops> files
140 (generally, the list of arguments to ops2c.pl
141 as invoked by make).
142 $num : Path to ops.num file.
143 $skip : Path to ops.skip file.
145 =item * B<Return Value:> String holding full path to a directory F<lib/>
146 found one level underneath the temporary directory denoted by F<tdir> above.
147 (This is the directory underneath which the temporary copy of
148 Parrot::OpLib::core is created.) The return value may be used in testing as a
149 marker for the creation of all the needed temporary subdirectories and the
150 temporary copy of Parrot::OpLib::core.
152 =back
154 =head1 DEPENDENCIES
156 =over 4
158 =item * File::Copy
160 =item * Parrot::Ops2c::Utils
162 =back
164 =head1 AUTHOR
166 James E Keenan (jkeenan@cpan.org).
168 =head1 SEE ALSO
170 =over 4
172 =item * Parrot::Ops2c::Utils
174 =item * F<tools/build/ops2c.pl>
176 =back
178 =cut
180 # Local Variables:
181 # mode: cperl
182 # cperl-indent-level: 4
183 # fill-column: 100
184 # End:
185 # vim: expandtab shiftwidth=4: