This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make utf8::encode respect magic
[perl5.git] / t / io / pvbm.t
CommitLineData
6e592b3a
BM
1#!./perl
2
3# Test that various IO functions don't try to treat PVBMs as
4# filehandles. Most of these will segfault perl if they fail.
5
6BEGIN {
7 chdir 't' if -d 't';
8 @INC = qw(. ../lib);
9 require "./test.pl";
10}
11
12BEGIN { $| = 1 }
13
14plan(28);
15
16sub PVBM () { 'foo' }
17{ my $dummy = index 'foo', PVBM }
18
19{
20 my $which;
21 {
22 package Tie;
23
24 sub TIEHANDLE { $which = 'TIEHANDLE' }
25 sub TIESCALAR { $which = 'TIESCALAR' }
26 }
27 my $pvbm = PVBM;
28
29 tie $pvbm, 'Tie';
30 is ($which, 'TIESCALAR', 'PVBM gets TIESCALAR');
31}
32
33{
34 my $pvbm = PVBM;
35 ok (scalar eval { untie $pvbm; 1 }, 'untie(PVBM) doesn\'t segfault');
36 ok (scalar eval { tied $pvbm; 1 }, 'tied(PVBM) doesn\'t segfault');
37}
38
39{
40 my $pvbm = PVBM;
41
42 ok (scalar eval { pipe $pvbm, PIPE; }, 'pipe(PVBM, ) succeeds');
43 close foo;
44 close PIPE;
45 ok (scalar eval { pipe PIPE, $pvbm; }, 'pipe(, PVBM) succeeds');
46 close foo;
47 close PIPE;
48 ok (!eval { pipe \$pvbm, PIPE; }, 'pipe(PVBM ref, ) fails');
49 ok (!eval { pipe PIPE, \$pvbm; }, 'pipe(, PVBM ref) fails');
50
51 ok (!eval { truncate $pvbm, 0 }, 'truncate(PVBM) fails');
52 ok (!eval { truncate \$pvbm, 0}, 'truncate(PVBM ref) fails');
53
54 ok (!eval { stat $pvbm }, 'stat(PVBM) fails');
55 ok (!eval { stat \$pvbm }, 'stat(PVBM ref) fails');
56
57 ok (!eval { lstat $pvbm }, 'lstat(PVBM) fails');
58 ok (!eval { lstat \$pvbm }, 'lstat(PVBM ref) fails');
59
60 ok (!eval { chdir $pvbm }, 'chdir(PVBM) fails');
61 ok (!eval { chdir \$pvbm }, 'chdir(pvbm ref) fails');
62
63 ok (!eval { close $pvbm }, 'close(PVBM) fails');
64 ok (!eval { close $pvbm }, 'close(PVBM ref) fails');
65
66 ok (!eval { chmod 0600, $pvbm }, 'chmod(PVBM) fails');
67 ok (!eval { chmod 0600, \$pvbm }, 'chmod(PVBM ref) fails');
68
ab14db95
SH
69 SKIP: {
70 skip('chown() not implemented on Win32', 2) if $^O eq 'MSWin32';
71 ok (!eval { chown 0, 0, $pvbm }, 'chown(PVBM) fails');
72 ok (!eval { chown 0, 0, \$pvbm }, 'chown(PVBM ref) fails');
73 }
6e592b3a
BM
74
75 ok (!eval { utime 0, 0, $pvbm }, 'utime(PVBM) fails');
76 ok (!eval { utime 0, 0, \$pvbm }, 'utime(PVBM ref) fails');
77
78 ok (!eval { <$pvbm> }, '<PVBM> fails');
79 ok (!eval { readline $pvbm }, 'readline(PVBM) fails');
80 ok (!eval { readline \$pvbm }, 'readline(PVBM ref) fails');
81
82 ok (!eval { open $pvbm, '<', 'none.such' }, 'open(PVBM) fails');
83 ok (!eval { open \$pvbm, '<', 'none.such', }, 'open(PVBM ref) fails');
84}