Author: jkeenan Date: Sat Sep 8 18:56:11 2007 New Revision: 21149 Added: branches/reconfigure/t/configure/039-slurp_file.t (contents, props changed) Modified: branches/reconfigure/MANIFEST branches/reconfigure/lib/Parrot/BuildUtil.pm
Log: Adding new test file t/configure/039-slurp_file.t. Andy slurped slurp_file into Parrot::BuildUtil last month. This file supplies unit tests. Cf.: RT 44607. Modified: branches/reconfigure/MANIFEST ============================================================================== --- branches/reconfigure/MANIFEST (original) +++ branches/reconfigure/MANIFEST Sat Sep 8 18:56:11 2007 @@ -1,7 +1,7 @@ # ex: set ro: # $Id$ # -# generated by tools/dev/mk_manifest_and_skip.pl Fri Sep 7 00:21:04 2007 UT +# generated by tools/dev/mk_manifest_and_skip.pl Sun Sep 9 01:48:45 2007 UT # # See tools/dev/install_files.pl for documentation on the # format of this file. @@ -2917,6 +2917,7 @@ t/configure/036_config_steps.t [] t/configure/037-run_single_step.t [] t/configure/038-run_single_step.t [] +t/configure/039-slurp_file.t [] t/configure/101-init_manifest.01.t [] t/configure/101-init_manifest.02.t [] t/configure/102-init_defaults.01.t [] Modified: branches/reconfigure/lib/Parrot/BuildUtil.pm ============================================================================== --- branches/reconfigure/lib/Parrot/BuildUtil.pm (original) +++ branches/reconfigure/lib/Parrot/BuildUtil.pm Sat Sep 8 18:56:11 2007 @@ -7,9 +7,9 @@ =head1 DESCRIPTION -For now, this package contains only one subroutine: C<parrot_version()>. -This subroutine is not exported and so must be requested with a fully -qualified path. +This package holds two subroutines: C<parrot_version()> and +<slurp_file>. Neither subroutine is exported and so each must be +requested with a fully qualified path. =cut @@ -69,7 +69,8 @@ =item C<slurp_file($filename)> -Slurps up the filename and returns the content as one string. +Slurps up the filename and returns the content as one string. While +doing so, it converts all DOS-style line endings to newlines. =cut Added: branches/reconfigure/t/configure/039-slurp_file.t ============================================================================== --- (empty file) +++ branches/reconfigure/t/configure/039-slurp_file.t Sat Sep 8 18:56:11 2007 @@ -0,0 +1,79 @@ +#! perl +# Copyright (C) 2007, The Perl Foundation. +# $Id$ +# 039-slurp_file.t + +use strict; +use warnings; + +use Test::More tests => 9; +use Carp; +use_ok( 'File::Temp', qw| tempfile | ); +use lib qw( lib ); +use Parrot::BuildUtil; + +{ + my ($fh, $tempfile) = tempfile(); + open $fh, ">", $tempfile + or croak "Unable to open tempfile for writing"; + print $fh "Testing Parrot::BuildUtil::slurp_file()\n"; + close $fh or croak "Unable to close tempfile after writing"; + + ok(-f $tempfile, "tempfile created for testing"); + my $str = Parrot::BuildUtil::slurp_file($tempfile); + ok($str, "slurpfile() returned true value"); + like($str, qr/Testing Parrot::BuildUtil::slurp_file/, + "Main content of tempfile correctly slurped"); +} + +{ + my ($fh, $tempfile) = tempfile(); + open $fh, ">", $tempfile + or croak "Unable to open tempfile for writing"; + print $fh "Testing Parrot::BuildUtil::slurp_file()\cM\cJ\n"; + close $fh or croak "Unable to close tempfile after writing"; + + ok(-f $tempfile, "tempfile created for testing"); + my $str = Parrot::BuildUtil::slurp_file($tempfile); + ok($str, "slurpfile() returned true value"); + like($str, qr/Testing Parrot::BuildUtil::slurp_file/, + "Main content of tempfile correctly slurped"); + like($str, qr/\n{2}/m, + "DOS line endings correctly converted during slurp_file"); +} + +pass("Completed all tests in $0"); + +################### DOCUMENTATION ################### + +=head1 NAME + +039-slurp_file.t - test C<Parrot::BuildUtil::slurp_file()> + +=head1 SYNOPSIS + + % prove t/configure/039-slurp_file.t + +=head1 DESCRIPTION + +The files in this directory test functionality used by F<Configure.pl>. + +The tests in this file test C<Parrot::BuildUtil::slurp_file()>. + +=head1 AUTHOR + +James E Keenan + +=head1 SEE ALSO + +Parrot::BuildUtil, F<Configure.pl>. + +=cut + +# Local Variables: +# mode: cperl +# cperl-indent-level: 4 +# fill-column: 100 +# End: +# vim: expandtab shiftwidth=4: +