1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
use Test::More tests => 12;
use Test::Mock::Cmd::TestUtils;
# use Test::Output; # See rt 72976
BEGIN {
*stdout_like = \&Test::Mock::Cmd::TestUtils::tmp_stdout_like_rt_72976;
}
use Test::Mock::Cmd::TestUtils::X;
BEGIN {
SKIP: {
skip '/bin/echo is required for these tests.', 4 if !-x '/bin/echo';
stdout_like(
sub {
Test::Mock::Cmd::TestUtils::do_in_fork(
sub {
Test::Mock::Cmd::TestUtils::X::i_call_exec( "/bin/echo", "unmocked exec in other package defined before mock exec list" );
ok( 0, 'unmocked class exec() list did not exit' );
}
);
},
qr/unmocked exec in other package defined before mock exec list/,
'unmocked exec() in other package defined before mock, list'
);
stdout_like(
sub {
Test::Mock::Cmd::TestUtils::do_in_fork(
sub {
Test::Mock::Cmd::TestUtils::X::i_call_exec("/bin/echo unmocked exec in other package defined before mock exec string");
ok( 0, 'unmocked class exec() string did not exit' );
}
);
},
qr/unmocked exec in other package defined before mock exec string/,
'unmocked exec() in other package defined before mock, string'
);
stdout_like(
sub {
Test::Mock::Cmd::TestUtils::do_in_fork(
sub {
# Statement unlikely to be reached ... no warnings 'exec'; doesn't help so we combine into one statement
exec( "/bin/echo", "unmocked exec defined before mock exec list" ) || ok( 0, 'unmocked exec() list did not exit' );
}
);
},
qr/unmocked exec defined before mock exec list/,
'unmocked exec() defined before mock, list'
);
stdout_like(
sub {
Test::Mock::Cmd::TestUtils::do_in_fork(
sub {
# Statement unlikely to be reached ... no warnings 'exec'; doesn't help so we combine into one statement
exec("/bin/echo unmocked exec defined before mock exec string") || ok( 0, 'unmocked exec() string did not exit' );
}
);
},
qr/unmocked exec defined before mock exec string/,
'unmocked exec() defined before mock, string'
);
}
}
use Test::Mock::Cmd \&Test::Mock::Cmd::TestUtils::test_more_is_like_return_42;
use Test::Mock::Cmd::TestUtils::Y;
diag("Testing Test::Mock::Cmd $Test::Mock::Cmd::VERSION");
my $rc = exec( 'I am exec', 'I am exec', 'exec() mocked' );
is( $rc, 42, "exec() mocked RV" );
my $rca = Test::Mock::Cmd::TestUtils::Y::i_call_exec( 'I am exec in pkg', 'I am exec in pkg', 'exec() in pkg loaded after mocking is mocked' );
is( $rca, 42, "exec() in an other class (loaded after mocking) mocked RV list" );
SKIP: {
skip '/bin/echo is required for these tests.', 4 if !-x '/bin/echo';
stdout_like(
sub {
Test::Mock::Cmd::TestUtils::do_in_fork(
sub {
Test::Mock::Cmd::TestUtils::X::i_call_exec( "/bin/echo", "exec call defined before mocking list not affected" );
ok( 0, 'unmocked class exec() list did not exit' );
}
);
},
qr/exec call defined before mocking list not affected/,
'exec call defined before mocking list not affected'
);
stdout_like(
sub {
Test::Mock::Cmd::TestUtils::do_in_fork(
sub {
Test::Mock::Cmd::TestUtils::X::i_call_exec("/bin/echo exec call defined before mocking string not affected");
ok( 0, 'unmocked class exec() string did not exit' );
}
);
},
qr/exec call defined before mocking string not affected/,
'exec call defined before mocking string not affected'
);
stdout_like(
sub {
Test::Mock::Cmd::TestUtils::do_in_fork(
sub {
Test::Mock::Cmd::orig_exec( "/bin/echo", "orig_exec list" );
ok( 0, 'unmocked exec() list did not exit' );
}
);
},
qr/orig_exec list/,
'orig_exec list'
);
stdout_like(
sub {
Test::Mock::Cmd::TestUtils::do_in_fork(
sub {
Test::Mock::Cmd::orig_exec("/bin/echo orig_exec string");
ok( 0, 'unmocked exec() string did not exit' );
}
);
},
qr/orig_exec string/,
'orig_exec string'
);
}
|