gpt4 book ai didi

perl - 为什么我的 Perl 测试错误地失败了?

转载 作者:行者123 更新时间:2023-12-04 19:25:39 24 4
gpt4 key购买 nike

我创建了以下测试类:

package Test::DB;

# $Id$
#

use strict;
use warnings;

our $VERSION = '0.01';

use Carp;
use English '-no_match_vars';
use Test::Most;

use base 'Test::Class';

sub startup : Tests(startup) {
eval {
require esp_libs_db;

esp_libs_db->import;

1;
} or Carp::croak($EVAL_ERROR);

return 1;
}

sub connect : Tests(2) {
can_ok 'esp_libs_db', 'espDbConnect';

my $schema = 'test_schema';

throws_ok { espDbConnect($schema) }
qr/Cannot locate database ($schema) connection file./,
'dies when connection file does not exist';

return 1;
}

1;

当我开始运行测试时,我得到以下输出:
t/run.t ..
#
# Test::DB->connect
1..2
ok 1 - esp_libs_db->can('espDbConnect')
not ok 2 - dies when connection file does not exist

# Failed test 'dies when connection file does not exist'
# at t/tests/Test/DB.pm line 39.
# (in Test::DB->connect)
# expecting: Regexp ((?-xism:Cannot locate database (test_schema) connection file.))
# found: <FONT color=red size=4 face=arial>ERROR: PM_DB_0004: Cannot locate database (test_schema) connection file.</FONT> at t/tests/Test/DB.pm line 38
# Looks like you failed 1 test of 2.
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/2 subtests

Test Summary Report
-------------------
t/run.t (Wstat: 256 Tests: 2 Failed: 1)
Failed test: 2
Non-zero exit status: 1
Files=1, Tests=2, 3 wallclock secs ( 0.44 usr 0.07 sys + 2.44 cusr 0.43 csys = 3.38 CPU)
Result: FAIL

我不明白为什么第二个测试应该很清楚地通过时失败了

最佳答案

()是正则表达式中的特殊字符,请尝试转义它们:

qr/Cannot locate database \($schema\) connection file./

关于perl - 为什么我的 Perl 测试错误地失败了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4440454/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com