Author: jkeenan
Date: Sat Apr 14 06:47:21 2007
New Revision: 18188

Added:
   branches/reconfigure/t/configure/06-bad_step.t   (contents, props changed)
   branches/reconfigure/t/configure/07-verbose_two.t   (contents, props changed)

Log:
Add two test files:  one for the failure case of passing a non-existent step;
the other for using option --verbose=2.


Added: branches/reconfigure/t/configure/06-bad_step.t
==============================================================================
--- (empty file)
+++ branches/reconfigure/t/configure/06-bad_step.t      Sat Apr 14 06:47:21 2007
@@ -0,0 +1,107 @@
+#! perl
+# Copyright (C) 2007, The Perl Foundation.
+# $Id$
+# 06-bad_step.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 => 13;
+use Carp;
+#use Data::Dumper;
+#$Data::Dumper::Indent=1;
+use Parrot::BuildUtil;
+use Parrot::Configure;
+use Parrot::Configure::Options qw( process_options );
+use Parrot::IO::Capture::Mini;
+
+my $parrot_version = Parrot::BuildUtil::parrot_version();
+like($parrot_version, qr/\d+\.\d+\.\d+/,
+    "Parrot version is in 3-part format");
+
+$| = 1;
+is($|, 1, "output autoflush is set");
+
+my $args = process_options( {
+    argv            => [],
+    script          => $0,
+    parrot_version  => $parrot_version,
+    svnid           => '$Id$',
+} );
+ok(defined $args, "process_options returned successfully");
+my %args = %$args;
+
+my $conf = Parrot::Configure->new;
+ok(defined $conf, "Parrot::Configure->new() returned okay");
+
+my $badstep = q{bad::step};
+my $badsteppath = q{bad/step.pm};
+
+$conf->add_steps( $badstep );
+my @confsteps = @{$conf->steps};
+isnt(scalar @confsteps, 0,
+    "Parrot::Configure object 'steps' key holds non-empty array reference");
+is(scalar @confsteps, 1,
+    "Parrot::Configure object 'steps' key holds ref to 1-element array");
+my $nontaskcount = 0;
+foreach my $k (@confsteps) {
+    $nontaskcount++ unless $k->isa("Parrot::Configure::Task");
+}
+is($nontaskcount, 0, "Each step is a Parrot::Configure::Task object");
+is($confsteps[0]->step, $badstep, 
+    "'step' element of Parrot::Configure::Task struct identified");
+is(ref($confsteps[0]->params), 'ARRAY',
+    "'params' element of Parrot::Configure::Task struct is array ref");
+ok(! ref($confsteps[0]->object),
+    "'object' element of Parrot::Configure::Task struct is not yet a ref");
+
+$conf->options->set(%args);
+is($conf->options->{c}->{debugging}, 1,
+    "command-line option '--debugging' has been stored in object");
+
+my $rv;
+eval { $rv = $conf->runsteps; };
+like($@, qr/Can't locate $badsteppath in [EMAIL PROTECTED]/,  #'
+    "Got expected die message when runsteps() called with nonexistent step");
+
+pass("Completed all tests in $0");
+
+################### DOCUMENTATION ###################
+
+=head1 NAME
+
+06-bad_step.t - test bad step failure case in Parrot::Configure
+
+=head1 SYNOPSIS
+
+    % prove t/configure/components/06-bad_step.t
+
+=head1 DESCRIPTION
+
+The files in this directory test functionality used by F<Configure.pl>.
+
+The tests in this file examine what happens when you attempt to do a
+C<runsteps> on a non-existent step.
+
+=head1 AUTHOR
+
+James E Keenan
+
+=head1 SEE ALSO
+
+Parrot::Configure, F<Configure.pl>.
+
+=cut

Added: branches/reconfigure/t/configure/07-verbose_two.t
==============================================================================
--- (empty file)
+++ branches/reconfigure/t/configure/07-verbose_two.t   Sat Apr 14 06:47:21 2007
@@ -0,0 +1,117 @@
+#! perl
+# Copyright (C) 2007, The Perl Foundation.
+# $Id$
+# 07-verbose_two.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 => 14;
+use Carp;
+use Data::Dumper;
+$Data::Dumper::Indent=1;
+use Parrot::BuildUtil;
+use Parrot::Configure;
+use Parrot::Configure::Options qw( process_options );
+use Parrot::IO::Capture::Mini;
+
+my $parrot_version = Parrot::BuildUtil::parrot_version();
+like($parrot_version, qr/\d+\.\d+\.\d+/,
+    "Parrot version is in 3-part format");
+
+$| = 1;
+is($|, 1, "output autoflush is set");
+
+my $args = process_options( {
+    argv            => [ q{--verbose=2} ],
+    script          => $0,
+    parrot_version  => $parrot_version,
+    svnid           => '$Id$',
+} );
+ok(defined $args, "process_options returned successfully");
+my %args = %$args;
+
+my $conf = Parrot::Configure->new;
+ok(defined $conf, "Parrot::Configure->new() returned okay");
+
+my $step = q{init::manifest};
+# Following assignment would change if config/init/manifest.pm changed.
+my $description = q{Checking MANIFEST};
+
+$conf->add_steps( $step );
+my @confsteps = @{$conf->steps};
+isnt(scalar @confsteps, 0,
+    "Parrot::Configure object 'steps' key holds non-empty array reference");
+is(scalar @confsteps, 1,
+    "Parrot::Configure object 'steps' key holds ref to 1-element array");
+my $nontaskcount = 0;
+foreach my $k (@confsteps) {
+    $nontaskcount++ unless $k->isa("Parrot::Configure::Task");
+}
+is($nontaskcount, 0, "Each step is a Parrot::Configure::Task object");
+is($confsteps[0]->step, $step, 
+    "'step' element of Parrot::Configure::Task struct identified");
+is(ref($confsteps[0]->params), 'ARRAY',
+    "'params' element of Parrot::Configure::Task struct is array ref");
+ok(! ref($confsteps[0]->object),
+    "'object' element of Parrot::Configure::Task struct is not yet a ref");
+
+$conf->options->set(%args);
+is($conf->options->{c}->{debugging}, 1,
+    "command-line option '--debugging' has been stored in object");
+
+my $rv;
+my ($tie, @lines);
+{
+    $tie = tie *STDOUT, "Parrot::IO::Capture::Mini"
+        or croak "Unable to tie";
+    $rv = $conf->runsteps;
+    @lines = $tie->READLINE;
+}
+ok($rv, "runsteps successfully ran $step");
+my $bigmsg = join q{}, @lines;
+like($bigmsg,
+    qr/$description\.\.\..*done.*Setting Configuration Data.*verbose.*2/s,
+    "Got message expected upon running $step");
+
+pass("Completed all tests in $0");
+
+################### DOCUMENTATION ###################
+
+=head1 NAME
+
+07-verbose_two.t - test bad step failure case in Parrot::Configure
+
+=head1 SYNOPSIS
+
+    % prove t/configure/components/07-verbose_two.t
+
+=head1 DESCRIPTION
+
+The files in this directory test functionality used by F<Configure.pl>.
+
+The tests in this file examine what happens when you configure with the
+<--verbose> option set to C<2>.
+
+=head1 AUTHOR
+
+James E Keenan
+
+=head1 SEE ALSO
+
+Parrot::Configure, F<Configure.pl>.
+
+=cut

Reply via email to