Author: jkeenan
Date: Sun Jul 20 19:17:43 2008
New Revision: 29641
Modified:
branches/parallel/config/gen/crypto.pm
branches/parallel/t/steps/gen_crypto-01.t
Log:
config/gen/crypto.pm: Pull hard-coded %digest into step's data structure (as
done for other config steps). Some typographic reformatting. Write first
tests for gen::crypto; so far, the case where crypto is unavailable.
Modified: branches/parallel/config/gen/crypto.pm
==============================================================================
--- branches/parallel/config/gen/crypto.pm (original)
+++ branches/parallel/config/gen/crypto.pm Sun Jul 20 19:17:43 2008
@@ -23,56 +23,56 @@
sub _init {
my $self = shift;
-
- return {
- description => q{Generating Digest PMC files},
- result => q{},
- };
+ my %data;
+ $data{description} = q{Generating Digest PMC files};
+ $data{result} = q{};
+ $data{digest} = {
+ MD2 => {},
+ MD4 => {},
+ MD5 => {},
+ RIPEMD160 => {
+ md_inc => 'ripemd',
+ },
+ SHA => {},
+ SHA1 => {
+ md_inc => 'sha',
+ md_ctx => 'SHA_CTX',
+ md_digest => 'SHA_DIGEST',
+ },
+ SHA256 => {
+ md_inc => 'sha',
+ version_needed => '0.9.8a',
+ },
+ SHA512 => {
+ md_inc => 'sha',
+ version_needed => '0.9.8a',
+ },
+ };
+ return \%data;
}
-my %digest = (
- MD2 => {},
- MD4 => {},
- MD5 => {},
- RIPEMD160 => {
- md_inc => 'ripemd',
- },
- SHA => {},
- SHA1 => {
- md_inc => 'sha',
- md_ctx => 'SHA_CTX',
- md_digest => 'SHA_DIGEST',
- },
- SHA256 => {
- md_inc => 'sha',
- version_needed => '0.9.8a',
- },
- SHA512 => {
- md_inc => 'sha',
- version_needed => '0.9.8a',
- },
-);
-
sub runstep {
my ( $self, $conf ) = @_;
if ( ! $conf->data->get('has_crypto') ) {
$self->set_result('skipped');
-
return 1;
}
my $openssl_version = $conf->data->get('openssl_version');
- while (my ($md, $val) = each %digest ) {
+ while (my ($md, $val) = each %{ $self->{digest} } ) {
my $file = lc $md;
$conf->data->set( md_name => $md );
$conf->data->set( md_file => $file );
$conf->data->set( md_inc => $val->{md_inc} || $file );
$conf->data->set( md_ctx => $val->{md_ctx} || $md . '_CTX' );
$conf->data->set( md_digest => $val->{md_digest} || $md . '_DIGEST' );
- $conf->data->set( md_guard =>
- ( exists $val->{version_needed} and ( $openssl_version lt
$val->{version_needed} ))
+ $conf->data->set( md_guard => (
+ ( exists $val->{version_needed} )
+ and
+ ( $openssl_version lt $val->{version_needed} )
+ )
? '#if 0'
: '#ifndef OPENSSL_NO_' . $md
);
Modified: branches/parallel/t/steps/gen_crypto-01.t
==============================================================================
--- branches/parallel/t/steps/gen_crypto-01.t (original)
+++ branches/parallel/t/steps/gen_crypto-01.t Sun Jul 20 19:17:43 2008
@@ -5,14 +5,48 @@
use strict;
use warnings;
-use Test::More tests => 2;
+use Test::More qw(no_plan); # tests => 2;
use Carp;
use lib qw( lib );
+use_ok('config::init::defaults');
use_ok('config::gen::crypto');
+use Parrot::Configure;
+use Parrot::Configure::Options qw( process_options );
+use Parrot::Configure::Test qw(
+ test_step_thru_runstep
+ rerun_defaults_for_testing
+ test_step_constructor_and_description
+);
+
+my $args = process_options(
+ {
+ argv => [ ],
+ mode => q{configure},
+ }
+);
+
+my $conf = Parrot::Configure->new;
+
+my $serialized = $conf->pcfreeze();
+
+test_step_thru_runstep( $conf, q{init::defaults}, $args );
+
+my $pkg = q{gen::crypto};
+$conf->add_steps($pkg);
+$conf->options->set( %{$args} );
+my $step = test_step_constructor_and_description($conf);
+my $has_crypto_orig = $conf->data->get('has_crypto');
+$conf->data->set( has_crypto => undef );
+my $ret = $step->runstep($conf);
+ok( $ret, "runstep() returned true value" );
+is($step->result(), q{skipped}, "Got expected result");
+# re-set for next test
+$conf->data->set( has_crypto => $has_crypto_orig );
+$step->set_result( q{} );
+
+$conf->replenish($serialized);
-=for hints_for_testing This is just a stub so that Configure.pl will run.
-=cut
pass("Completed all tests in $0");