2 # Copyright (C) 2008, Parrot Foundation.
8 use Test::More tests => 17;
10 use lib qw( lib t/configure/testlib );
11 use_ok('config::init::defaults');
12 use_ok('config::auto::format');
13 use Parrot::BuildUtil;
14 use Parrot::Configure::Options qw( process_options );
15 use Parrot::Configure::Step::Test;
16 use Parrot::Configure::Test qw(
17 test_step_constructor_and_description
20 ########## _set_intvalfmt() ##########
22 my ($args, $step_list_ref) = process_options( {
27 my $conf = Parrot::Configure::Step::Test->new;
28 $conf->include_config_results( $args );
30 my ($task, $step_name, $step, $ret);
31 my $pkg = q{auto::format};
33 $conf->add_steps($pkg);
34 $conf->options->set(%{$args});
35 $step = test_step_constructor_and_description($conf);
37 $conf->data->set( iv => 'int' );
38 auto::format::_set_intvalfmt($conf);
39 is($conf->data->get( 'intvalfmt' ), '%d',
40 "intvalfmt set as expected");
42 $conf->data->set( iv => undef );
45 $conf->data->set( iv => 'long' );
46 auto::format::_set_intvalfmt($conf);
47 is($conf->data->get( 'intvalfmt' ), '%ld',
48 "intvalfmt set as expected");
50 $conf->data->set( iv => undef );
53 $conf->data->set( iv => 'long int' );
54 auto::format::_set_intvalfmt($conf);
55 is($conf->data->get( 'intvalfmt' ), '%ld',
56 "intvalfmt set as expected");
58 $conf->data->set( iv => undef );
61 $conf->data->set( iv => 'long long' );
62 auto::format::_set_intvalfmt($conf);
63 is($conf->data->get( 'intvalfmt' ), '%lld',
64 "intvalfmt set as expected");
66 $conf->data->set( iv => undef );
69 $conf->data->set( iv => 'long long int' );
70 auto::format::_set_intvalfmt($conf);
71 is($conf->data->get( 'intvalfmt' ), '%lld',
72 "intvalfmt set as expected");
74 $conf->data->set( iv => undef );
78 $conf->data->set( iv => $type );
79 eval { auto::format::_set_intvalfmt($conf); };
81 qr/Can't find a printf-style format specifier for type '$type'/, #'
82 "Got expected error message");
85 ########## _set_floatvalfmt_nvsize() ##########
88 $conf->data->set( nv => 'double' );
89 auto::format::_set_floatvalfmt_nvsize($conf);
90 is($conf->data->get( 'floatvalfmt' ), '%.15g',
91 "floatvalfmt set as expected");
92 is($conf->data->get( 'nvsize' ), $conf->data->get( 'doublesize' ),
93 "nvsize set as expected");
101 my $p5format = '%.15' . $conf->data->get('sPRIgldbl_provisional');
102 $p5format =~ s/"//g; # Perl 5's Config value has embedded double quotes
103 $conf->data->set( nv => 'long double' );
105 auto::format::_set_floatvalfmt_nvsize($conf);
107 is($conf->data->get( 'floatvalfmt' ), $p5format,
108 "floatvalfmt set as expected: nv long double");
109 is($conf->data->get( 'nvsize' ), $conf->data->get( 'hugefloatvalsize' ),
110 "nvsize set as expected: nv long double");
113 floatvalfmt => undef,
119 $conf->data->set( nv => 'foobar' );
120 eval { auto::format::_set_floatvalfmt_nvsize($conf); };
122 qr/Can't find a printf-style format specifier for type '$type'/, #'
123 "Got expected error message");
126 pass("Completed all tests in $0");
128 ################### DOCUMENTATION ###################
132 auto/format-01.t - test auto::format
136 % prove t/steps/auto/format-01.t
140 The files in this directory test functionality used by F<Configure.pl>.
142 The tests in this file test auto::format.
150 config::auto::format, F<Configure.pl>.
156 # cperl-indent-level: 4
159 # vim: expandtab shiftwidth=4: