Either config/auto/attributes.pm is now DWIMming or I don't understand it correctly. Please help me determine which.
Consider the first of two files attached (neither of which is yet in trunk): t/configure/114-auto_attributes-02.t. It's set up like many of the other t/configure/*.t tests, no nothing interesting happens until line 41: # 114-auto_attributes-02.t my $attr = q{HASATTRIBUTE_MALLOC}; # <-- line 41 ok(! defined ( $step->try_attr($conf, $attr) ), "try_attr() returned undef as expected"); is($conf->data->get($attr), 1, "$attr set to true value as expected"); like($conf->data->get("ccflags"), qr/$attr/, "'cc_flags' includes specified attribute as expected"); Here, in order to write unit tests for the class's Perl 5 code, I take advantage of the fact that auto::attributes has a try_attr() subroutine defined and provide it with an attribute which happens to be an element of @potential_attributes. Because it's a real attribute, I expect try_attr() to complete with a bare return, set the 'HASATTRIBUTE_MALLOC' in the 'data' section of the Parrot::Configure object to a true value, and to include that attribute in the value of the 'cc_flags' attribute as well. And all my expectations are met. Now, let's suppose that I provide try_attr() with an obviously phony attribute such as HASATTRIBUTE_NONSENSE in t/configure/114-auto-attributes-03.t (the other file attached). Without knowing anything about the meaning or role of attributes, and without knowing anything about C code run by Parrot::Configure::Step::_run_command inside try_attr(), I would expect that providing try_attr() with a bogus value would mean that try_attr() would lead to different results from the HASATTRIBUTE_MALLOC case. Specifically, though I would expect try_attr() to return an undefined value -- as currently written, it always does so -- I would not expect HASATTRIBUTE_NONSENSE to have a true value, nor would I expect to find it in the string held in $cc_flags. But my expectations are not met. The two tests starting at line 44 both fail. # 114-auto_attributes-03.t my $attr = q{HASATTRIBUTE_NONSENSE}; ok(! defined ( $step->try_attr($conf, $attr) ), "try_attr() returned undef as expected"); is($conf->data->get($attr), 0, "$attr set to false value as expected"); # <-- line 44 unlike($conf->data->get("ccflags"), qr/$attr/, "'cc_flags' includes specified attribute as expected"); Am I missing something? Or is auto::attributes set up so that *any* attribute will succeed? If the latter, is that what we want? Thank you very much. kid51
#! perl # Copyright (C) 2007, The Perl Foundation. # $Id$ # 114-auto_attributes-02.t use strict; use warnings; use Test::More qw(no_plan); # tests => 11; use Carp; use lib qw( lib t/configure/testlib ); use_ok('config::init::defaults'); use_ok('config::auto::attributes'); use Parrot::Configure; use Parrot::Configure::Options qw( process_options ); use Parrot::Configure::Test qw( test_step_thru_runstep); my $args = process_options( { argv => [ qq{--verbose} ], mode => q{configure}, } ); my $conf = Parrot::Configure->new(); test_step_thru_runstep($conf, q{init::defaults}, $args); my ($task, $step_name, @step_params, $step, $ret); my $pkg = q{auto::attributes}; $conf->add_steps($pkg); $conf->options->set(%{$args}); $task = $conf->steps->[1]; $step_name = $task->step; @step_params = @{ $task->params }; $step = $step_name->new(); ok(defined $step, "$step_name constructor returned defined value"); isa_ok($step, $step_name); ok($step->description(), "$step_name has description"); my $attr = q{HASATTRIBUTE_MALLOC}; ok(! defined ( $step->try_attr($conf, $attr) ), "try_attr() returned undef as expected"); is($conf->data->get($attr), 1, "$attr set to true value as expected"); like($conf->data->get("ccflags"), qr/$attr/, "'cc_flags' includes specified attribute as expected"); pass("Completed all tests in $0");
#! perl # Copyright (C) 2007, The Perl Foundation. # $Id$ # 114-auto_attributes-03.t use strict; use warnings; use Test::More qw(no_plan); # tests => 11; use Carp; use lib qw( lib t/configure/testlib ); use_ok('config::init::defaults'); use_ok('config::auto::attributes'); use Parrot::Configure; use Parrot::Configure::Options qw( process_options ); use Parrot::Configure::Test qw( test_step_thru_runstep); my $args = process_options( { argv => [ qq{--verbose} ], mode => q{configure}, } ); my $conf = Parrot::Configure->new(); test_step_thru_runstep($conf, q{init::defaults}, $args); my ($task, $step_name, @step_params, $step, $ret); my $pkg = q{auto::attributes}; $conf->add_steps($pkg); $conf->options->set(%{$args}); $task = $conf->steps->[1]; $step_name = $task->step; @step_params = @{ $task->params }; $step = $step_name->new(); ok(defined $step, "$step_name constructor returned defined value"); isa_ok($step, $step_name); ok($step->description(), "$step_name has description"); my $attr = q{HASATTRIBUTE_NONSENSE}; ok(! defined ( $step->try_attr($conf, $attr) ), "try_attr() returned undef as expected"); is($conf->data->get($attr), 0, "$attr set to false value as expected"); unlike($conf->data->get("ccflags"), qr/$attr/, "'cc_flags' includes specified attribute as expected"); pass("Completed all tests in $0");