[t][TT #1122] Convert t/op/numbert.t to PIR, mgrimes++
[parrot.git] / t / tools / pmc2cutils / 03-dump_vtable.t
blob8a7eab6ab6ea53e2402671153c96657dd6232714
1 #! perl
2 # Copyright (C) 2006-2007, Parrot Foundation.
3 # $Id$
4 # 03-dump_vtable.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 => 8;
23 use_ok('Parrot::Pmc2c::Pmc2cMain');
24 use_ok('File::Basename');
25 use_ok( 'File::Temp', qw| tempdir | );
26 use Data::Dumper;
28 my ( %opt, @include, @args );
29 my $self;
30 my $dump_file;
31 my $cwd;
33 # basic test
35     $cwd = cwd();
36     my $tdir1 = tempdir( CLEANUP => 1 );
37     ok( chdir $tdir1, 'changed to temp directory for testing' );
39     $self = Parrot::Pmc2c::Pmc2cMain->new(
40         {
41             include => \@include,
42             opt     => \%opt,
43             args    => [@args],
44             bin     => $Bin,
45         }
46     );
47     $dump_file = $self->dump_vtable("$main::topdir/src/vtable.tbl");
48     ok( -e $dump_file, "dump_vtable created vtable.dump" );
50     is( dirname($dump_file), realpath($tdir1), "vtable.dump created in expected directory" );
52     ok( chdir $cwd, "changed back to original directory" );
55 pass("Completed all tests in $0");
57 ################### DOCUMENTATION ###################
59 =head1 NAME
61 03-dump_vtable.t - test C<Parrot::Pmc2c::Pmc2cMain::dump_vtable()>
63 =head1 SYNOPSIS
65     % prove t/tools/pmc2cutils/03-dump_vtable.t
67 =head1 DESCRIPTION
69 The files in this directory test the publicly callable methods of
70 F<lib/Parrot/Pmc2c/Pmc2cMain.pm>.  By doing so, they test the functionality
71 of the F<pmc2c.pl> utility.  That functionality has largely been extracted
72 into the methods of F<Pmc2cMain.pm>.
74 F<03-dump_vtable.t> tests the C<Parrot::Pmc2c::Pmc2cMain::dump_vtable()> method.
75 F<make> calls this method when it calls in C<tools/build/pmc2c.pl --vtable>.
77 When all of F<pmc2c.pl>'s functionality was contained within that program,
78 C<dump_vtable()> was a subroutine named C<dump_default()>.  That name was
79 confusing, because it suggested that what was being 'dumped' was
80 F<src/pmc/default.pmc> -- which was not the case.  The file which this method
81 takes as an argument is F<src/vtable.tbl>; hence, the method's renaming.
83 So as not to pollute the Parrot build directories with files created
84 during the testing process, all functions which create or modify
85 files should be called within a temporary directory.
87 =head1 AUTHOR
89 James E Keenan
91 =head1 SEE ALSO
93 Parrot::Pmc2c, F<pmc2c.pl>.
95 =cut
97 # Local Variables:
98 #   mode: cperl
99 #   cperl-indent-level: 4
100 #   fill-column: 100
101 # End:
102 # vim: expandtab shiftwidth=4: