Revision 29641

Date:
2008/07/21 02:17:43
Author:
jkeenan
Revision 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.
Files:

Legend:

 
Added
 
Removed
 
Modified
  • branches/parallel/config/gen/crypto.pm

     
    23 23
    24 24 sub _init {
    25 25 my $self = shift;
    26
    27 return {
    28 description => q{Generating Digest PMC files},
    29 result => q{},
    30 };
    26 my %data;
    27 $data{description} = q{Generating Digest PMC files};
    28 $data{result} = q{};
    29 $data{digest} = {
    30 MD2 => {},
    31 MD4 => {},
    32 MD5 => {},
    33 RIPEMD160 => {
    34 md_inc => 'ripemd',
    35 },
    36 SHA => {},
    37 SHA1 => {
    38 md_inc => 'sha',
    39 md_ctx => 'SHA_CTX',
    40 md_digest => 'SHA_DIGEST',
    41 },
    42 SHA256 => {
    43 md_inc => 'sha',
    44 version_needed => '0.9.8a',
    45 },
    46 SHA512 => {
    47 md_inc => 'sha',
    48 version_needed => '0.9.8a',
    49 },
    50 };
    51 return \%data;
    31 52 }
    32 53
    33 my %digest = (
    34 MD2 => {},
    35 MD4 => {},
    36 MD5 => {},
    37 RIPEMD160 => {
    38 md_inc => 'ripemd',
    39 },
    40 SHA => {},
    41 SHA1 => {
    42 md_inc => 'sha',
    43 md_ctx => 'SHA_CTX',
    44 md_digest => 'SHA_DIGEST',
    45 },
    46 SHA256 => {
    47 md_inc => 'sha',
    48 version_needed => '0.9.8a',
    49 },
    50 SHA512 => {
    51 md_inc => 'sha',
    52 version_needed => '0.9.8a',
    53 },
    54 );
    55
    56 54 sub runstep {
    57 55 my ( $self, $conf ) = @_;
    58 56
    59 57 if ( ! $conf->data->get('has_crypto') ) {
    60 58 $self->set_result('skipped');
    61
    62 59 return 1;
    63 60 }
    64 61
    65 62 my $openssl_version = $conf->data->get('openssl_version');
    66 63
    67 while (my ($md, $val) = each %digest ) {
    64 while (my ($md, $val) = each %{ $self->{digest} } ) {
    68 65 my $file = lc $md;
    69 66 $conf->data->set( md_name => $md );
    70 67 $conf->data->set( md_file => $file );
    71 68 $conf->data->set( md_inc => $val->{md_inc} || $file );
    72 69 $conf->data->set( md_ctx => $val->{md_ctx} || $md . '_CTX' );
    73 70 $conf->data->set( md_digest => $val->{md_digest} || $md . '_DIGEST' );
    74 $conf->data->set( md_guard =>
    75 ( exists $val->{version_needed} and ( $openssl_version lt $val->{version_needed} ))
    71 $conf->data->set( md_guard => (
    72 ( exists $val->{version_needed} )
    73 and
    74 ( $openssl_version lt $val->{version_needed} )
    75 )
    76 76 ? '#if 0'
    77 77 : '#ifndef OPENSSL_NO_' . $md
    78 78 );
  • branches/parallel/t/steps/gen_crypto-01.t

     
    5 5
    6 6 use strict;
    7 7 use warnings;
    8 use Test::More tests => 2;
    8 use Test::More qw(no_plan); # tests => 2;
    9 9 use Carp;
    10 10 use lib qw( lib );
    11 use_ok('config::init::defaults');
    11 12 use_ok('config::gen::crypto');
    13 use Parrot::Configure;
    14 use Parrot::Configure::Options qw( process_options );
    15 use Parrot::Configure::Test qw(
    16 test_step_thru_runstep
    17 rerun_defaults_for_testing
    18 test_step_constructor_and_description
    19 );
    12 20
    13 =for hints_for_testing This is just a stub so that Configure.pl will run.
    21 my $args = process_options(
    22 {
    23 argv => [ ],
    24 mode => q{configure},
    25 }
    26 );
    14 27
    15 =cut
    28 my $conf = Parrot::Configure->new;
    16 29
    30 my $serialized = $conf->pcfreeze();
    31
    32 test_step_thru_runstep( $conf, q{init::defaults}, $args );
    33
    34 my $pkg = q{gen::crypto};
    35 $conf->add_steps($pkg);
    36 $conf->options->set( %{$args} );
    37 my $step = test_step_constructor_and_description($conf);
    38 my $has_crypto_orig = $conf->data->get('has_crypto');
    39 $conf->data->set( has_crypto => undef );
    40 my $ret = $step->runstep($conf);
    41 ok( $ret, "runstep() returned true value" );
    42 is($step->result(), q{skipped}, "Got expected result");
    43 # re-set for next test
    44 $conf->data->set( has_crypto => $has_crypto_orig );
    45 $step->set_result( q{} );
    46
    47 $conf->replenish($serialized);
    48
    49
    50
    17 51 pass("Completed all tests in $0");
    18 52
    19 53 ################### DOCUMENTATION ###################