From: Chris W. <la...@us...> - 2004-11-28 00:28:44
|
Update of /cvsroot/openinteract/OpenInteract2/t In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23385/t Modified Files: config_ini.t Log Message: add functionality to bring in other INI configurations with @INCLUDE directive Index: config_ini.t =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/t/config_ini.t,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** config_ini.t 12 Jun 2004 20:50:01 -0000 1.16 --- config_ini.t 27 Nov 2004 20:33:54 -0000 1.17 *************** *** 6,10 **** use lib 't/'; require 'utils.pl'; ! use Test::More tests => 38; require_ok( 'OpenInteract2::Config::Ini' ); --- 6,10 ---- use lib 't/'; require 'utils.pl'; ! use Test::More tests => 54; require_ok( 'OpenInteract2::Config::Ini' ); *************** *** 14,17 **** --- 14,19 ---- sub1 = val1 + @INCLUDE = included_config.ini + [head1] sub1 = val1 *************** *** 32,58 **** TEST { my $conf = eval { ! OpenInteract2::Config::Ini->new({ content => $test_config } ) }; ok( ! $@, "Object created (content)" ) || diag "Error: $@"; is( ref( $conf ), 'OpenInteract2::Config::Ini', ! 'Correct object type created (content)' ); is( $conf->{sub1}, 'val1', ! 'Global value read in correctly (content)' ); is( $conf->{head2}{sub1}, 'val1', ! 'Sub value scalar read in correctly (content)' ); is( $conf->{head2}{sub2}, 'this is a longer value with a line continuation', ! 'Sub value scalar with line continuations read in correctly (content)' ); is( $conf->{head1}{sub1}[0], 'val1', ! 'Sub value array read in correctly (content)' ); is( $conf->{head3}{child}{sub2}, 'val3', ! 'Nested sub value scalar read in correctly (content)' ); is_deeply( $conf->{head1}{sub2}, [ 'val1', 'val2' ], ! 'Sub value array with leading @, read in correctly (content)' ); is_deeply( $conf->{head3}{child}{sub1}, [ qw( val1 val2 val3 val4 val5 val6 ) ], 'Nested sub value array declared with mixed @, and line has ' . ! 'correct members (content)' ); my $conf_data = $conf->as_data; --- 34,72 ---- TEST + my $config_file = get_use_file( 'test_config.ini', 'name' ); + { my $conf = eval { ! OpenInteract2::Config::Ini->new({ ! directory => get_use_dir(), ! content => $test_config, ! }) }; ok( ! $@, "Object created (content)" ) || diag "Error: $@"; is( ref( $conf ), 'OpenInteract2::Config::Ini', ! 'Correct object type created (from content)' ); is( $conf->{sub1}, 'val1', ! 'Global value read in correctly (from content)' ); is( $conf->{head2}{sub1}, 'val1', ! 'Sub value scalar read in correctly (from content)' ); is( $conf->{head2}{sub2}, 'this is a longer value with a line continuation', ! 'Sub value scalar with line continuations read in correctly (from content)' ); is( $conf->{head1}{sub1}[0], 'val1', ! 'Sub value array read in correctly (from content)' ); is( $conf->{head3}{child}{sub2}, 'val3', ! 'Nested sub value scalar read in correctly (from content)' ); is_deeply( $conf->{head1}{sub2}, [ 'val1', 'val2' ], ! 'Sub value array with leading @, read in correctly (from content)' ); is_deeply( $conf->{head3}{child}{sub1}, [ qw( val1 val2 val3 val4 val5 val6 ) ], 'Nested sub value array declared with mixed @, and line has ' . ! 'correct members (from content)' ); ! is( $conf->{include}{position}, 'Center', ! 'Included scalar read in correctly (from content)' ); ! is_deeply( $conf->{include}{name}, [ 'Mario', 'Lemieux' ], ! 'Included array read in correctly (from content)' ); ! is_deeply( $conf->{include}{location}, [ 'Pittsburgh', 'Pennsylvania', 'USA' ], ! 'Included array with leading @, read in correctly (from content)' ); ! my $conf_data = $conf->as_data; *************** *** 60,132 **** 'Correct data type returned from as_data()' ); is( $conf_data->{sub1}, 'val1', ! 'Global value in as_data() correctly (content)' ); is( $conf_data->{head2}{sub1}, 'val1', ! 'Sub value scalar in as_data() correctly (content)' ); is( $conf_data->{head2}{sub2}, 'this is a longer value with a line continuation', ! 'Sub value scalar with line continuations in as_data() correctly (content)' ); is( $conf_data->{head1}{sub1}[0], 'val1', ! 'Sub value array in as_data() correctly (content)' ); is( $conf_data->{head3}{child}{sub2}, 'val3', ! 'Nested sub value scalar in as_data() correctly (content)' ); is( $conf_data->{head3}{child}{sub1}[0], 'val1', ! 'Nested sub value array in as_data() correctly (content)' ); is_deeply( $conf_data->{head1}{sub2}, [ 'val1', 'val2' ], 'Sub value array with leading @, read in correctly in ' . ! 'as_data() (content)' ); is_deeply( $conf_data->{head3}{child}{sub1}, [ qw( val1 val2 val3 val4 val5 val6) ], 'Nested sub value array declared with mixed @, and line has ' . ! 'correct members in as_data() (content)' ); } { - my $config_file = get_use_file( 'test_config.ini', 'name' ); my $conf = eval { OpenInteract2::Config::Ini->new({ filename => $config_file } ) }; ! ok( ! $@, "Object created (file)" ) || diag "Error: $@"; is( ref( $conf ), 'OpenInteract2::Config::Ini', ! 'Correct object type created (file)' ); is( $conf->{sub1}, 'val1', ! 'Global value read in correctly (file)' ); is( $conf->{head2}{sub1}, 'val1', ! 'Sub value scalar read in correctly (file)' ); is( $conf->{head2}{sub2}, 'this is a longer value with a line continuation', ! 'Sub value scalar with line continuations read in correctly (file)' ); is( $conf->{head1}{sub1}[0], 'val1', ! 'Sub value array read in correctly (file)' ); is( $conf->{head3}{child}{sub2}, 'val3', ! 'Nested sub value scalar read in correctly (file)' ); is( $conf->{head3}{child}{sub1}[0], 'val1', ! 'Nested sub value array read in correctly (file)' ); is_deeply( $conf->{head1}{sub2}, [ 'val1', 'val2' ], ! 'Sub value array with leading @, read in correctly (file)' ); is_deeply( $conf->{head3}{child}{sub1}, [ qw( val1 val2 val3 val4 val5 val6 ) ], 'Nested sub value array declared with mixed @, and line has ' . ! 'correct members (file)' ); my $conf_data = $conf->as_data; is( ref( $conf_data ), 'HASH', ! 'Correct data type returned from as_data() (file)' ); is( $conf_data->{sub1}, 'val1', ! 'Global value in as_data() correctly (file)' ); is( $conf_data->{head2}{sub1}, 'val1', ! 'Sub value scalar in as_data() correctly (file)' ); is( $conf->{head2}{sub2}, 'this is a longer value with a line continuation', ! 'Sub value scalar with line continuations in as_data() correctly (file)' ); is( $conf_data->{head1}{sub1}[0], 'val1', ! 'Sub value array in as_data() correctly (file)' ); is( $conf_data->{head3}{child}{sub2}, 'val3', ! 'Nested sub value scalar in as_data() correctly (file)' ); is( $conf_data->{head3}{child}{sub1}[0], 'val1', ! 'Nested sub value array in as_data() correctly (file)' ); is_deeply( $conf_data->{head1}{sub2}, [ 'val1', 'val2' ], 'Sub value array with leading @, read in correctly in ' . ! 'as_data() (file)' ); is_deeply( $conf_data->{head3}{child}{sub1}, [ qw( val1 val2 val3 val4 val5 val6) ], 'Nested sub value array declared with mixed @, and line has ' . ! 'correct members in as_data() (file)' ); } --- 74,187 ---- 'Correct data type returned from as_data()' ); is( $conf_data->{sub1}, 'val1', ! 'Global value in as_data() correctly (from content)' ); is( $conf_data->{head2}{sub1}, 'val1', ! 'Sub value scalar in as_data() correctly (from content)' ); is( $conf_data->{head2}{sub2}, 'this is a longer value with a line continuation', ! 'Sub value scalar with line continuations in as_data() correctly (from content)' ); is( $conf_data->{head1}{sub1}[0], 'val1', ! 'Sub value array in as_data() correctly (from content)' ); is( $conf_data->{head3}{child}{sub2}, 'val3', ! 'Nested sub value scalar in as_data() correctly (from content)' ); is( $conf_data->{head3}{child}{sub1}[0], 'val1', ! 'Nested sub value array in as_data() correctly (from content)' ); is_deeply( $conf_data->{head1}{sub2}, [ 'val1', 'val2' ], 'Sub value array with leading @, read in correctly in ' . ! 'as_data() (from content)' ); is_deeply( $conf_data->{head3}{child}{sub1}, [ qw( val1 val2 val3 val4 val5 val6) ], 'Nested sub value array declared with mixed @, and line has ' . ! 'correct members in as_data() (from content)' ); ! is( $conf_data->{include}{position}, 'Center', ! 'Included scalar read in correctly in as_data() (from content)' ); ! is_deeply( $conf_data->{include}{name}, [ 'Mario', 'Lemieux' ], ! 'Included array read in correctly in as_data() (from content)' ); ! is_deeply( $conf_data->{include}{location}, [ 'Pittsburgh', 'Pennsylvania', 'USA' ], ! 'Included array with leading @, read in correctly in as_data() (from content)' ); } { my $conf = eval { OpenInteract2::Config::Ini->new({ filename => $config_file } ) }; ! ok( ! $@, "Object created (from file)" ) || diag "Error: $@"; is( ref( $conf ), 'OpenInteract2::Config::Ini', ! 'Correct object type created (from file)' ); is( $conf->{sub1}, 'val1', ! 'Global value read in correctly (from file)' ); is( $conf->{head2}{sub1}, 'val1', ! 'Sub value scalar read in correctly (from file)' ); is( $conf->{head2}{sub2}, 'this is a longer value with a line continuation', ! 'Sub value scalar with line continuations read in correctly (from file)' ); is( $conf->{head1}{sub1}[0], 'val1', ! 'Sub value array read in correctly (from file)' ); is( $conf->{head3}{child}{sub2}, 'val3', ! 'Nested sub value scalar read in correctly (from file)' ); is( $conf->{head3}{child}{sub1}[0], 'val1', ! 'Nested sub value array read in correctly (from file)' ); is_deeply( $conf->{head1}{sub2}, [ 'val1', 'val2' ], ! 'Sub value array with leading @, read in correctly (from file)' ); is_deeply( $conf->{head3}{child}{sub1}, [ qw( val1 val2 val3 val4 val5 val6 ) ], 'Nested sub value array declared with mixed @, and line has ' . ! 'correct members (from file)' ); ! is( $conf->{include}{position}, 'Center', ! 'Included scalar read in correctly (from file)' ); ! is_deeply( $conf->{include}{name}, [ 'Mario', 'Lemieux' ], ! 'Included array read in correctly (from file)' ); ! is_deeply( $conf->{include}{location}, [ 'Pittsburgh', 'Pennsylvania', 'USA' ], ! 'Included array with leading @, read in correctly (from file)' ); my $conf_data = $conf->as_data; is( ref( $conf_data ), 'HASH', ! 'Correct data type returned from as_data() (from file)' ); is( $conf_data->{sub1}, 'val1', ! 'Global value in as_data() correctly (from file)' ); is( $conf_data->{head2}{sub1}, 'val1', ! 'Sub value scalar in as_data() correctly (from file)' ); is( $conf->{head2}{sub2}, 'this is a longer value with a line continuation', ! 'Sub value scalar with line continuations in as_data() correctly (from file)' ); is( $conf_data->{head1}{sub1}[0], 'val1', ! 'Sub value array in as_data() correctly (from file)' ); is( $conf_data->{head3}{child}{sub2}, 'val3', ! 'Nested sub value scalar in as_data() correctly (from file)' ); is( $conf_data->{head3}{child}{sub1}[0], 'val1', ! 'Nested sub value array in as_data() correctly (from file)' ); is_deeply( $conf_data->{head1}{sub2}, [ 'val1', 'val2' ], 'Sub value array with leading @, read in correctly in ' . ! 'as_data() (from file)' ); is_deeply( $conf_data->{head3}{child}{sub1}, [ qw( val1 val2 val3 val4 val5 val6) ], 'Nested sub value array declared with mixed @, and line has ' . ! 'correct members in as_data() (from file)' ); ! is( $conf_data->{include}{position}, 'Center', ! 'Included scalar read in correctly in as_data() (from file)' ); ! is_deeply( $conf_data->{include}{name}, [ 'Mario', 'Lemieux' ], ! 'Included array read in correctly in as_data() (from file)' ); ! is_deeply( $conf_data->{include}{location}, [ 'Pittsburgh', 'Pennsylvania', 'USA' ], ! 'Included array with leading @, read in correctly in as_data() (from file)' ); ! } ! ! # ensure @INCLUDE not found throws exception ! ! { ! my $conf = eval { ! OpenInteract2::Config::Ini->new({ content => $test_config }) ! }; ! ok( $@, 'Exception correctly thrown if we cannot find @INCLUDE specified in content' ); ! my $error = "$@"; ! like( $error, qr/Config file '\..+included_config.ini' does not exist/, ! 'Expected exception thrown with @INCLUDE not found' ); } + { + my $conf = eval { + OpenInteract2::Config::Ini->new({ + filename => $config_file, + directory => 'somepath', + }) + }; + ok( $@, 'Exception correctly thrown if we feed bad directory to @INCLUDE specified in file' ); + my $error = "$@"; + like( $error, qr/Config file 'somepath.+included_config.ini' does not exist/, + 'Expected exception thrown with @INCLUDE not found' ); + } |