Switching to `` requires one more \ to escape $Config in new_config=`...`
[p5sagit/p5-mst-13.2.git] / t / lib / autodie / truncate.t
CommitLineData
0b09a93a 1#!/usr/bin/perl -w
2use strict;
3
4use Test::More;
5use File::Temp qw(tempfile);
6use IO::Handle;
7
8my $tmpfh = tempfile();
9
10eval {
11 truncate($tmpfh, 0);
12};
13
14if ($@) {
15 plan skip_all => 'Truncate not implemented on this system';
16}
17
18plan tests => 3;
19
20SKIP: {
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
36eval {
37 use autodie;
38 no warnings 'once';
39 truncate(\*FOO, 0);
40};
41
42isa_ok($@, 'autodie::exception', "Truncating an unopened file is wrong.");
43
44$tmpfh->print("Hello World");
45$tmpfh->flush;
46
47eval {
48 use autodie;
49 truncate($tmpfh, 0);
50};
51
52is($@, "", "Truncating a normal file should be fine");