File: truncate.t

package info (click to toggle)
libautodie-perl 2.10-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 528 kB
  • ctags: 305
  • sloc: perl: 4,012; makefile: 4
file content (53 lines) | stat: -rwxr-xr-x 971 bytes parent folder | download | duplicates (4)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/perl -w
use strict;

use Test::More;
use File::Temp qw(tempfile);
use IO::Handle;

my $tmpfh = tempfile();
my $truncate_status;

eval {
    $truncate_status = truncate($tmpfh, 0);
};

if ($@ || !defined($truncate_status)) {
    plan skip_all => 'Truncate not implemented or not working on this system';
}

plan tests => 3;

SKIP: {
    my $can_truncate_stdout = truncate(\*STDOUT,0);

    if ($can_truncate_stdout) {
        skip("This system thinks we can truncate STDOUT. Suuure!", 1);
    }

    eval {
        use autodie;
        truncate(\*STDOUT,0);
    };

    isa_ok($@, 'autodie::exception', "Truncating STDOUT should throw an exception");

}

eval {
    use autodie;
    no warnings 'once';
    truncate(\*FOO, 0);
};

isa_ok($@, 'autodie::exception', "Truncating an unopened file is wrong.");

$tmpfh->print("Hello World");
$tmpfh->flush;

eval {
    use autodie;
    truncate($tmpfh, 0);
};

is($@, "", "Truncating a normal file should be fine");