use strict; use warnings; use Test::More 'tests' => 7; sub empty_string { '' } sub no_replacement { my $x = 'x'; return ($x =~ s/y//); } my $warning; $SIG{__WARN__} = sub { $warning = shift }; ok( ! defined $warning, 'no warning recorded' ); is( 0+empty_string(), 0, 'empty string is zero' ); ok( $warning, 'warning is generated' ); my $expected_warning = q{Argument "" isn't numeric in addition (+)}; is( substr( $warning, 0, length $expected_warning ), $expected_warning, q{warning is the one that's expected} ); undef $warning; ok( ! defined $warning, 'recorded warning is cleared' ); is( 0+no_replacement(), 0, 'no replacement is zero' ); ok( ! defined $warning, 'no warning is generated' );