Commit | Line | Data |
0b09a93a |
1 | #!/usr/bin/perl -w |
2 | use strict; |
3 | |
4 | use Test::More; |
5 | use File::Temp qw(tempfile); |
6 | use IO::Handle; |
7 | |
8 | my $tmpfh = tempfile(); |
9 | |
10 | eval { |
11 | truncate($tmpfh, 0); |
12 | }; |
13 | |
14 | if ($@) { |
15 | plan skip_all => 'Truncate not implemented on this system'; |
16 | } |
17 | |
18 | plan tests => 3; |
19 | |
20 | SKIP: { |
21 | my $can_truncate_stdout = truncate(\*STDOUT,0); |
22 | |
23 | if ($can_truncate_stdout) { |
24 | skip("This system thinks we can truncate STDOUT. Suuure!", 1); |
25 | } |
26 | |
27 | eval { |
28 | use autodie; |
29 | truncate(\*STDOUT,0); |
30 | }; |
31 | |
32 | isa_ok($@, 'autodie::exception', "Truncating STDOUT should throw an exception"); |
33 | |
34 | } |
35 | |
36 | eval { |
37 | use autodie; |
38 | no warnings 'once'; |
39 | truncate(\*FOO, 0); |
40 | }; |
41 | |
42 | isa_ok($@, 'autodie::exception', "Truncating an unopened file is wrong."); |
43 | |
44 | $tmpfh->print("Hello World"); |
45 | $tmpfh->flush; |
46 | |
47 | eval { |
48 | use autodie; |
49 | truncate($tmpfh, 0); |
50 | }; |
51 | |
52 | is($@, "", "Truncating a normal file should be fine"); |