目錄

名稱

TAP::Parser::SourceHandler::Executable - 來自可執行 TAP 來源的串流輸出

版本

版本 3.44

概要

use TAP::Parser::Source;
use TAP::Parser::SourceHandler::Executable;

my $source = TAP::Parser::Source->new->raw(['/usr/bin/ruby', 'mytest.rb']);
$source->assemble_meta;

my $class = 'TAP::Parser::SourceHandler::Executable';
my $vote  = $class->can_handle( $source );
my $iter  = $class->make_iterator( $source );

說明

這是一個可執行 TAP::Parser::SourceHandler - 它有 2 個工作

1. 找出給定的 TAP::Parser::Source 是否為可執行命令 ("can_handle")。

2. 為可執行命令建立一個迭代器 ("make_iterator")。

除非您正在撰寫外掛程式或子類別化 TAP::Parser,否則您可能不需要直接使用此模組。

方法

類別方法

can_handle

my $vote = $class->can_handle( $source );

只有當 $source 看起來像執行檔時才投票。投下以下票數

0.9  if it's a hash with an 'exec' key
0.8  if it's a .bat file
0.75 if it's got an execute bit set

make_iterator

my $iterator = $class->make_iterator( $source );

針對來源傳回新的 TAP::Parser::Iterator::Process$source->raw 必須符合下列其中一種格式

{ exec => [ @exec ] }

[ @exec ]

$file

發生錯誤時會 croak

iterator_class

要使用的反覆運算器類別,如果您是子類別,請覆寫。預設為 TAP::Parser::Iterator::Process

子類別

請參閱 TAP::Parser 中的「子類別」 以取得子類別概觀。

範例

package MyRubySourceHandler;

use strict;

use Carp qw( croak );
use TAP::Parser::SourceHandler::Executable;

use base 'TAP::Parser::SourceHandler::Executable';

# expect $handler->(['mytest.rb', 'cmdline', 'args']);
sub make_iterator {
  my ($self, $source) = @_;
  my @test_args = @{ $source->test_args };
  my $rb_file   = $test_args[0];
  croak("error: Ruby file '$rb_file' not found!") unless (-f $rb_file);
  return $self->SUPER::raw_source(['/usr/bin/ruby', @test_args]);
}

另請參閱

TAP::ObjectTAP::ParserTAP::Parser::IteratorFactoryTAP::Parser::SourceHandlerTAP::Parser::SourceHandler::PerlTAP::Parser::SourceHandler::FileTAP::Parser::SourceHandler::HandleTAP::Parser::SourceHandler::RawTAP