]> Dogcows Code - chaz/p5-File-KDBX/blob - t/erase.t
add initial WIP
[chaz/p5-File-KDBX] / t / erase.t
1 #!/usr/bin/env perl
2
3 use warnings;
4 use strict;
5
6 use lib 't/lib';
7 use TestCommon;
8
9 use File::KDBX::Util qw(erase erase_scoped);
10 use Test::More;
11
12 my $data1 = 'hello';
13 my $data2 = 'hello';
14 my $hash1 = {foo => 'secret'};
15 my $array1 = [qw(bar baz)];
16
17 erase $data1, \$data2, $hash1, $array1;
18 is $data1, undef, 'Erase by alias';
19 is $data2, undef, 'Erase by reference';
20 is scalar keys %$hash1, 0, 'Erase by hashref';
21 is scalar @$array1, 0, 'Erase by arrayref';
22
23 {
24 my $data3 = 'hello';
25 my $cleanup = erase_scoped $data3;
26 is $data3, 'hello', 'Data not yet erased';
27 undef $cleanup;
28 is $data3, undef, 'Scoped erased';
29 }
30
31 sub get_secret {
32 my $secret = 'conspiracy';
33 my $cleanup = erase_scoped \$secret;
34 return $secret;
35 }
36
37 my $another;
38 {
39 my $thing = get_secret();
40 $another = $thing;
41 is $thing, 'conspiracy', 'Data not yet erased';
42 undef $thing;
43 is $thing, undef, 'Scope erased';
44 }
45 is $another, 'conspiracy', 'Data not erased in the other scalar';
46
47 done_testing;
This page took 0.038957 seconds and 4 git commands to generate.