tagged release 0.6.4
[parrot.git] / t / configure / 044-slurp_file.t
blob7844977fc673b27395d816a0225334b9c7ccb077
1 #! perl
2 # Copyright (C) 2007, The Perl Foundation.
3 # $Id$
4 # 044-slurp_file.t
6 use strict;
7 use warnings;
9 use Test::More tests => 10;
10 use Carp;
11 use_ok( 'File::Temp', qw| tempfile | );
12 use lib qw( lib );
13 use Parrot::BuildUtil;
16     my ( $fh, $tempfile ) = tempfile( UNLINK => 1 );
17     open $fh, ">", $tempfile
18         or croak "Unable to open tempfile for writing";
19     print $fh "Testing Parrot::BuildUtil::slurp_file()\n";
20     close $fh or croak "Unable to close tempfile after writing";
22     ok( -f $tempfile, "tempfile created for testing" );
23     my $str = Parrot::BuildUtil::slurp_file($tempfile);
24     ok( $str, "slurpfile() returned true value" );
25     like(
26         $str,
27         qr/Testing Parrot::BuildUtil::slurp_file/,
28         "Main content of tempfile correctly slurped"
29     );
33     my ( $fh, $tempfile ) = tempfile( UNLINK => 1 );
34     open $fh, ">", $tempfile
35         or croak "Unable to open tempfile for writing";
36     print $fh "Testing Parrot::BuildUtil::slurp_file()\cM\cJ\n";
37     close $fh or croak "Unable to close tempfile after writing";
39     ok( -f $tempfile, "tempfile created for testing" );
40     my $str = Parrot::BuildUtil::slurp_file($tempfile);
41     ok( $str, "slurpfile() returned true value" );
42     like(
43         $str,
44         qr/Testing Parrot::BuildUtil::slurp_file/,
45         "Main content of tempfile correctly slurped"
46     );
47     like( $str, qr/\n{2}/m, "DOS line endings correctly converted during slurp_file" );
51     my $phony = q{foobar};
52     my $str;
53     eval { $str = Parrot::BuildUtil::slurp_file($phony); };
54     like(
55         $@,
56         qr/open '$phony'/,
57         "Got error message expected upon attempting to slurp non-existent file"
58     );
61 pass("Completed all tests in $0");
63 ################### DOCUMENTATION ###################
65 =head1 NAME
67 044-slurp_file.t - test C<Parrot::BuildUtil::slurp_file()>
69 =head1 SYNOPSIS
71     % prove t/configure/044-slurp_file.t
73 =head1 DESCRIPTION
75 The files in this directory test functionality used by F<Configure.pl>.
77 The tests in this file test C<Parrot::BuildUtil::slurp_file()>.
79 =head1 AUTHOR
81 James E Keenan
83 =head1 SEE ALSO
85 Parrot::BuildUtil, F<Configure.pl>.
87 =cut
89 # Local Variables:
90 #   mode: cperl
91 #   cperl-indent-level: 4
92 #   fill-column: 100
93 # End:
94 # vim: expandtab shiftwidth=4: