diff options
author | Nicholas Clark <nick@ccl4.org> | 2010-07-28 11:01:51 +0100 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2010-07-28 11:01:51 +0100 |
commit | da1010ecc50c91387eed9bcc349e6960909a3484 (patch) | |
tree | 64250a5517609b41345cd9ca147facb1be24dfd2 /t | |
parent | 1c761d95ce3e122676f2110e57e721b7689cd4c2 (diff) | |
download | perl-da1010ecc50c91387eed9bcc349e6960909a3484.tar.gz |
Make srand() return "0 but true" for 0, for backwards compatible behaviour.
Diffstat (limited to 't')
-rw-r--r-- | t/op/srand.t | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/t/op/srand.t b/t/op/srand.t index 34fa9af935..3d49126268 100644 --- a/t/op/srand.t +++ b/t/op/srand.t @@ -10,7 +10,7 @@ BEGIN { use strict; require "test.pl"; -plan(tests => 5); +plan(tests => 9); # Generate a load of random numbers. # int() avoids possible floating point error. @@ -61,3 +61,21 @@ ok( !eq_array(\@first_run, \@second_run), 'srand() called automatically'); # check srand's return value my $seed = srand(1764); is( $seed, 1764, "return value" ); + +$seed = srand(0); +ok( $seed, "true return value for srand(0)"); +cmp_ok( $seed, '==', 0, "numeric 0 return value for srand(0)"); + +{ + my @warnings; + my $b; + { + local $SIG{__WARN__} = sub { + push @warnings, "@_"; + warn @_; + }; + $b = $seed + 0; + } + is( $b, 0, "Quacks like a zero"); + is( "@warnings", "", "Does not warn"); +} |