Created
January 8, 2020 16:14
-
-
Save atoomic/98ee3a7af8e26989fb6bae6085c8e3ed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!perl | |
use Test::More; | |
my %storage; | |
use constant SAMPLE_CONSTANT => defined eval { $storage{cache} = get_string('abcd') }; | |
sub get_string { | |
my ( $str ) = @_; | |
return ":$str:"; | |
} | |
is SAMPLE_CONSTANT, 1, "constant is set to true"; | |
is $storage{cache}, ':abcd:', "cache is set at compile time"; | |
done_testing; |
working better once the get_string
function is moved above
use strict;
use warnings;
use Test::More;
my %storage;
sub get_string {
my ( $str ) = @_;
return ":$str:";
}
use constant SAMPLE_CONSTANT => defined eval { $storage{cache} = get_string('abcd') };
is SAMPLE_CONSTANT, 1, "constant is set to true";
is $storage{cache}, ':abcd:', "cache is set at compile time";
done_testing;
extra/constant-eval.t ..
ok 1 - constant is set to true
ok 2 - cache is set at compile time
1..2
ok
All tests successful.
Files=1, Tests=2, 1 wallclock secs ( 0.03 usr 0.00 sys + 0.07 cusr 0.01 csys = 0.11 CPU)
Result: PASS
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This test is failing