[svn:parrot] r49803 - in branches/tt532_headerizer_refactor: lib/Parrot/Headerizer t/tools/dev/headerizer
jkeenan at svn.parrot.org
jkeenan at svn.parrot.org
Mon Nov 8 02:56:12 UTC 2010
Author: jkeenan
Date: Mon Nov 8 02:56:12 2010
New Revision: 49803
URL: https://trac.parrot.org/parrot/changeset/49803
Log:
Write basic tests of read_file() and write_file().
Modified:
branches/tt532_headerizer_refactor/lib/Parrot/Headerizer/Functions.pm
branches/tt532_headerizer_refactor/t/tools/dev/headerizer/01_functions.t
Modified: branches/tt532_headerizer_refactor/lib/Parrot/Headerizer/Functions.pm
==============================================================================
--- branches/tt532_headerizer_refactor/lib/Parrot/Headerizer/Functions.pm Mon Nov 8 02:41:51 2010 (r49802)
+++ branches/tt532_headerizer_refactor/lib/Parrot/Headerizer/Functions.pm Mon Nov 8 02:56:12 2010 (r49803)
@@ -18,6 +18,7 @@
=head1 SYNOPSIS
use Parrot::Headerizer::Functions qw(
+ print_headerizer_warnings
read_file
write_file
);
@@ -53,6 +54,9 @@
}
}
+# We can't alias this to Parrot::BuildUtil::slurp_file() because that function
+# changes DOS line endings to Unix, which we don't necessarily want here.
+
sub read_file {
my $filename = shift;
Modified: branches/tt532_headerizer_refactor/t/tools/dev/headerizer/01_functions.t
==============================================================================
--- branches/tt532_headerizer_refactor/t/tools/dev/headerizer/01_functions.t Mon Nov 8 02:41:51 2010 (r49802)
+++ branches/tt532_headerizer_refactor/t/tools/dev/headerizer/01_functions.t Mon Nov 8 02:56:12 2010 (r49803)
@@ -7,9 +7,10 @@
use warnings;
use Test::More qw(no_plan); # tests => 60;
use Cwd;
-use File::Basename;
-use File::Copy;
+#use File::Basename;
+#use File::Copy;
use File::Temp qw( tempdir );
+use Tie::File;
use lib qw( lib );
use Parrot::Headerizer::Functions qw(
print_headerizer_warnings
@@ -18,6 +19,28 @@
);
use IO::CaptureOutput qw| capture |;
+my $cwd = cwd();
+{
+ my $tdir = tempdir( CLEANUP => 1 );
+ chdir $tdir;
+ my $file = "filename$$";
+ my @lines_to_write = (
+ "Goodbye\n",
+ "cruel\n",
+ "world\n",
+ );
+ my $text = join( '' => @lines_to_write );
+ write_file($file, $text);
+ ok(-f $file, "File was written");
+
+ my $text_returned = read_file($file);
+ ok($text_returned, "Got non-empty string back from read_file()");
+ my @lines_read = split /\n/, $text_returned;
+ is($lines_read[0], 'Goodbye', "Got first line");
+ is($lines_read[1], 'cruel', "Got second line");
+ is($lines_read[2], 'world', "Got third line");
+}
+
pass("Completed all tests in $0");
More information about the parrot-commits
mailing list