Fix big bug in test
Tomas Doran [Wed, 25 Nov 2009 22:51:28 +0000 (22:51 +0000)]
TODO.scripts
lib/Catalyst/Script/Test.pm
lib/Catalyst/ScriptRunner.pm
t/aggregate/unit_core_script_test.t

index 99f8300..f55544d 100644 (file)
@@ -1,3 +1,2 @@
-* $ARGV[0] has slipped to $ARGV[1] in ::Test
 * Sort out help so that it shows what you fucked up.
 * Fix horrible hacking around MX::Getopt's help display - probably by fixing MX::Getopt.
index 4b30853..1416bd4 100644 (file)
@@ -1,5 +1,6 @@
 package Catalyst::Script::Test;
 use Moose;
+use Catalyst::Test ();
 use namespace::autoclean;
 
 with 'Catalyst::ScriptRole';
@@ -9,10 +10,9 @@ __PACKAGE__->meta->get_attribute('help')->cmd_aliases('h');
 sub run {
     my $self = shift;
 
-    Class::MOP::load_class("Catalyst::Test");
     Catalyst::Test->import($self->application_name);
 
-    print request($ARGV[1])->content  . "\n";
+    print request($ARGV[0])->content  . "\n";
 
 }
 
index de3c8bb..247ce30 100644 (file)
@@ -11,9 +11,6 @@ sub run {
 
     lib->import(File::Spec->catdir($FindBin::Bin, '..', 'lib'));
 
-    warn("load $classtoload or Catalyst::Script::$scriptclass");
-
-    # FIXME - Error handling / reporting
     unless ( eval { Class::MOP::load_class($classtoload) } ) {
         warn("Could not load $classtoload - falling back to Catalyst::Script::$scriptclass : $@\n")
             if $@ !~ /Can't locate/;
index cc91a3a..5f56681 100644 (file)
@@ -11,38 +11,44 @@ use Catalyst::Script::Test;
 use File::Temp qw/tempfile/;
 use IO::Handle;
 
-my ($fh, $fn) = tempfile();
-
-binmode( $fh );
-binmode( STDOUT );
-
-{
-    local @ARGV = ('/');
-    my $i;
-    lives_ok {
-        $i = Catalyst::Script::Test->new_with_options(application_name => 'TestApp');
-    } "new_with_options";
-    ok $i;
-    my $saved;
-    open( $saved, '<&'. STDIN->fileno )
-          or croak("Can't dup stdin: $!");
-    open( STDOUT, '>&='. $fh->fileno )
-        or croak("Can't open stdout: $!");
-    eval { $i->run };
-    ok !$@, 'Ran ok';
-
-    STDOUT->flush
-        or croak("Can't flush stdout: $!");
-
-    open( STDOUT, '>&'. fileno($saved) )
-        or croak("Can't restore stdout: $!");
-}
-
-my $data = do { my $fh; open($fh, '<', $fn) or die $!; local $/; <$fh>; };
-$fh = undef;
-unlink $fn if -r $fn;
-
-is $data, "root index\n", 'correct content printed';
+is run_test('/'), "root index\n", 'correct content printed';
+is run_test('/moose/get_attribute'), "42\n", 'Correct content printed for non root action';
 
 done_testing;
 
+sub run_test {
+    my $url = shift;
+
+    my ($fh, $fn) = tempfile();
+
+    binmode( $fh );
+    binmode( STDOUT );
+
+    {
+        local @ARGV = ($url);
+        my $i;
+        lives_ok {
+            $i = Catalyst::Script::Test->new_with_options(application_name => 'TestApp');
+        } "new_with_options";
+        ok $i;
+        my $saved;
+        open( $saved, '<&'. STDIN->fileno )
+              or croak("Can't dup stdin: $!");
+        open( STDOUT, '>&='. $fh->fileno )
+            or croak("Can't open stdout: $!");
+        eval { $i->run };
+        ok !$@, 'Ran ok';
+
+        STDOUT->flush
+            or croak("Can't flush stdout: $!");
+
+        open( STDOUT, '>&'. fileno($saved) )
+            or croak("Can't restore stdout: $!");
+    }
+
+    my $data = do { my $fh; open($fh, '<', $fn) or die $!; local $/; <$fh>; };
+    $fh = undef;
+    unlink $fn if -r $fn;
+
+    return $data;
+}