6.5. like(value, qr/expected regex/, name);It is especially important when you don't want or can't realisticly expect an exact match with the result. compares with =~ Example 6-3. examples/intro/like.t #!/usr/bin/perl
use strict;
use warnings;
use Test::More tests => 2;
like( foo(), qr/\d+/, "there are some digits in the result" );
like( bar(), qr/\d+/, "there are some digits in the result" );
sub foo {
return "This is a long text with a number 42 in it";
}
sub bar {
return "This is another string with no number in it";
}$ perl like.t 1..2 ok 1 - there are some digits in the result not ok 2 - there are some digits in the result # Failed test 'there are some digits in the result' # in like.t at line 7. # 'This is another string with no number in it' # doesn't match '(?-xism:\d+)' # Looks like you failed 1 test of 2.
|
Follow me: