[Jifty-commit] r4221 - in jifty/trunk: lib/Jifty t/TestApp/etc t/TestApp/t/config t/lib/Jifty

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Tue Oct 9 19:56:15 EDT 2007


Author: sartak
Date: Tue Oct  9 19:56:14 2007
New Revision: 4221

Added:
   jifty/trunk/t/TestApp/etc/
   jifty/trunk/t/TestApp/etc/config.yml
   jifty/trunk/t/TestApp/etc/site_config.yml
   jifty/trunk/t/TestApp/t/config/03-nosubtest.t
Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/Config.pm
   jifty/trunk/lib/Jifty/Test.pm
   jifty/trunk/t/TestApp/t/config/01-basic.t
   jifty/trunk/t/TestApp/t/config/02-individual.t
   jifty/trunk/t/lib/Jifty/SubTest.pm

Log:
 r43569 at onn:  sartak | 2007-10-09 19:56:09 -0400
 Fix the problem of tests having both config and a correctly-relative $0
 Jifty::SubTest now makes available the old Cwd (which as 03-nosubtest demonstrates doesn't break apps that don't use Jifty::SubTest)
 Also a bit of doc in Jifty::Config
 The Feature is Done. :)


Modified: jifty/trunk/lib/Jifty/Config.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Config.pm	(original)
+++ jifty/trunk/lib/Jifty/Config.pm	Tue Oct  9 19:56:14 2007
@@ -96,6 +96,9 @@
 the framework's C<TestConfig> or the C<JIFTY_TEST_CONFIG> environment
 variable.
 
+Note that the test config may be drawn from several files if you use
+L<Jifty::Test>. See the documentation of L<Jifty::Test::load_test_configs>.
+
 Values in the test configuration will clobber the site configuration.
 Values in the site configuration file clobber those in the vendor
 configuration file. Values in the vendor configuration file clobber

Modified: jifty/trunk/lib/Jifty/Test.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Test.pm	(original)
+++ jifty/trunk/lib/Jifty/Test.pm	Tue Oct  9 19:56:14 2007
@@ -277,10 +277,14 @@
     my $class = shift;
     my ($test_config_file) = @_;
 
+    # Jifty::SubTest uses chdir which screws up $0, so to be nice it also makes
+    # available the cwd was before it uses chdir.
+    my $cwd = $Jifty::SubTest::OrigCwd;
+
     # 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.yml";
-    $test_config_file = File::Spec->rel2abs($test_config_file);
+    $test_config_file = File::Spec->rel2abs($test_config_file, $cwd);
 
     my $test_options = _read_and_merge_config_file($test_config_file, {});
 

Added: jifty/trunk/t/TestApp/etc/config.yml
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp/etc/config.yml	Tue Oct  9 19:56:14 2007
@@ -0,0 +1,5 @@
+---
+application:
+    ThisConfigFile: etc/config.yml
+    EtcConfig: 1
+

Added: jifty/trunk/t/TestApp/etc/site_config.yml
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp/etc/site_config.yml	Tue Oct  9 19:56:14 2007
@@ -0,0 +1,5 @@
+---
+application:
+    ThisConfigFile: etc/site_config.yml
+    EtcSiteConfig: 1
+

Modified: jifty/trunk/t/TestApp/t/config/01-basic.t
==============================================================================
--- jifty/trunk/t/TestApp/t/config/01-basic.t	(original)
+++ jifty/trunk/t/TestApp/t/config/01-basic.t	Tue Oct  9 19:56:14 2007
@@ -2,29 +2,23 @@
 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 lib 't/lib';
+use Jifty::SubTest;
 
 use Jifty::Test;
 
 my %option_from_file = (
+    EtcConfig         => 'etc/config.yml',
+    EtcSiteConfig     => 'etc/site_config.yml',
     TTestConfig       => 't/test_config.yml',
     TConfigTestConfig => 't/config/test_config.yml',
 );
 
-plan tests => 3 + keys %option_from_file;
+my %no_option_from_file = (
+    IndividualFile    => 't/config/02-individual.t-config.yml',
+);
+
+plan tests => 2 + keys(%option_from_file) + keys %no_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");
@@ -33,7 +27,7 @@
     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;
+while (my ($option, $file) = each %no_option_from_file) {
+    is(Jifty->config->app($option), undef, "options from $file NOT loaded");
+}
 

Modified: jifty/trunk/t/TestApp/t/config/02-individual.t
==============================================================================
--- jifty/trunk/t/TestApp/t/config/02-individual.t	(original)
+++ jifty/trunk/t/TestApp/t/config/02-individual.t	Tue Oct  9 19:56:14 2007
@@ -2,9 +2,14 @@
 use strict;
 use warnings;
 
+use lib 't/lib';
+use Jifty::SubTest;
+
 use Jifty::Test;
 
 my %option_from_file = (
+    EtcConfig         => 'etc/config.yml',
+    EtcSiteConfig     => 'etc/site_config.yml',
     TTestConfig       => 't/test_config.yml',
     TConfigTestConfig => 't/config/test_config.yml',
     IndividualFile    => 't/config/02-individual.t-config.tml ',
@@ -19,5 +24,3 @@
     is(Jifty->config->app($option), '1', "options from $file loaded");
 }
 
-1;
-

Added: jifty/trunk/t/TestApp/t/config/03-nosubtest.t
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp/t/config/03-nosubtest.t	Tue Oct  9 19:56:14 2007
@@ -0,0 +1,30 @@
+#!/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',
+);
+
+my %no_option_from_file = (
+    EtcConfig         => 'etc/config.yml',
+    EtcSiteConfig     => 'etc/site_config.yml',
+    IndividualFile    => 't/config/02-individual.t-config.yml',
+);
+
+plan tests => 2 + keys(%option_from_file) + keys %no_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");
+}
+
+while (my ($option, $file) = each %no_option_from_file) {
+    is(Jifty->config->app($option), undef, "options from $file NOT loaded");
+}
+

Modified: jifty/trunk/t/lib/Jifty/SubTest.pm
==============================================================================
--- jifty/trunk/t/lib/Jifty/SubTest.pm	(original)
+++ jifty/trunk/t/lib/Jifty/SubTest.pm	Tue Oct  9 19:56:14 2007
@@ -2,7 +2,11 @@
 
 use FindBin;
 use File::Spec;
+use Cwd;
+
 BEGIN {
+    $Jifty::SubTest::OrigCwd = Cwd::cwd;
+
     @INC = grep { defined } map { ref($_) ? $_ : File::Spec->rel2abs($_) } @INC;
     chdir "$FindBin::Bin/..";
 }


More information about the Jifty-commit mailing list