[Jifty-commit] r4220 - in jifty/trunk: lib/Jifty t/TestApp/t
t/TestApp/t/config
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Tue Oct 9 19:40:34 EDT 2007
Author: sartak
Date: Tue Oct 9 19:40:34 2007
New Revision: 4220
Added:
jifty/trunk/t/TestApp/t/config/
jifty/trunk/t/TestApp/t/config/01-basic.t
jifty/trunk/t/TestApp/t/config/02-individual.t
jifty/trunk/t/TestApp/t/config/02-individual.t-config.yml
jifty/trunk/t/TestApp/t/config/test_config.yml
jifty/trunk/t/TestApp/t/test_config.yml
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Test.pm
Log:
r43567 at onn: sartak | 2007-10-09 19:40:28 -0400
Test config loading is now complete code-wise :)
And it has tests now too! Just need to doc it in manual or Jifty::Config
Modified: jifty/trunk/lib/Jifty/Test.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Test.pm (original)
+++ jifty/trunk/lib/Jifty/Test.pm Tue Oct 9 19:40:34 2007
@@ -13,6 +13,7 @@
use File::Spec;
use File::Temp;
use Hash::Merge;
+use Cwd 'abs_path';
=head1 NAME
@@ -256,11 +257,11 @@
=over 4
-=item C</home/bob/MyApp/t/user/12-delete.t-config.yaml>
+=item C</home/bob/MyApp/t/user/12-delete.t-config.yml>
-=item C</home/bob/MyApp/t/user/test_config.yaml>
+=item C</home/bob/MyApp/t/user/test_config.yml>
-=item C</home/bob/MyApp/t/test_config.yaml>
+=item C</home/bob/MyApp/t/test_config.yml>
=back
@@ -275,30 +276,29 @@
sub load_test_configs {
my $class = shift;
my ($test_config_file) = @_;
- my $test_options = {};
+ # get the initial test config file, which is the input . "-config.yml"
$test_config_file = $0 if !defined($test_config_file);
- $test_config_file .= "-config.yaml";
+ $test_config_file .= "-config.yml";
+ $test_config_file = File::Spec->rel2abs($test_config_file);
- Hash::Merge::set_behavior('RIGHT_PRECEDENT');
+ my $test_options = _read_and_merge_config_file($test_config_file, {});
+
+ # get the directory of the input, so we can recurse upwards
+ my ($volume, $directories) = File::Spec->splitpath($test_config_file);
+ my $directory = File::Spec->catdir($volume, $directories);
my $depth = $ENV{JIFTY_TEST_DEPTH} || 30;
for (1 .. $depth)
{
- my $file_options = Jifty::Config->load_file($test_config_file);
-
- # merge the new options into what we have so far
- $test_options = Hash::Merge::merge($file_options, $test_options);
+ my $file = File::Spec->catfile($directory, "test_config.yml");
+ $test_options = _read_and_merge_config_file($file, $test_options);
# are we at the app root? if so, then we can stop moving up
- my $parent = File::Spec->parent($test_config_file);
+ $directory = abs_path(File::Spec->catdir($directory, File::Spec->updir($directory)));
return $test_options
- if Jifty::Util->is_app_root($parent);
-
- # set up the next iteration (this would be at the top, but we special
- # case the first iteration)
- $test_config_file = File::Spec->catfile($parent, "test_config.yaml");
+ if Jifty::Util->is_app_root($directory);
}
Jifty->log->fatal("Stopping looking for test config files after recursing upwards $depth times. Either you have a nonstandard layout or an incredibly deep test hierarchy. If you really do have an incredibly deep test hierarchy, you can set the environment variable JIFTY_TEST_DEPTH to a larger value.");
@@ -306,6 +306,18 @@
return $test_options;
}
+sub _read_and_merge_config_file {
+ my $file = shift;
+ my $config = shift;
+
+ my $file_options = Jifty::Config->load_file($file);
+
+ Hash::Merge::set_behavior('RIGHT_PRECEDENT');
+
+ # merge the new options into what we have so far
+ return Hash::Merge::merge($file_options, $config);
+}
+
=head2 test_config
Returns a hash which overrides parts of the application's
Added: jifty/trunk/t/TestApp/t/config/01-basic.t
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp/t/config/01-basic.t Tue Oct 9 19:40:34 2007
@@ -0,0 +1,39 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+=for your_eyes_only
+
+Note that we CANNOT easily test for loading etc/config.yml: the usual way to
+get t/TestApp* config is to C<use Jifty::SubTest>, which C<chdir>s into
+TestApp. unfortunately that screws up the canonicalization of C<$0> (since it
+is still relative to jifty, not TestApp), which finally screws up the config
+loading, which use C<$0>.
+
+The solution will probably be to have C<Jifty::SubTest> set some global
+variable that we use instead of C<Cwd::cwd> in C<Jifty::Test::load_configs>.
+Yes it sucks, but it beats the weirdness/portability of setting C<$0> (which
+uses magic to actually change the program name for C<ps>).
+
+=cut
+
+use Jifty::Test;
+
+my %option_from_file = (
+ TTestConfig => 't/test_config.yml',
+ TConfigTestConfig => 't/config/test_config.yml',
+);
+
+plan tests => 3 + keys %option_from_file;
+
+ok(Jifty->config->framework('Web')->{'Port'} >= 10000, "default test config still exists");
+is(Jifty->config->app('ThisConfigFile'), 't/config/test_config.yml', "the same value merges correctly");
+
+while (my ($option, $file) = each %option_from_file) {
+ is(Jifty->config->app($option), '1', "options from $file loaded");
+}
+
+is(Jifty->config->app('IndividualFile'), undef, "options from t/config/02-individual.t-config.tml NOT loaded");
+
+1;
+
Added: jifty/trunk/t/TestApp/t/config/02-individual.t
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp/t/config/02-individual.t Tue Oct 9 19:40:34 2007
@@ -0,0 +1,23 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+use Jifty::Test;
+
+my %option_from_file = (
+ TTestConfig => 't/test_config.yml',
+ TConfigTestConfig => 't/config/test_config.yml',
+ IndividualFile => 't/config/02-individual.t-config.tml ',
+);
+
+plan tests => 2 + keys %option_from_file;
+
+ok(Jifty->config->framework('Web')->{'Port'} >= 10000, "default test config still exists");
+is(Jifty->config->app('ThisConfigFile'), 't/config/02-individual.t-config.yml', "the same value merges correctly");
+
+while (my ($option, $file) = each %option_from_file) {
+ is(Jifty->config->app($option), '1', "options from $file loaded");
+}
+
+1;
+
Added: jifty/trunk/t/TestApp/t/config/02-individual.t-config.yml
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp/t/config/02-individual.t-config.yml Tue Oct 9 19:40:34 2007
@@ -0,0 +1,5 @@
+---
+application:
+ ThisConfigFile: t/config/02-individual.t-config.yml
+ IndividualFile: 1
+
Added: jifty/trunk/t/TestApp/t/config/test_config.yml
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp/t/config/test_config.yml Tue Oct 9 19:40:34 2007
@@ -0,0 +1,5 @@
+---
+application:
+ ThisConfigFile: t/config/test_config.yml
+ TConfigTestConfig: 1
+
Added: jifty/trunk/t/TestApp/t/test_config.yml
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp/t/test_config.yml Tue Oct 9 19:40:34 2007
@@ -0,0 +1,5 @@
+---
+application:
+ ThisConfigFile: t/test_config.yml
+ TTestConfig: 1
+
More information about the Jifty-commit
mailing list