From 02c8fbd5fbe95ada9ecfd79c7c67d9ce48ff0232 Mon Sep 17 00:00:00 2001 From: Alexander Gough Date: Thu, 31 May 2001 14:26:34 +0100 Subject: [PATCH] Re: [PATCH] Tests for File::Compare Message-Id: p4raw-id: //depot/perl@10354 --- MANIFEST | 1 + t/lib/1_compile.t | 1 + t/lib/filecomp.t | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 t/lib/filecomp.t diff --git a/MANIFEST b/MANIFEST index 8da41ab..2af84c0 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1524,6 +1524,7 @@ t/lib/fatal.t See if Fatal works t/lib/fcntl.t See if Fcntl works t/lib/fields.t See if base/fields works t/lib/filecache.t See if FileCache works +t/lib/filecomp.t See if File::Compare works t/lib/filecopy.t See if File::Copy works t/lib/filefind.t See if File::Find works t/lib/filefunc.t See if File::Spec::Functions works diff --git a/t/lib/1_compile.t b/t/lib/1_compile.t index eb2d70b..e46e14b 100644 --- a/t/lib/1_compile.t +++ b/t/lib/1_compile.t @@ -147,6 +147,7 @@ Fatal Fcntl File::Basename File::CheckTree +File::Compare File::Copy File::DosGlob File::Find diff --git a/t/lib/filecomp.t b/t/lib/filecomp.t new file mode 100644 index 0000000..b841d87 --- /dev/null +++ b/t/lib/filecomp.t @@ -0,0 +1,103 @@ +#!./perl + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; +} + +BEGIN { + our @TEST = stat "TEST"; + our @README = stat "README"; + unless (@TEST && @README) { + print "1..0 # Skip: no file TEST or README\n"; + exit 0; + } +} + +print "1..12\n"; + +use File::Compare qw(compare compare_text); + +print "ok 1\n"; + +# named files, same, existing but different, cause an error +print "not " unless compare("README","README") == 0; +print "ok 2\n"; + +print "not " unless compare("TEST","README") == 1; +print "ok 3\n"; + +print "not " unless compare("README","HLAGHLAG") == -1; + # a file which doesn't exist +print "ok 4\n"; + +# compare_text, the same file, different but existing files +# cause error, test sub form. +print "not " unless compare_text("README","README") == 0; +print "ok 5\n"; + +print "not " unless compare_text("TEST","README") == 1; +print "ok 6\n"; + +print "not " unless compare_text("TEST","HLAGHLAG") == -1; +print "ok 7\n"; + +print "not " unless + compare_text("README","README",sub {$_[0] ne $_[1]}) == 0; +print "ok 8\n"; + +# filehandle and same file +{ + my $fh; + open ($fh, "catfile(File::Spec->tmpdir, 'fcmpXXXX'); + my($tfh,$filename) = mkstemp($template); + { + local $/; #slurp + my $fh; + open($fh,'README'); + my $data = <$fh>; + print $tfh $data; + close($fh); + } + seek($tfh,0,0); + $donetests[0] = compare($tfh,'README'); + $donetests[1] = compare("$filename",'README'); + unlink0($tfh,$filename); +}; +print "# problems when testing with a tempory file\n" if $@; + +if (@donetests == 2) { + print "not " unless $donetests[0] == 0; + print "ok 11\n"; + print "not " unless $donetests[1] == 0; + print "ok 12\n"; +} +else { + print "ok 11# Skip\nok 12 # Skip Likely due to File::Temp\n"; +} + -- 1.8.3.1