2 # Copyright (C) 2007, The Perl Foundation.
4 # 04-print_c_source_top.t
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 => 26;
26 use File::Temp (qw| tempdir |);
27 use_ok('Parrot::Ops2pm::Utils');
28 use lib ("$main::topdir/t/tools/ops2cutils/testlib");
36 ok( chdir $main::topdir, "Positioned at top-level Parrot directory" );
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" );
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;
61 my $self = Parrot::Ops2c::Utils->new(
63 argv => $local_argv_ref,
64 flag => { core => 1 },
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" );
80 pass("Completed all tests in $0");
82 ################### DOCUMENTATION ###################
86 04-print_c_source_top.t - test C<Parrot::Ops2c::Utils::print_c_source_top()>
90 % prove t/tools/ops2cutils/04-print_c_source_top.t
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
106 F<04-print_c_source_top.t> tests whether
107 C<Parrot::Ops2c::Utils::print_c_source_top()> work properly.
115 Parrot::Ops2c::Auxiliary, F<ops2c.pl>.
121 # cperl-indent-level: 4
124 # vim: expandtab shiftwidth=4: