围绕生产脚本的Perl测试包装器

围绕生产脚本的Perl测试包装器,perl,testing,wrapper,diagnostics,aspect,Perl,Testing,Wrapper,Diagnostics,Aspect,出于测试目的,我想创建一个包装脚本,它可以在不更改原始脚本的情况下向现有脚本添加功能。我的问题是,这在perl中可能吗?我如何做到 包装器脚本将执行以下操作: #!/usr/bin/perl use strict; use warnings; use diagnostics; use Aspect; run syntax checking on config files; run unittesting stuff; call production script; 生产脚本将保持不变并完全独

出于测试目的,我想创建一个包装脚本,它可以在不更改原始脚本的情况下向现有脚本添加功能。我的问题是,这在perl中可能吗?我如何做到

包装器脚本将执行以下操作:

#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use Aspect;

run syntax checking on config files;
run unittesting stuff;
call production script;
生产脚本将保持不变并完全独立:

#!/usr/bin/perl
use strict;
use warnings;

bunch of production code here;
当然,我希望诊断和方面编织在生产代码上工作。我已经尝试了一些简单的事情,但它们都不起作用,代码甚至没有运行

eval { require "production.pl" };
do 'production.pl';
require 'production.pl';
我会用。这些块帮助您分离测试用例

您可以通过这种方式调用程序以获取诊断消息:

perl -Mdiagnostics -MAspect your_script.pl [args]
以下是集成此测试的方法:

use Test::More;
use Test::Script::Run;
### test 1
{
  note 'test1 is running...';
  note 'test 1 app_name running fine';
  run_ok( 'app_name', [ app's args ], 'app_name runs ok' );
  note 'test 1 does not throws errors and returns correct values';
  my ( $return, $stdout, $stderr ) = run_script( 'app_name', [ app's args ] );
  run_output_matches_unordered(
        'app_name', [ app's args ],
        [ 'out line 2', 'out line 1' ],
        [ 'err line 2', 'err line 1' ],
        'run_output_matches_unordered'
  );

};
### test 2
{
   ...
};
done_testing();

我运行了一个测试,但是如果您这样调用它,诊断不会应用到生产脚本。Run在后台使用IPC::Run3,这似乎只是产生了一个单独的进程。然后,从调用者的导入不会应用于被调用者。这是一件非常不同的事情。可以通过以下方式实现:perl-Mdiagnostics-MAspect your_script.pl[args]