2 # Copyright (C) 2007-2008, Parrot 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 => 42;
25 use File::Temp (qw| tempdir |);
28 use_ok('Parrot::Ops2pm');
30 use constant NUM_FILE => "src/ops/ops.num";
31 use constant SKIP_FILE => "src/ops/ops.skip";
33 ok( chdir $main::topdir, "Positioned at top-level Parrot directory" );
41 my $tdir = tempdir( CLEANUP => 1 );
42 ok( chdir $tdir, 'changed to temp directory for testing' );
43 ok( ( mkdir qq{$tdir/src} ), "able to make tempdir/src" );
44 ok( ( mkdir qq{$tdir/src/ops} ), "able to make tempdir/src" );
45 foreach my $f (@ARGV) {
46 ok( copy( qq{$cwd/$f}, qq{$tdir/$f} ), "copied .ops file" );
50 ok( copy( qq{$cwd/$num}, qq{$tdir/$num} ), "copied ops.num file" );
51 ok( copy( qq{$cwd/$skip}, qq{$tdir/$skip} ), "copied ops.skip file" );
52 my @opsfiles = glob("./src/ops/*.ops");
54 my $self = Parrot::Ops2pm->new(
57 script => "tools/build/ops2pm.pl",
60 moddir => "lib/Parrot/OpLib",
63 # inc_dir => "include/parrot/oplib",
67 isa_ok( $self, q{Parrot::Ops2pm} );
69 ok( $self->prepare_ops, "prepare_ops() returned successfully" );
70 ok( defined( $self->{ops} ), "'ops' key has been defined" );
72 ok( $self->load_op_map_files(), "load_op_map_files() completed successfully" );
73 ok( -f $num, "ops.num located after renumbering" );
74 ok( -f $skip, "ops.skip located after renumbering" );
76 ok( $self->sort_ops(), "sort_ops returned successfully" );
78 ok( $self->prepare_real_ops(), "prepare_real_ops() returned successfully" );
80 ok( $self->print_module(), "print_module() returned true" );
81 ok( -f qq{$tdir/$self->{moddir}/$self->{module}}, "core.pm file written" );
83 # Todo: test characteristics of .pm file written
85 ok( chdir $cwd, 'changed back to starting directory after testing' );
89 # --no-lines command-line option
97 my $tdir = tempdir( CLEANUP => 1 );
98 ok( chdir $tdir, 'changed to temp directory for testing' );
99 ok( ( mkdir qq{$tdir/src} ), "able to make tempdir/src" );
100 ok( ( mkdir qq{$tdir/src/ops} ), "able to make tempdir/src" );
101 foreach my $f (@ARGV) {
102 ok( copy( qq{$cwd/$f}, qq{$tdir/$f} ), "copied .ops file" );
105 my $skip = SKIP_FILE;
106 ok( copy( qq{$cwd/$num}, qq{$tdir/$num} ), "copied ops.num file" );
107 ok( copy( qq{$cwd/$skip}, qq{$tdir/$skip} ), "copied ops.skip file" );
108 my @opsfiles = glob("./src/ops/*.ops");
110 my $self = Parrot::Ops2pm->new(
113 script => "tools/build/ops2pm.pl",
116 moddir => "lib/Parrot/OpLib",
119 # inc_dir => "include/parrot/oplib",
123 isa_ok( $self, q{Parrot::Ops2pm} );
125 ok( $self->prepare_ops, "prepare_ops() returned successfully" );
126 ok( defined( $self->{ops} ), "'ops' key has been defined" );
128 ok( $self->load_op_map_files(), "load_op_map_files() completed successfully" );
129 ok( -f $num, "ops.num located after renumbering" );
130 ok( -f $skip, "ops.skip located after renumbering" );
132 ok( $self->sort_ops(), "sort_ops returned successfully" );
134 ok( $self->prepare_real_ops(), "prepare_real_ops() returned successfully" );
136 ok( $self->print_module(), "print_module() returned true" );
137 ok( -f qq{$tdir/$self->{moddir}/$self->{module}}, "core.pm file written" );
139 my $fhin = IO::File->new();
140 ok( ( $fhin->open("<$tdir/$self->{moddir}/$self->{module}") ),
141 "Able to open file for reading" );
147 ok( $fhin->close(), "Able to close file after reading" );
148 unlike( $corepm, qr/#line/, "No '#line' directives found in generated C code" );
150 # Todo: more tests of characteristics of .pm file written
152 ok( chdir $cwd, 'changed back to starting directory after testing' );
156 pass("Completed all tests in $0");
158 ################### DOCUMENTATION ###################
162 10-print_module.t - test C<Parrot::Ops2pm::print_module()>
166 % prove t/tools/ops2pm/10-print_module.t
170 The files in this directory test the publicly callable methods of
171 F<lib/Parrot/Ops2pm.pm> and F<lib/Parrot/Ops2pm/Auxiliary.pm>.
172 By doing so, they test the functionality of the F<ops2pm.pl> utility.
173 That functionality has largely been extracted
174 into the methods of F<Utils.pm>.
176 F<10-print_module.t> tests whether
177 C<Parrot::Ops2pm::print_module()> works properly.
181 The following statements, branches and conditions in C<print_module()>
182 are as yet uncovered:
188 Directory failure: can it be provoked?
190 if ( !-d $fulldir ) {
191 File::Path::mkpath( [ $fulldir ], 0, 0755 )
192 or die "$self->{script}: Could not mkdir $fulldir: $!!\n";
203 Parrot::Ops2pm, F<ops2pm.pl>.
209 # cperl-indent-level: 4
212 # vim: expandtab shiftwidth=4: