Skip to content

Commit

Permalink
closes #12;
Browse files Browse the repository at this point in the history
if a caller wants to use the platform's recsep in write, just call platform_recsep() and send that in as the custom recsep directly
  • Loading branch information
stevieb9 committed Jan 22, 2016
1 parent 92c3d59 commit c7fc220
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 30 deletions.
5 changes: 3 additions & 2 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Revision history for File-Edit-Portable

1.16 2016-01-22
- disabled the lock test if RELEASE_TESTING isn't available, as it was
failing on a small number of situations
- closes #15; removed the write() lock test completely
- closes #12; platform_recsep() can be used as the custom recsep to
write(). Added tests to confirm this

1.15 2016-01-18
- we now LOCK_EX in write() (prereq Fcntl)
Expand Down
3 changes: 0 additions & 3 deletions lib/File/Edit/Portable.pm
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ sub write {
}
}

# the following allows unit tests to test the lock
sleep 1 if $ENV{TEST_WRITE_LOCK};

close $wfh;
$self->{is_read} = 0;

Expand Down
40 changes: 15 additions & 25 deletions t/02-write.t
Original file line number Diff line number Diff line change
Expand Up @@ -100,40 +100,30 @@ my $rw = File::Edit::Portable->new;

is($recsep_sub->called_count, 3, "recsep() is called if ! is_read");
}
{
SKIP: {
skip "RELEASE_TESTING not enabled for lock test", 1 if ! $ENV{RELEASE_TESTING};
SKIP: {

$ENV{TEST_WRITE_LOCK} = 1;
skip "win32 test, but not on windows", 1 unless $^O eq 'MSWin32';

my @file = $rw->read($unix);
my $fh = $rw->read($unix);

writing($rw, \@file);
$rw->write(copy => $copy, contents => $fh, recsep => $rw->platform_recsep);

sleep 1;
my $eor = $rw->recsep($copy, 'hex');

open my $fh, '<', $copy or die $!;
is ($eor, '\0d\0a', "platform_recsep() w/ no parameters can be used as custom recsep" );
};
SKIP: {

eval {
flock($fh, LOCK_EX | LOCK_NB) or die "can't lock write file";
1;
};
skip "nix test but we're not on unix", 1 unless $^O ne 'MSWin32';

like ($@, qr/can't lock write file/, "when writing, file is locked ok");
print "here";
sleep 1; # because we need to wait for the fork() to finish
};
}
my $fh = $rw->read($unix);

done_testing();
$rw->write(copy => $copy, contents => $fh, recsep => $rw->platform_recsep);

sub writing {
my ($rw, $contents) = @_;
my $pid = fork;
my $eor = $rw->recsep($copy, 'hex');

return if $pid;
is ($eor, '\0d\0a', "platform_recsep() w/ no parameters can be used as custom recsep" );
};

$rw->write(copy => $copy, contents => $contents);
done_testing();

exit 0;
}

0 comments on commit c7fc220

Please sign in to comment.