Skip to content

Commit

Permalink
Write basic tests of read_file() and write_file().
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.parrot.org/parrot/branches/tt532_headerizer_refactor@49803 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
jkeenan committed Nov 8, 2010
1 parent 619ef4d commit d7649c0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/Parrot/Headerizer/Functions.pm
Expand Up @@ -18,6 +18,7 @@ Parrot::Headerizer::Functions - Functions used in headerizer programs
=head1 SYNOPSIS
use Parrot::Headerizer::Functions qw(
print_headerizer_warnings
read_file
write_file
);
Expand Down Expand Up @@ -53,6 +54,9 @@ sub print_headerizer_warnings {
}
}

# 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;

Expand Down
27 changes: 25 additions & 2 deletions t/tools/dev/headerizer/01_functions.t
Expand Up @@ -7,9 +7,10 @@ use strict;
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
Expand All @@ -18,6 +19,28 @@ use Parrot::Headerizer::Functions qw(
);
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");

Expand Down

0 comments on commit d7649c0

Please sign in to comment.