Преглед на файлове

Still some problems on DESTROY it seems

Andy Baugh преди 3 месеца
родител
ревизия
1aa7f7651f
променени са 2 файла, в които са добавени 11 реда и са изтрити 6 реда
  1. 3 3
      lib/Net/OpenSSH/More.pm
  2. 8 3
      t/Net-OpenSSH-More.t

+ 3 - 3
lib/Net/OpenSSH/More.pm

@@ -314,8 +314,9 @@ my $init_ssh = sub {
 
 my $connection_check = sub {
     my ( $self ) = @_;
+    return 1 if $self->check_master;
 	local $@;
-    eval { $self = $init_ssh->($self->{'_opts'}) unless $self->check_master; };
+    eval { $self = $init_ssh->( __PACKAGE__, $self->{'_opts'}) };
     return $@ ? 0 : 1;
 };
 
@@ -482,8 +483,7 @@ my $do_persistent_command = sub {
 
 sub new {
     my ( $class, %opts ) = @_;
-    $die_no_trace->( "No host given to $class.", 'PEBCAK' ) if !$opts{'host'};
-    $opts{'host'} = '127.0.0.1' if $opts{'host'} eq 'localhost';
+    $opts{'host'} = '127.0.0.1' if !$opts{'host'} || $opts{'host'} eq 'localhost';
 
     # Set defaults, check if we can return early
     %opts = ( %defaults, %opts );

+ 8 - 3
t/Net-OpenSSH-More.t

@@ -3,6 +3,7 @@ use warnings;
 
 use Test2::V0;
 use Test2::Tools::Explain;
+use Test2::Tools::Subtest qw{subtest_streamed};
 use Test2::Plugin::NoWarnings;
 use Test::MockModule qw{strict};
 use Carp::Always;
@@ -13,19 +14,23 @@ use lib "$FindBin::Bin/../lib";
 
 use Net::OpenSSH::More;
 
-subtest "Live tests versus localhost" => sub {
+subtest_streamed "Live tests versus localhost" => sub {
     plan 'skip_all' => 'AUTHOR_TESTS not set in shell environment, skipping...' if !$ENV{'AUTHOR_TESTS'};
     local %Net::OpenSSH::More::cache;
     my $obj = Net::OpenSSH::More->new( 'host' => '127.0.0.1' );
     is( ref $obj, 'Net::OpenSSH::More', "Got right ref type for object upon instantiation (using IP)" );
-    $obj = Net::OpenSSH::More->new( 'host' => 'localhost', 'debug' => 1, 'output_prefix' => '# ' );
+    undef $obj;
+    %Net::OpenSSH::More::cache = ();
+    $obj = Net::OpenSSH::More->new( 'host' => 'localhost', 'output_prefix' => '# ' );
     is( ref $obj, 'Net::OpenSSH::More', "Got right ref type for object upon instantiation (using localhost)" );
     my @cmd_ret = $obj->cmd( { 'no_persist' => 1 }, 'echo "whee"' );
     is( \@cmd_ret, [ "whee", '', 0 ], "Got expected return (non-persistent shell)" );
+    @cmd_ret = $obj->cmd( '/bin/true' );
+    is( \@cmd_ret, [ '', '', 0 ], "Got expected return (persistent shell)" );
 };
 
 # Mock based testing
-subtest "Common tests using mocks" => sub {
+subtest_streamed "Common tests using mocks" => sub {
     local %Net::OpenSSH::More::cache;
     my $parent_mock = Test::MockModule->new('Net::OpenSSH');
     $parent_mock->redefine(