tagged release 0.6.4
[parrot.git] / t / tools / ops2cutils / 04-print_c_source_top.t
blob912e4b43bc173eeac3d524d4a99aa57c1adae646
1 #! perl
2 # Copyright (C) 2007, The Perl Foundation.
3 # $Id$
4 # 04-print_c_source_top.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 => 26;
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
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     my $tlib = generate_core( $cwd, $tdir, \@srcopsfiles, $num, $skip );
45     ok( -d $tlib, "lib directory created under tempdir" );
46     unshift @INC, $tlib;
47     require Parrot::Ops2c::Utils;
49     test_print_c_source_top( [qw( C )] );
50     test_print_c_source_top( [qw( CGoto )] );
51     test_print_c_source_top( [qw( CGP )] );
52     test_print_c_source_top( [qw( CSwitch )] );
53     test_print_c_source_top( [qw( C CGoto CGP CSwitch CPrederef )] );
55     ok( chdir($cwd), "returned to starting directory" );
58 sub test_print_c_source_top {
59     my $local_argv_ref = shift;
60     {
61         my $self = Parrot::Ops2c::Utils->new(
62             {
63                 argv => $local_argv_ref,
64                 flag => { core => 1 },
65             }
66         );
67         ok( defined $self,
68             "Constructor correctly returned when provided with argument(s): @{$local_argv_ref}" );
70         my $c_header_file = $self->print_c_header_file();
71         ok( -e $c_header_file, "$c_header_file created" );
72         ok( -s $c_header_file, "$c_header_file has non-zero size" );
74         my $source = IO::File->new('>' . $$self{source});
75         $self->print_c_source_top($source);
76         ok( -s $source, "print_c_source_top printed something to the file" );
77     }
80 pass("Completed all tests in $0");
82 ################### DOCUMENTATION ###################
84 =head1 NAME
86 04-print_c_source_top.t - test C<Parrot::Ops2c::Utils::print_c_source_top()>
88 =head1 SYNOPSIS
90     % prove t/tools/ops2cutils/04-print_c_source_top.t
92 =head1 DESCRIPTION
94 The files in this directory test the publicly callable subroutines of
95 F<lib/Parrot/Ops2c/Utils.pm> and F<lib/Parrot/Ops2c/Auxiliary.pm>.
96 By doing so, they test the functionality of the F<ops2c.pl> utility.
97 That functionality has largely been extracted
98 into the methods of F<Utils.pm>.
100 All the files in this directory are intended to be run B<after>
101 F<Configure.pl> has been run but before F<make> has been called.  Hence, they
102 are B<not> part of the test suite run by F<make test>.   Once you have run
103 F<Configure.pl>, however, you may run these tests as part of F<make
104 buildtools_tests>.
106 F<04-print_c_source_top.t> tests whether
107 C<Parrot::Ops2c::Utils::print_c_source_top()> work properly.
109 =head1 AUTHOR
111 James E Keenan
113 =head1 SEE ALSO
115 Parrot::Ops2c::Auxiliary, F<ops2c.pl>.
117 =cut
119 # Local Variables:
120 #   mode: cperl
121 #   cperl-indent-level: 4
122 #   fill-column: 100
123 # End:
124 # vim: expandtab shiftwidth=4: