有没有更优雅的方法来编写依赖于 O/S 的测试脚本部分?
请参考注释行下方的代码。
背景:模块Perl::Tags为 VIM 创建一个标签文件。在 Win32 上,目录分隔符是“\”,但在其他操作系统上是“/”。Vim 的 Perl-support 模块似乎读标签文件很愉快,所以似乎不需要修改模块。
#!/usr/bin/perl -w
use strict; use warnings;
use Data::Dumper;
use Test::More tests => 6;
use FindBin qw($Bin);
BEGIN {
use_ok( 'Perl::Tags' );
}
my $naive_tagger = Perl::Tags::Naive->new( max_level=>1 );
ok (defined $naive_tagger, 'created Perl::Tags' );
isa_ok ($naive_tagger, 'Perl::Tags::Naive' );
isa_ok ($naive_tagger, 'Perl::Tags' );
my $result =
$naive_tagger->process(
files => [ "$Bin/Test.pm" ],
refresh=> 1
);
ok ($result, 'processed successfully' ) or diag "RESULT $result";
# Other tests also fail because \Test.pm on Win32 vs /Test.pm on Linux/ OS X
if ( $^O =~ /MSWin32/ ) {
like ($naive_tagger, qr{Test\t\S+\\Test.pm\t/package Test;/} , 'package line');
} else {
like ($naive_tagger, qr{Test\t\S+/Test.pm\t/package Test;/} , 'package line');
}