1

テスト目的で、元のスクリプトを変更せずに既存のスクリプトに機能を追加できるラッピング スクリプトを作成したいと考えています。私の質問は、これは 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';
4

1 に答える 1

1

Test::Script::Runを使用します。ブロックは、テスト ケースを分離するのに役立ちます。

この方法でプログラムを呼び出して、診断メッセージを取得できます。

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();
于 2014-04-28T10:56:46.180 に答える