Commits

Diab Jerius committed 5523d5f

add test for L handler; fix mock server code for read_line command (incorrect call to read_chunk)

Comments (0)

Files changed (2)

t/Hg/Lib/Server/Pipe/runcommand.t

 
 package Pipe::RunCommand;
 
+use 5.10.1;
+
 use strict;
 use warnings;
 
 
 }
 
-sub no_prompt_handler : Tests {
+sub no_L_handler : Tests {
 
     my $self   = shift;
     my $server = $self->{server};
 
-    my $e = exception { $server->runcommand( [ 'read_line' ] ) };
+    my $e = exception { $server->runcommand( ['read_line'] ) };
 
     isa_ok( $e, EPipe, 'EPipe' );
     like( $e, qr/unexpected data .* channel L/, 'message' );
     $self->{stop_error} = [ EPipe, qr/unexpected termination of server/ ];
 
 }
+
+sub L_handler : Tests {
+
+    my $self   = shift;
+    my $server = $self->{server};
+
+    sub handle_L {
+        # my $buffer = shift;
+        state $i = 5;
+        return $i ? sprintf( "%03d\n", $i-- ) : '';
+    }
+
+    sub handle_o {
+        # my $buffer = shift;
+        state $buffer = '';
+        return $buffer unless @_;
+        $buffer .= $_[0];
+    }
+
+    my $e = exception {
+        $server->runcommand(
+            ['read_line'],
+            inchannels  => { L => \&handle_L },
+            outchannels => { o => \&handle_o },
+        );
+    };
+
+    is( $e, undef, 'no exception' );
+    is( handle_o(), "001\n002\n003\n004\n005\n", 'returned message' );
+
+}

t/lib/Server/Commands.pm

 
         do {
             $server->write( pack( 'A[1] N', 'L', 4096 ) );
-            $nr = $server->read_chunk( $buf );
+            $server->read_chunk( $buf );
+	    $nr = length $buf;
             unshift @buf, $buf if $nr;
         } while $nr;