Author: jkeenan Date: Mon Feb 12 19:28:11 2007 New Revision: 16960 Added: branches/buildtools/t/tools/ops2cutils/03-print_c_header_file.t Modified: branches/buildtools/t/tools/ops2cutils/01-new.t
Log: Created t/tools/ops2cutils/03-print_c_header_file.t to test Parrot::Ops2c::Utils::print_c_header_file(). Modified: branches/buildtools/t/tools/ops2cutils/01-new.t ============================================================================== --- branches/buildtools/t/tools/ops2cutils/01-new.t (original) +++ branches/buildtools/t/tools/ops2cutils/01-new.t Mon Feb 12 19:28:11 2007 @@ -1,6 +1,6 @@ #! perl # Copyright (C) 2006, The Perl Foundation. -# $Id: 01-new.t 16894 2007-02-04 22:54:29Z jkeenan $ +# $Id$ # 01-new.t use strict; @@ -17,7 +17,7 @@ } unshift @INC, qq{$topdir/lib}; } -use Test::More qw(no_plan); # tests => 30; +use Test::More tests => 20; use Carp; use Cwd; use File::Copy; @@ -82,18 +82,14 @@ "Got correct error message"); } + test_single_trans(q{C}); + test_single_trans(q{CGoto}); + test_single_trans(q{CGP}); + test_single_trans(q{CSwitch}); + test_single_trans(q{CPrederef}); + { - local @ARGV = qw( C ); - my $self = Parrot::Ops2c::Utils->new( { - argv => [ @ARGV ], - flag => { core => 1 }, - } ); - ok(defined $self, - "Constructor correctly returned when provided 1 argument"); - } - - { - local @ARGV = qw( C CGoto CGP CSwitch CPrederef); + local @ARGV = qw( C CGoto CGP CSwitch CPrederef ); my $self = Parrot::Ops2c::Utils->new( { argv => [ @ARGV ], flag => { core => 1 }, @@ -123,6 +119,20 @@ pass("Completed all tests in $0"); +sub test_single_trans { + my $trans = shift; + my %available = map {$_, 1} qw( C CGoto CGP CSwitch CPrederef ); + croak "Bad argument $trans to test_single_trans()" + unless $available{$trans}; + + my $self = Parrot::Ops2c::Utils->new( { + argv => [ $trans ], + flag => { core => 1 }, + } ); + ok(defined $self, + "Constructor correct when provided with single argument $trans"); +} + ################### DOCUMENTATION ################### =head1 NAME Added: branches/buildtools/t/tools/ops2cutils/03-print_c_header_file.t ============================================================================== --- (empty file) +++ branches/buildtools/t/tools/ops2cutils/03-print_c_header_file.t Mon Feb 12 19:28:11 2007 @@ -0,0 +1,142 @@ +#! perl +# Copyright (C) 2006, The Perl Foundation. +# $Id: 03-print_c_header_file.t 16948 2007-02-12 03:58:24Z jkeenan $ +# 03-print_c_header_file.t + +use strict; +use warnings; +BEGIN { + use FindBin qw($Bin); + use Cwd qw(cwd realpath); + realpath($Bin) =~ m{^(.*\/parrot)\/[^/]*\/[^/]*\/[^/]*$}; + our $topdir = $1; + if (defined $topdir) { + print "\nOK: Parrot top directory located\n"; + } else { + $topdir = realpath($Bin) . "/../../.."; + } + unshift @INC, qq{$topdir/lib}; +} +use Test::More tests => 26; +use Carp; +use Cwd; +use File::Copy; +use File::Temp (qw| tempdir |); +use_ok( 'Parrot::Ops2pm::Utils' ); +use lib ("$main::topdir/t/tools/ops2cutils/testlib"); +use_ok( "Capture" ); +use_ok( "GenerateCore", qw| generate_core | ); + +my @srcopsfiles = qw( src/ops/core.ops src/ops/bit.ops src/ops/cmp.ops +src/ops/debug.ops src/ops/experimental.ops src/ops/io.ops src/ops/math.ops +src/ops/object.ops src/ops/pic.ops src/ops/pmc.ops src/ops/set.ops +src/ops/stack.ops src/ops/stm.ops src/ops/string.ops src/ops/sys.ops +src/ops/var.ops ); +my $num = "src/ops/ops.num"; +my $skip = "src/ops/ops.skip"; + +ok(chdir $main::topdir, "Positioned at top-level Parrot directory"); +my $cwd = cwd(); +my ($msg, $tie); + +{ + my $tdir = tempdir( CLEANUP => 1 ); + ok(chdir $tdir, 'changed to temp directory for testing'); + + my $tlib = generate_core( + $cwd, $tdir, [EMAIL PROTECTED], $num, $skip); + + ok(-d $tlib, "lib directory created under tempdir"); + unshift @INC, $tlib; + require Parrot::Ops2c::Utils; + + + test_single_trans_and_header(q{C}); + test_single_trans_and_header(q{CGoto}); + test_single_trans_and_header(q{CGP}); + test_single_trans_and_header(q{CSwitch}); + test_single_trans_and_header(q{CPrederef}); + + { + local @ARGV = qw( C CGoto CGP CSwitch CPrederef ); + my $self = Parrot::Ops2c::Utils->new( { + argv => [ @ARGV ], + flag => { core => 1 }, + } ); + ok(defined $self, + "Constructor correctly returned when provided >= 1 arguments"); + my $c_header_file = $self->print_c_header_file(); + ok(-e $c_header_file, "$c_header_file created"); + ok(-s $c_header_file, "$c_header_file has non-zero size"); + } + + ok(chdir($cwd), "returned to starting directory"); +} + + +pass("Completed all tests in $0"); + +sub test_single_trans_and_header { + my $trans = shift; + my %available = map {$_, 1} qw( C CGoto CGP CSwitch CPrederef ); + croak "Bad argument $trans to test_single_trans()" + unless $available{$trans}; + + my $self = Parrot::Ops2c::Utils->new( { + argv => [ $trans ], + flag => { core => 1 }, + } ); + ok(defined $self, + "Constructor correct when provided with single argument $trans"); + my $c_header_file = $self->print_c_header_file(); + ok(-e $c_header_file, "$c_header_file created"); + ok(-s $c_header_file, "$c_header_file has non-zero size"); +} + +################### DOCUMENTATION ################### + +=head1 NAME + +03-print_c_header_file.t - test C<Parrot::Ops2c::Utils::new()> + +=head1 SYNOPSIS + + % prove t/tools/ops2cutils/03-print_c_header_file.t + +=head1 DESCRIPTION + +The files in this directory test the publicly callable subroutines of +F<lib/Parrot/Ops2c/Utils.pm> and F<lib/Parrot/Ops2c/Auxiliary.pm>. +By doing so, they test the functionality of the F<ops2c.pl> utility. +That functionality has largely been extracted +into the methods of F<Utils.pm>. + +F<03-print_c_header_file.t> tests whether C<Parrot::Ops2c::Auxiliary::Usage()> +and F<getoptions()> work properly. + +=head1 AUTHOR + +James E Keenan + +=head1 SEE ALSO + +Parrot::Ops2c::Auxiliary, F<ops2c.pl>. + +=cut + +__END__ + +#$VAR1 = []; +#$VAR2 = bless( { +# 'split_count' => 0 +# }, 'Parrot::OpTrans::CSwitch' ); +#$VAR3 = '_switch'; +#/usr/local/bin/perl tools/build/vtable_extend.pl +#/usr/local/bin/perl tools/build/ops2c.pl CGoto --core +#$VAR1 = []; +#$VAR2 = bless( {}, 'Parrot::OpTrans::CGoto' ); +#$VAR3 = '_cg'; +#/usr/local/bin/perl tools/build/ops2c.pl CGP --core +#$VAR1 = []; +#$VAR2 = bless( {}, 'Parrot::OpTrans::CGP' ); +#$VAR3 = '_cgp';