Author: jkeenan Date: Wed Oct 31 16:08:48 2007 New Revision: 22649 Added: trunk/t/configure/127-auto_byteorder-01.t (contents, props changed) trunk/t/configure/127-auto_byteorder-02.t (contents, props changed) trunk/t/configure/127-auto_byteorder-03.t (contents, props changed) Removed: trunk/t/configure/127-auto_byteorder.t Modified: trunk/MANIFEST trunk/config/auto/byteorder.pm
Log: config/auto/byteorder.pm: Refactored to increase testability. Add 3 test files; remove placeholder test file Updated MANIFEST. Cf.: https://rt.perl.org/rt3/Ticket/Display.html?id=43309. Modified: trunk/MANIFEST ============================================================================== --- trunk/MANIFEST (original) +++ trunk/MANIFEST Wed Oct 31 16:08:48 2007 @@ -1,7 +1,7 @@ # ex: set ro: # $Id$ # -# generated by tools/dev/mk_manifest_and_skip.pl Wed Oct 31 22:48:47 2007 UT +# generated by tools/dev/mk_manifest_and_skip.pl Wed Oct 31 23:05:08 2007 UT # # See tools/dev/install_files.pl for documentation on the # format of this file. @@ -3061,7 +3061,9 @@ t/configure/124-auto_alignptrs-01.t [] t/configure/125-auto_headers-01.t [] t/configure/126-auto_sizes-01.t [] -t/configure/127-auto_byteorder.t [] +t/configure/127-auto_byteorder-01.t [] +t/configure/127-auto_byteorder-02.t [] +t/configure/127-auto_byteorder-03.t [] t/configure/128-auto_va_ptr.t [] t/configure/129-auto_pack.t [] t/configure/130-auto_format.t [] Modified: trunk/config/auto/byteorder.pm ============================================================================== --- trunk/config/auto/byteorder.pm (original) +++ trunk/config/auto/byteorder.pm Wed Oct 31 16:08:48 2007 @@ -32,13 +32,25 @@ sub runstep { my ( $self, $conf ) = @_; + my $byteorder = _probe_for_byteorder(); + + $self->_evaluate_byteorder($conf, $byteorder); + + return 1; +} + +sub _probe_for_byteorder { cc_gen('config/auto/byteorder/test_c.in'); cc_build(); - my $byteorder = cc_run() or die "Can't run the byteorder testing program: $!"; + my $byteorder = cc_run() + or die "Can't run the byteorder testing program: $!"; cc_clean(); - chomp $byteorder; + return $byteorder; +} +sub _evaluate_byteorder { + my ($self, $conf, $byteorder) = @_; if ( $byteorder =~ /^1234/ ) { $conf->data->set( byteorder => $byteorder, @@ -56,7 +68,6 @@ else { die "Unsupported byte-order [$byteorder]!"; } - return 1; } Added: trunk/t/configure/127-auto_byteorder-01.t ============================================================================== --- (empty file) +++ trunk/t/configure/127-auto_byteorder-01.t Wed Oct 31 16:08:48 2007 @@ -0,0 +1,83 @@ +#! perl +# Copyright (C) 2007, The Perl Foundation. +# $Id$ +# 127-auto_byteorder-01.t + +use strict; +use warnings; +use Test::More tests => 14; +use Carp; +use lib qw( lib t/configure/testlib ); +use_ok('config::init::defaults'); +use_ok('config::auto::byteorder'); +use Parrot::Configure; +use Parrot::Configure::Options qw( process_options ); +use Parrot::Configure::Test qw( test_step_thru_runstep); + +my $args = process_options( + { + argv => [ ], + mode => q{configure}, + } +); + +my $conf = Parrot::Configure->new; + +test_step_thru_runstep( $conf, q{init::defaults}, $args ); + +my $pkg = q{auto::byteorder}; + +$conf->add_steps($pkg); +$conf->options->set( %{$args} ); + +my ( $task, $step_name, @step_params, $step); +$task = $conf->steps->[1]; +$step_name = $task->step; [EMAIL PROTECTED] = @{ $task->params }; + +$step = $step_name->new(); +ok( defined $step, "$step_name constructor returned defined value" ); +isa_ok( $step, $step_name ); +ok( $step->description(), "$step_name has description" ); + +my $byteorder = q{1234}; +my $rv = $step->_evaluate_byteorder($conf, $byteorder); +ok( $rv, "_evaluate_byteorder() returned true value as expected"); +is( $conf->data->get( 'byteorder'), $byteorder, "Got expected byteorder"); +ok( ! $conf->data->get( 'bigendian' ), "Not big-endian"); +is( $step->result, 'little-endian', "Rather, little-endian"); + +pass("Completed all tests in $0"); + +################### DOCUMENTATION ################### + +=head1 NAME + +127-auto_byteorder-01.t - test config::auto::byteorder + +=head1 SYNOPSIS + + % prove t/configure/127-auto_byteorder-01.t + +=head1 DESCRIPTION + +The files in this directory test functionality used by F<Configure.pl>. + +The tests in this file test subroutines exported by config::auto::byteorder. + +=head1 AUTHOR + +James E Keenan + +=head1 SEE ALSO + +config::auto::byteorder, F<Configure.pl>. + +=cut + +# Local Variables: +# mode: cperl +# cperl-indent-level: 4 +# fill-column: 100 +# End: +# vim: expandtab shiftwidth=4: Added: trunk/t/configure/127-auto_byteorder-02.t ============================================================================== --- (empty file) +++ trunk/t/configure/127-auto_byteorder-02.t Wed Oct 31 16:08:48 2007 @@ -0,0 +1,92 @@ +#! perl +# Copyright (C) 2007, The Perl Foundation. +# $Id$ +# 127-auto_byteorder-02.t + +use strict; +use warnings; +use Test::More tests => 18; +use Carp; +use lib qw( lib t/configure/testlib ); +use_ok('config::init::defaults'); +use_ok('config::auto::byteorder'); +use Parrot::Configure; +use Parrot::Configure::Options qw( process_options ); +use Parrot::Configure::Test qw( test_step_thru_runstep); + +my $args = process_options( + { + argv => [ ], + mode => q{configure}, + } +); + +my $conf = Parrot::Configure->new; + +test_step_thru_runstep( $conf, q{init::defaults}, $args ); + +my $pkg = q{auto::byteorder}; + +$conf->add_steps($pkg); +$conf->options->set( %{$args} ); + +my ( $task, $step_name, @step_params, $step); +$task = $conf->steps->[1]; +$step_name = $task->step; [EMAIL PROTECTED] = @{ $task->params }; + +$step = $step_name->new(); +ok( defined $step, "$step_name constructor returned defined value" ); +isa_ok( $step, $step_name ); +ok( $step->description(), "$step_name has description" ); + +my ($byteorder, $rv); + +$byteorder = q{8765}; +$rv = $step->_evaluate_byteorder($conf, $byteorder); +ok( $rv, "_evaluate_byteorder() returned true value as expected"); +is( $conf->data->get( 'byteorder'), $byteorder, "Got expected byteorder"); +ok( $conf->data->get( 'bigendian' ), "Not big-endian"); +is( $step->result, 'big-endian', "Indeed, big-endian"); + +$byteorder = q{4321}; +$rv = $step->_evaluate_byteorder($conf, $byteorder); +ok( $rv, "_evaluate_byteorder() returned true value as expected"); +is( $conf->data->get( 'byteorder'), $byteorder, "Got expected byteorder"); +ok( $conf->data->get( 'bigendian' ), "Not big-endian"); +is( $step->result, 'big-endian', "Indeed, big-endian"); + +pass("Completed all tests in $0"); + +################### DOCUMENTATION ################### + +=head1 NAME + +127-auto_byteorder-02.t - test config::auto::byteorder + +=head1 SYNOPSIS + + % prove t/configure/127-auto_byteorder-02.t + +=head1 DESCRIPTION + +The files in this directory test functionality used by F<Configure.pl>. + +The tests in this file test subroutines exported by config::auto::byteorder. + +=head1 AUTHOR + +James E Keenan + +=head1 SEE ALSO + +config::auto::byteorder, F<Configure.pl>. + +=cut + +# Local Variables: +# mode: cperl +# cperl-indent-level: 4 +# fill-column: 100 +# End: +# vim: expandtab shiftwidth=4: Added: trunk/t/configure/127-auto_byteorder-03.t ============================================================================== --- (empty file) +++ trunk/t/configure/127-auto_byteorder-03.t Wed Oct 31 16:08:48 2007 @@ -0,0 +1,86 @@ +#! perl +# Copyright (C) 2007, The Perl Foundation. +# $Id$ +# 127-auto_byteorder-03.t + +use strict; +use warnings; +use Test::More qw(no_plan); # tests => 18; +use Carp; +use lib qw( lib t/configure/testlib ); +use_ok('config::init::defaults'); +use_ok('config::auto::byteorder'); +use Parrot::Configure; +use Parrot::Configure::Options qw( process_options ); +use Parrot::Configure::Test qw( test_step_thru_runstep); + +my $args = process_options( + { + argv => [ ], + mode => q{configure}, + } +); + +my $conf = Parrot::Configure->new; + +test_step_thru_runstep( $conf, q{init::defaults}, $args ); + +my $pkg = q{auto::byteorder}; + +$conf->add_steps($pkg); +$conf->options->set( %{$args} ); + +my ( $task, $step_name, @step_params, $step); +$task = $conf->steps->[1]; +$step_name = $task->step; [EMAIL PROTECTED] = @{ $task->params }; + +$step = $step_name->new(); +ok( defined $step, "$step_name constructor returned defined value" ); +isa_ok( $step, $step_name ); +ok( $step->description(), "$step_name has description" ); + +my ($byteorder, $rv); + +$byteorder = q{foobar}; +eval { + $rv = $step->_evaluate_byteorder($conf, $byteorder); +}; +like($@, + qr/Unsupported byte-order \[$byteorder\]!/, + "Got error message expected with bad byte-order"); + +pass("Completed all tests in $0"); + +################### DOCUMENTATION ################### + +=head1 NAME + +127-auto_byteorder-03.t - test config::auto::byteorder + +=head1 SYNOPSIS + + % prove t/configure/127-auto_byteorder-03.t + +=head1 DESCRIPTION + +The files in this directory test functionality used by F<Configure.pl>. + +The tests in this file test subroutines exported by config::auto::byteorder. + +=head1 AUTHOR + +James E Keenan + +=head1 SEE ALSO + +config::auto::byteorder, F<Configure.pl>. + +=cut + +# Local Variables: +# mode: cperl +# cperl-indent-level: 4 +# fill-column: 100 +# End: +# vim: expandtab shiftwidth=4: