9 our @TEST = stat "TEST";
10 our @README = stat "README";
11 unless (@TEST && @README) {
12 print "1..0 # Skip: no file TEST or README\n";
19 use File::Compare qw(compare compare_text);
23 # named files, same, existing but different, cause an error
24 print "not " unless compare("README","README") == 0;
27 print "not " unless compare("TEST","README") == 1;
30 print "not " unless compare("README","HLAGHLAG") == -1;
31 # a file which doesn't exist
34 # compare_text, the same file, different but existing files
35 # cause error, test sub form.
36 print "not " unless compare_text("README","README") == 0;
39 print "not " unless compare_text("TEST","README") == 1;
42 print "not " unless compare_text("TEST","HLAGHLAG") == -1;
46 compare_text("README","README",sub {$_[0] ne $_[1]}) == 0;
49 # filehandle and same file
52 open ($fh, "<README") or print "not ";
54 print "not " unless compare($fh,"README") == 0;
59 # filehandle and different (but existing) file.
62 open ($fh, "<README") or print "not ";
64 print "not " unless compare_text($fh,"TEST") == 1;
69 # Different file with contents of known file,
70 # will use File::Temp to do this, skip rest of
71 # tests if this doesn't seem to work
75 require File::Spec; import File::Spec;
76 require File::Path; import File::Path;
77 require File::Temp; import File::Temp qw/ :mktemp unlink0 /;
79 my $template = File::Spec->catfile(File::Spec->tmpdir, 'fcmpXXXX');
80 my($tfh,$filename) = mkstemp($template);
91 $donetests[0] = compare($tfh, 'README');
92 $donetests[1] = compare($filename, 'README');
93 unlink0($tfh,$filename);
95 print "# problems when testing with a tempory file\n" if $@;
97 if (@donetests == 2) {
98 print "not " unless $donetests[0] == 0;
101 # The open attempt on FROM in File::Compare::compare should fail
102 # on this OS since files are not shared by default.
103 print "not " unless $donetests[1] == -1;
107 print "not " unless $donetests[1] == 0;
112 print "ok 11# Skip\nok 12 # Skip Likely due to File::Temp\n";