"Fossies" - the Fresh Open Source Software Archive

Member "Archive-Tar-2.38/t/07_ptardiff.t" (14 Sep 2014, 1204 Bytes) of package /linux/privat/Archive-Tar-2.38.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 use strict;
    2 use warnings;
    3 use Test::More;
    4 
    5 use File::Spec;
    6 use FindBin '$Bin';
    7 use Archive::Tar;
    8 
    9 # filenames
   10 my $tartest = File::Spec->catfile("t", "ptardiff");
   11 my $foo = File::Spec->catfile("t", "ptardiff", "foo");
   12 my $bar = File::Spec->catfile("t", "ptardiff", "bar");
   13 my $tarfile = File::Spec->catfile("t", "ptardiff.tar");
   14 my $ptardiff = File::Spec->catfile($Bin, "..", "bin", "ptardiff");
   15 my $cmd = "$^X $ptardiff $tarfile";
   16 
   17 eval { require Text::Diff; };
   18 plan skip_all => 'Text::Diff required to test ptardiff' if $@;
   19 plan tests => 1;
   20 
   21 # create directory/files
   22 mkdir $tartest;
   23 open my $fh, ">", $foo or die $!;
   24 print $fh "file foo\n";
   25 close $fh;
   26 open $fh, ">", $bar or die $!;
   27 print $fh "file bar\n";
   28 close $fh;
   29 
   30 # create archive
   31 my $tar = Archive::Tar->new;
   32 $tar->add_files($foo, $bar);
   33 $tar->write($tarfile);
   34 
   35 # change file
   36 open $fh, ">>", $foo or die $!;
   37 print $fh "added\n";
   38 close $fh;
   39 
   40 # see if ptardiff shows the changes
   41 my $out = qx{$cmd};
   42 cmp_ok($out, '=~', qr{^\+added$}m, "ptardiff shows added text");
   43 
   44 # cleanup
   45 END {
   46     unlink $tarfile;
   47     if ( -e $foo ) { unlink $foo or die $!; }
   48     if ( -e $bar ) { unlink $bar or die $!; }
   49     if ( -d $tartest ) { rmdir $tartest or die $!; }
   50 }