From 6f3681b86d21901afec555dee2ab263fd98fc382 Mon Sep 17 00:00:00 2001 From: sbertrand Date: Tue, 12 Jan 2016 08:23:44 -0700 Subject: [PATCH] Added tests for remove() --- t/02-file_extentions.t | 4 ++-- t/45-inject.t | 2 +- t/49-remove.t | 35 +++++++++++++++++++++++++++++++++++ t/__clean.t | 3 ++- 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 t/49-remove.t diff --git a/t/02-file_extentions.t b/t/02-file_extentions.t index 589f0e2..496b435 100644 --- a/t/02-file_extentions.t +++ b/t/02-file_extentions.t @@ -33,7 +33,7 @@ use_ok( 'File::Edit::Portable' ) || print "Bail out!\n"; types => [qw(*.t)], ); - is (@files, 53, "using *.t extension works properly"); + is (@files, 54, "using *.t extension works properly"); @files = $rw->dir( dir => $dir, @@ -49,7 +49,7 @@ use_ok( 'File::Edit::Portable' ) || print "Bail out!\n"; types => [qw(*.data *.t)], ); - is (@files, 60, "using *.data and *.t extensions works properly"); + is (@files, 61, "using *.data and *.t extensions works properly"); } diff --git a/t/45-inject.t b/t/45-inject.t index 5354eeb..cfb073a 100644 --- a/t/45-inject.t +++ b/t/45-inject.t @@ -62,7 +62,7 @@ my $rw = File::Edit::Portable->new; copy => $copy, ); - my @code = ('hello();'); + my @code = ('hello();', "\n", 'there();'); $des->inject(inject_after_sub_def => \@code); diff --git a/t/49-remove.t b/t/49-remove.t new file mode 100644 index 0000000..caee5d2 --- /dev/null +++ b/t/49-remove.t @@ -0,0 +1,35 @@ +#!perl +use warnings; +use strict; + +use Data::Dumper; +use File::Copy; +use Test::More tests => 4; + +use_ok( 'Devel::Examine::Subs' ) || print "Bail out!\n"; + +my $file = 't/sample.data'; +my $copy = 't/remove.data'; + +eval{ copy $file, $copy or die $!; }; +is ($@, '', "sample file copied ok"); + +$file = $copy; + +my $des = Devel::Examine::Subs->new ( + file => $file, +); + +{ + $des->remove(delete => ["# sample data file"]); + + open my $fh, '<', $copy or die $!; + + my $line = <$fh>; + + like ($line, qr/package/, "remove deletes properly"); +} + +eval { unlink $file or die $!; }; +is ($@, '', "test data file removed ok"); + diff --git a/t/__clean.t b/t/__clean.t index c66c946..6b12e2c 100644 --- a/t/__clean.t +++ b/t/__clean.t @@ -2,7 +2,7 @@ use warnings; use strict; -use Test::More tests => 28; +use Test::More tests => 30; use File::Copy qw(copy); BEGIN {#1 @@ -35,6 +35,7 @@ my @files_to_delete = qw( t/engine_dump.debug t/post_proc_dump.debug t/pre_proc_dump.debug + t/remove.data ); my @bak_glob = <*.bak>;