Permalink
Browse files

Demonstrate all execution paths through config/auto/git_describe.pm b…

…y writing

t/steps/auto/git_describe-01.t.
  • Loading branch information...
1 parent ec6c5b4 commit 8967056eac0572ba6b0c59a278a6228652345207 @jkeenan jkeenan committed Nov 14, 2010
Showing with 114 additions and 4 deletions.
  1. +2 −1 MANIFEST
  2. +3 −3 config/auto/git_describe.pm
  3. +109 −0 t/steps/auto/git_describe-01.t
View
3 MANIFEST
@@ -1,7 +1,7 @@
# ex: set ro:
# $Id$
#
-# generated by tools/dev/mk_manifest_and_skip.pl Sat Nov 13 21:48:05 2010 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Sun Nov 14 02:10:12 2010 UT
#
# See below for documentation on the format of this file.
#
@@ -1997,6 +1997,7 @@ t/steps/auto/frames-01.t [test]
t/steps/auto/gc-01.t [test]
t/steps/auto/gcc-01.t [test]
t/steps/auto/gettext-01.t [test]
+t/steps/auto/git_describe-01.t [test]
t/steps/auto/glibc-01.t [test]
t/steps/auto/gmp-01.t [test]
t/steps/auto/headers-01.t [test]
View
6 config/auto/git_describe.pm
@@ -32,17 +32,17 @@ sub runstep {
my ( $self, $conf ) = @_;
my $describe = $Parrot::Git::Describe::current;
- $conf->data->set( git_describe => $describe );
if ( defined($describe) and $describe !~ /^(RELEASE_|REL_)\d+_\d+_\d+-\d+-g[a-z0-9]+$/i ) {
die "Invalid git describe string (Git::Describe): $!";
}
+ $conf->data->set( git_describe => $describe );
if ( defined $describe ) {
- $self->set_result("$describe");
+ $self->set_result($describe);
}
else {
- $self->set_result("done");
+ $self->set_result('done');
}
return 1;
View
109 t/steps/auto/git_describe-01.t
@@ -0,0 +1,109 @@
+#! perl
+# Copyright (C) 2007, Parrot Foundation.
+# auto/git_describe-01.t
+
+use strict;
+use warnings;
+use Test::More tests => 12;
+use Carp;
+use lib qw( lib t/configure/testlib );
+use_ok('config::auto::git_describe');
+use Parrot::Configure::Options qw( process_options );
+use Parrot::Configure::Step::Test;
+use Parrot::Configure::Test qw(
+ test_step_constructor_and_description
+);
+
+########## regular ##########
+
+my ($args, $step_list_ref) = process_options(
+ {
+ argv => [ ],
+ mode => q{configure},
+ }
+);
+
+my $conf = Parrot::Configure::Step::Test->new;
+$conf->include_config_results( $args );
+my $serialized = $conf->pcfreeze();
+
+my $pkg = q{auto::git_describe};
+
+$conf->add_steps($pkg);
+$conf->options->set( %{$args} );
+my $step = test_step_constructor_and_description($conf);
+{
+ no warnings 'once';
+ local $Parrot::Git::Describe::current = undef;
+ my $ret = $step->runstep($conf);
+ ok( $ret, "runstep() returned true value" );
+ is($step->result(), q{done},
+ "Got expected result for undefined \$Parrot::Git::Describe::current"
+ );
+ ok(! defined $conf->data->get( 'git_describe' ),
+ "'git_describe' undefined as expected" );
+ $conf->data->set( git_describe => undef ); # prepare for next test
+}
+
+$conf->replenish($serialized);
+
+{
+ no warnings 'once';
+ local $Parrot::Git::Describe::current = 'invalid git describe string';
+ my $ret;
+ eval { $ret = $step->runstep($conf); };
+ like($@, qr/Invalid git describe string \(Git::Describe\)/,
+ "Got expected 'die' message for invalid git describe string" );
+ ok( ! defined $ret, "runstep() returned undefined as expected" );
+}
+
+$conf->replenish($serialized);
+
+{
+ no warnings 'once';
+ my $cur = 'REL_2004_09_07-678-ga83bd';
+ local $Parrot::Git::Describe::current = $cur;
+ my $ret = $step->runstep($conf);
+ ok( $ret, "runstep() returned true value" );
+ is($step->result(), $cur,
+ "Got expected result for valid \$Parrot::Git::Describe::current"
+ );
+ $conf->data->set( git_describe => undef ); # prepare for next test
+}
+
+
+pass("Completed all tests in $0");
+
+################### DOCUMENTATION ###################
+
+=head1 NAME
+
+auto/git_describe-01.t - test auto::git_describe
+
+=head1 SYNOPSIS
+
+ % prove t/steps/auto/git_describe-01.t
+
+=head1 DESCRIPTION
+
+The files in this directory test functionality used by F<Configure.pl>.
+
+The tests in this file test execution paths in configuration step
+C<auto::git_describe>.
+
+=head1 AUTHOR
+
+James E Keenan
+
+=head1 SEE ALSO
+
+config::auto::git_describe, F<Configure.pl>.
+
+=cut
+
+# Local Variables:
+# mode: cperl
+# cperl-indent-level: 4
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

0 comments on commit 8967056

Please sign in to comment.