xref: /openbsd-src/gnu/usr.bin/perl/cpan/Memoize/t/flush.t (revision f2a19305cfc49ea4d1a5feb55cd6c283c6f1e031)
1*f2a19305Safresh1use strict; use warnings;
2*f2a19305Safresh1use Memoize qw(flush_cache memoize);
3*f2a19305Safresh1use Test::More tests => 9;
4b39c5158Smillert
5b39c5158Smillertmy $V = 100;
6b39c5158Smillertsub VAL { $V }
7b39c5158Smillert
8*f2a19305Safresh1ok eval { memoize('VAL'); 1 }, 'memozing the test function';
9b39c5158Smillert
10*f2a19305Safresh1is VAL(), 100, '... with the expected return value';
11b39c5158Smillert$V = 200;
12*f2a19305Safresh1is VAL(), 100, '... which is expectedly sticky';
13b39c5158Smillert
14*f2a19305Safresh1ok eval { flush_cache('VAL'); 1 }, 'flusing the cache by name works';
15b39c5158Smillert
16*f2a19305Safresh1is VAL(), 200, '... with the expected new return value';
17b39c5158Smillert$V = 300;
18*f2a19305Safresh1is VAL(), 200, '... which is expectedly sticky';
19b39c5158Smillert
20*f2a19305Safresh1ok eval { flush_cache(\&VAL); 1 }, 'flusing the cache by name works';
21b39c5158Smillert
22*f2a19305Safresh1is VAL(), 300, '... with the expected new return value';
23b39c5158Smillert$V = 400;
24*f2a19305Safresh1is VAL(), 300, '... which is expectedly sticky';
25