File: builtin-taint.t

package info (click to toggle)
perl 5.42.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 128,392 kB
  • sloc: perl: 534,963; ansic: 240,563; sh: 72,042; pascal: 6,934; xml: 2,428; yacc: 1,360; makefile: 1,197; cpp: 208; lisp: 1
file content (40 lines) | stat: -rw-r--r-- 946 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!./perl -T

BEGIN {
    chdir 't' if -d 't';
    require './test.pl';
    set_up_inc('../lib');
}

use v5.36;
no warnings 'experimental::builtin';

package FetchStoreCounter {
    sub TIESCALAR($class, @args) { bless \@args, $class }

    sub FETCH($self)    { $self->[0]->$*++ }
    sub STORE($self, $) { $self->[1]->$*++ }
}

# is_tainted
{
    use builtin qw( is_tainted );

    is(is_tainted($0), !!${^TAINT}, "\$0 is tainted (if tainting is supported)");
    ok(!is_tainted($1), "\$1 isn't tainted");

    # Invokes magic
    tie my $tied, FetchStoreCounter => (\my $fetchcount, \my $storecount);

    my $_dummy = is_tainted($tied);
    is($fetchcount, 1, 'is_tainted() invokes FETCH magic');

    $tied = is_tainted($0);
    is($storecount, 1, 'is_tainted() invokes STORE magic');

    is(prototype(\&builtin::is_tainted), '$', 'is_tainted prototype');
}

# vim: tabstop=4 shiftwidth=4 expandtab autoindent softtabstop=4

done_testing();