Test-Files-0.15/040755 000452 000311 00000000000 13761421132 013305 5ustar00miejfedi000000 000000 Test-Files-0.15/Changes100644 000452 000311 00000011410 13761367677 014621 0ustar00miejfedi000000 000000 Revision history for Perl extension Test::Files. 0.15 Tue Dec 1 08:22:14 CET 2020 - Got rid of index built-in causing severe issues during test coverage determination due to a still unfixed bug in Devel::Cover. 0.14 Wed Mar 28 10:14:05 CDT 2007 - Removed use Test::More from Test::Files package, which was causing chatter during TODO tests that confused the harness. Thanks to Julien Beasley for pointing out the problem and to Schwern for sending the patch. Apologies to all CPAN users for omitting the following change entry from the 0.13 distribution. 0.13 Wed Feb 14 09:45:54 CST 2007 - Added file_filter_ok, like the other filter functions. 0.12 Wed Mar 1 16:35:30 PST 2006 Thanks to Robin Barker for help with all of the changes for this release. - Added solaris to the list of unix style operating systems in tests 06 and 07. - Altered the wanted sub in dir_only_contains_ok to test more carefully for the base directory (which should be skipped). - Corrected base_dir skip test in compare_dirs_only_ok. A recent change in File::Spec invalidated the old approach. 0.11 Mon Nov 7 17:01:59 CST 2005 - Added Algorithm::Diff to the prereq list in Makefile.PL (Text::Diff already requires it, but I wanted to make it more explicit). - Corrected docs to explain that compare_dirs_ok and compare_dirs_filter_ok compare files from the first directory (and its sub dirs) to files in the second directory. Files missing from the second directory are noted, but files missing from the first directory are not. Callers should combine this test with dir_contains_ok or dir_contains_only-ok, if they want to ensure that the first directory is complete. 0.10 Mon Sep 5 10:57:12 CDT 2005 - Converted to File::Spec inside the module and in the test suite. - Added compare_filter_ok which works like compare_dirs_filter_ok, but for single comparisons. - Added documentation to make clear that this module uses Text::Diff to report tables of diff output when text contents of files it is comparing differ. 0.05 Mon Oct 20 15:13:50 CDT 2003 - Corrected diagnostic output in compare_dirs* so that each missing file is listed on its own line. Previously, they were juxtaposed on one line, including very pleasant #'s for decoration. - Changed Files.pm so none of the tests report timestamps. Some OSes (notably Solaris) translated the timestamps, probably to deal with time zones. I am explicitly deciding that timestamps do not count in file comparisons. If you need to test timestamps, use -M etc. Remember that the person installing your module won't always be in your timezone. - Corrected tests to reflect the removal of time stamps from file_ok output. - Sorted the list of missing files in compare_dirs* so that I can test the error message (and the new vesion is neater). 0.04 Fri Oct 17 09:14:20 CDT 2003 - Added compare_dirs_filter_ok which works like compare_dirs_ok, but sends each line of input through a caller supplied filter function first. This allows you to remove things like timestamps which though different should not count as failure. - Refactored to avoid code duplication in the compare_dirs* functions. - On advice from Schwern, converted tests to use the very nice Test::Builder::Tester. This made the tests nicer and easier to work on, but had no affect on the Files.pm code. - Improved the documentation (well I think it as in improvement) 0.03 Wed Oct 15 10:02:49 CDT 2003 - Made various refactorings to increase code reuse. - Changed from using Test::Differences to using Text::Diff. This has two advantages: 1. It makes it slightly easier to have the location of the error correctly reported when a test fails. 2. It enables compares_dirs_ok which needs to compare lots of files while reporting a single error. - Added compare_dirs_ok which compares all files in a pair of directory, failing with diff diagnostics if any disagree. 0.02 Mon Oct 13 15:03:17 CDT 2003 - Added dir_contains_ok which checks a directory for the presence of named files. - Added dir_only_contains_ok which makes sure that a directory has exactly a specified list of elements, nothing more or less. This is a bit awkward since you must currently list subdirectories explicitly, lest they show up in the list of unexpectedly seen files. - Corrected diagnostic output so it works like other Test:: modules. Previously, I had folded some error output into the test name 0.01 Thu Oct 9 13:14:55 2003 - original version; created by h2xs 1.22 with options -AXn Test::Files -b 5.6.0 Test-Files-0.15/Files.pm100644 000452 000311 00000033144 13761417760 014723 0ustar00miejfedi000000 000000 package Test::Files; use File::Find; use File::Spec; use Test::Builder; use Text::Diff; use strict; use warnings; # This is off in Test::More, eventually it may have to go. require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw( file_ok file_filter_ok compare_ok compare_filter_ok dir_contains_ok dir_only_contains_ok compare_dirs_ok compare_dirs_filter_ok ); our $VERSION = '0.15'; my $Test = Test::Builder->new; my $diff_options = { CONTEXT => 3, # change this one later if needed STYLE => "Table", FILENAME_A => "Got", FILENAME_B => "Expected", OFFSET_A => 1, OFFSET_B => 1, INDEX_LABEL => "Ln", MTIME_A => "", MTIME_B => "", }; sub file_ok { my $candidate_file = shift; my $expected = shift; my $name = shift; unless (-f $candidate_file and -r _) { $Test->ok(0, $name); $Test->diag("$candidate_file absent"); return; } # chomping and reappending the line ending was done in # Test::Differences::eq_or_diff my $diff = diff($candidate_file, \$expected, $diff_options); chomp $diff; my $failed = length $diff; $diff .= "\n"; if ($failed) { $Test->ok(0, $name); $Test->diag($diff); } else { $Test->ok(1, $name); } } sub file_filter_ok { my $candidate_file = shift; my $expected = shift; my $filter = shift; my $name = shift; unless (open CANDIDATE, "$candidate_file") { $Test->ok(0, $name); $Test->diag( "$candidate_file absent" ); return; } my $candidate = _read_and_filter_handle( *CANDIDATE, $filter ); # chomping and reappending the line ending was done in # Test::Differences::eq_or_diff my $diff = diff(\$candidate, \$expected, $diff_options); chomp $diff; my $failed = length $diff; $diff .= "\n"; if ($failed) { $Test->ok(0, $name); $Test->diag($diff); } else { $Test->ok(1, $name); } } sub _read_two_files { my $first = shift; my $second = shift; my $filter = shift; my $success = 1; my @errors; unless (open FIRST, "$first") { $success = 0; push @errors, "$first absent"; } unless (open SECOND, "$second") { $success = 0; push @errors, "$second absent"; } return ($success, @errors) unless $success; my $first_data = _read_and_filter_handle(*FIRST, $filter); my $second_data = _read_and_filter_handle(*SECOND, $filter); close FIRST; close SECOND; return ($success, $first_data, $second_data); } sub _read_and_filter_handle { my $handle = shift; my $filter = shift; if ($filter) { my @retval; while (<$handle>) { my $filtered = $filter->($_); push @retval, $filtered if $filtered; } return join "", @retval; } else { return join "", <$handle>; } } sub compare_ok { my $got_file = shift; my $expected_file = shift; my $name = shift; @_ = ($got_file, $expected_file, undef, $name); goto &compare_filter_ok; } sub compare_filter_ok { my $got_file = shift; my $expected_file = shift; my $filter = shift; my $name = shift; my @read_result = _read_two_files($got_file, $expected_file, $filter); my $files_exist = shift @read_result; if ($files_exist) { my ($got, $expected) = @read_result; # chomping and reappending the line ending was done in # Test::Differences::eq_or_diff my $diff = diff(\$got, \$expected, $diff_options); chomp $diff; my $failed = length $diff; $diff .= "\n"; if ($failed) { $Test->ok(0, $name); $Test->diag($diff); } else { $Test->ok(1, $name); } } else { $Test->ok(0, $name); $Test->diag(join "\n", @read_result); } } sub _dir_missing_helper { my $base_dir = shift; my $list = shift; my $name = shift; my $function = shift; unless (-d $base_dir) { return(0, "$base_dir absent"); } if (ref($list) ne 'ARRAY') { return(0, "$function requires array ref as second arg"); } my @missing; foreach my $element (@$list) { my $elem_path = File::Spec->catfile( $base_dir, $element ); push @missing, $element unless (-e $elem_path ); } return (\@missing); } sub dir_contains_ok { my $base_dir = shift; my $list = shift; my $name = shift; my @result = _dir_missing_helper( $base_dir, $list, $name, 'dir_contains_ok' ); if (@result == 2) { $Test->ok(0, $name); $Test->diag($result[1]); return; } my $missing = $result[0]; if (@$missing) { $Test->ok(0, $name); $Test->diag("failed to see these: @$missing"); } else { $Test->ok(1, $name); } } sub dir_only_contains_ok { my $base_dir = shift; my $list = shift; my $name = shift; my @result = _dir_missing_helper( $base_dir, $list, $name, 'dir_only_contains_ok' ); if (@result == 2) { $Test->ok(0, $name); $Test->diag($result[1]); return; } my $missing = $result[0]; my $success; my @diags; if (@$missing) { $success = 0; push @diags, "failed to see these: @$missing"; } else { $success = 1; } # Then, make sure no other files are present. my %expected; my @unexpected; @expected{ @$list } = (); # by defining $contains here, it can use our scope my $contains = sub { my $name = $File::Find::name; return if ($name eq $base_dir); $name = File::Spec->abs2rel( $name, $base_dir ); push @unexpected, $name unless (exists $expected{$name}); }; find($contains, ($base_dir)); if (@unexpected) { $success = 0; my $unexp = @unexpected; push @diags, "unexpectedly saw: @unexpected"; } $Test->ok($success, $name); $Test->diag(join "\n", @diags) if @diags; } sub compare_dirs_ok { my $first_dir = shift; my $second_dir = shift; my $name = shift; @_ = ($first_dir, $second_dir, undef, $name); goto &compare_dirs_filter_ok; } sub compare_dirs_filter_ok { my $first_dir = shift; my $second_dir = shift; my $filter = shift; my $name = shift; unless (-d $first_dir) { $Test->ok(0, $name); $Test->diag("$first_dir is not a valid directory"); return; } unless (-d $second_dir) { $Test->ok(0, $name); $Test->diag("$second_dir is not a valid directory"); return; } unless (not defined $filter or ref($filter) eq 'CODE') { $Test->ok(0, $filter); $Test->diag( "Third argument to compare_dirs_filter_ok must be " . "a code reference (or undef)" ); return; } my @diags; my $matches = sub { my $name = $File::Find::name; return if (-d $name); $name = File::Spec->abs2rel( $name, $first_dir ); return if length($name) < 1; # skip the base directory my $first_file = File::Spec->catfile( $first_dir, $name ); my $second_file = File::Spec->catfile( $second_dir, $name ); my @result = _read_two_files( $first_file, $second_file, $filter ); my $files_exist = shift @result; if ($files_exist) { my ($got, $expected) = @result; my $diff = diff( \$got, \$expected, { %$diff_options, FILENAME_A => $first_file, FILENAME_B => $second_file, } ); chomp $diff; my $failed = length $diff; $diff .= "\n"; if ($failed) { push @diags, $diff; } } else { push @diags, "$result[0]\n"; } }; find({ wanted => $matches, no_chdir => 1 }, $first_dir); if (@diags) { $Test->ok(0, $name); $Test->diag(sort @diags); } else { $Test->ok(1, $name); } } 1; __END__ =head1 NAME Test::Files - A Test::Builder based module to ease testing with files and dirs =head1 SYNOPSIS use Test::More tests => 5; use Test::Files; use File::Spec; my $some_file = File::Spec->catfile( qw/ path to some file / ); my $other_file = File::Spec->catfile( qw/ path to other file / ); my $some_dir = File::Spec->catdir ( qw/ some dir / ); my $other_dir = File::Spec->catdir ( qw/ dir with same stuff / ); file_ok($some_file, "contents\nof file", "some file has contents"); file_filter_ok( $some_file, "filtered contents\nof file", \&filter, "some file has contents" ); compare_ok($some_file, $other_file, "files are the same"); compare_filter_ok( $file1, $file2, \&filter, "they're almost the same" ); dir_contains_ok( $some_dir, [qw(files some_dir must contain)], "$some_dir has all files in list" ); dir_only_contains_ok( $some_dir, [qw(files some_dir should contain)], "$some_dir has exactly the files in the list" ); compare_dirs_ok($some_dir, $other_dir); compare_dirs_filter_ok($some_dir, $other_dir, \&filter_fcn); =head1 ABSTRACT Test::Builder based test helper for file and directory contents. =head1 DESCRIPTION This module is like Test::More, in fact you should use that first as shown above. It exports =over 4 =item file_ok compare the contents of a file to a string =item file_filter_ok compare the contents of a file to a string, but filter the file first. (You must filter your own string if needed.) =item compare_ok compare the contents of two files =item compare_filter_ok compare the contents of two files, but sends each line through a filter so things that shouldn't count against success can be stripped =item dir_contains_ok checks a directory for the presence of a list files =item dir_contains_only_ok checks a directory to ensure that the listed files are present and that they are the only ones present =item compare_dirs_ok compares all text files in two directories reporting any differences =item compare_dirs_filter_ok works like compare_dirs_ok, but calls a filter function on each line of input, allowing you to exclude or alter some text to avoid spurious failures (like timestamp disagreements). =back Though the SYNOPSIS examples don't all have names, you can and should provide a name for each test. Names are omitted above only to reduce clutter and line widths. You should follow the lead of the SYNOPSIS examples and use File::Spec. This makes it much more likely that your tests will pass on a different operating system. All of the content comparison routines provide diff diagnostic output when they report failure. Currently that diff output is always in table form and can't be changed. Most of the functions are self explanatory. One exception is C which compares two directory trees, like C but with a twist. The twist is a filter which each line is fed through before comparison. I wanted this because some files are really the same, but look different textually. In particular, I was comparing files with machine generated dates. Everything in them was identical, except those dates. The filter function receives each line of each file. It may perform any necessary transformations (like excising dates), then it must return the line in (possibly) transformed state. For example, my first filter was sub chop_dates { my $line = shift; $line =~ s/\d{4}(.\d\d){5}//; return $line; } This removes all strings like 2003.10.14.14.17.37. Everything else is unchanged and my failing tests started passing when they shold. If you want to exclude the line from consideration, return "" (do not return undef, that makes it harder to chain filters together and might lead to warnings). C works in a similar manner for a single file comparison, while C filters the file before comparing it to your unfiltered string. The test suite has examples of the use of each function and what the output looks like on failure, though it that doesn't necessarily make them easy to read. =head2 BUGS C and C do not test for whether the first directory has all the files that are in the second. If you care about missing files in the first direcotry, you must also call C or C. The C routines do notice when the second directory does not have a files that the first one has. =head2 EXPORT file_ok file_filter_ok compare_ok compare_filter_ok dir_contains_ok dir_only_contains_ok compare_dirs_ok compare_dirs_filter_ok =head1 DEPENDENCIES Algorithm::Diff Test::Builder Test::More Text::Diff Test::Builder::Tester (used only during testing) =head1 SEE ALSO Consult Test::Simple, Test::More, and Test::Builder for more testing help. This module really just adds functions to what Test::More does. =head1 AUTHOR Phil Crow, Ephilcrow2000@yahoo.com Jurij Fajnberg, Efajnbergj@gmail.com =head1 COPYRIGHT AND LICENSE Copyright 2003-2007 by Phil Crow Copyright 2020 by Jurij Fajnberg This library is free software; you can redistribute it and/or modify it under the same terms as Perl 5.8.1 itself. =cut Test-Files-0.15/MANIFEST100644 000452 000311 00000001063 13761421132 014433 0ustar00miejfedi000000 000000 Changes Files.pm Makefile.PL MANIFEST META.yml Module meta-data (added by MakeMaker) README t/01useok.t t/02file_ok.t t/03compare_ok.t t/04dir_contains_ok.t t/05dir_only_con.t t/06compare_dirs.t t/07comp_dir_f.t t/08comp_filt.t t/lib/Test/Simple/Catch.pm t/lib_fail/Test/Simple/Catch.pm t/lib_pass/Test/Simple/Catch.pm t/ok_pass.dat t/ok_pass.diff.dat t/ok_pass.same.dat t/time/time_stamp.dat t/time2/time_stamp.dat t/time3/t1 t/time3/t2 t/time3/t3 t/time3/time_stamp.dat TODO META.json Module JSON meta-data (added by MakeMaker) Test-Files-0.15/META.json100664 000452 000311 00000002124 13761421132 014724 0ustar00miejfedi000000 000000 { "abstract" : "A Test::Builder based module to ease testing with files and dirs", "author" : [ "Phil Crow " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.36, CPAN::Meta::Converter version 2.150005", "license" : [ "unknown" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Test-Files", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Algorithm::Diff" : "0", "Test::Builder" : "0", "Test::Builder::Tester" : "0", "Test::More" : "0", "Text::Diff" : "0" } } }, "release_status" : "stable", "version" : "0.15", "x_serialization_backend" : "JSON::PP version 4.04" } Test-Files-0.15/META.yml100664 000452 000311 00000001250 13761421131 014552 0ustar00miejfedi000000 000000 --- abstract: 'A Test::Builder based module to ease testing with files and dirs' author: - 'Phil Crow ' build_requires: ExtUtils::MakeMaker: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.36, CPAN::Meta::Converter version 2.150005' license: unknown meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Test-Files no_index: directory: - t - inc requires: Algorithm::Diff: '0' Test::Builder: '0' Test::Builder::Tester: '0' Test::More: '0' Text::Diff: '0' version: '0.15' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Test-Files-0.15/Makefile.PL100644 000452 000311 00000001224 13761420627 015263 0ustar00miejfedi000000 000000 use 5.006; use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( 'NAME' => 'Test::Files', 'VERSION_FROM' => 'Files.pm', # finds $VERSION 'PREREQ_PM' => { Test::Builder => 0, Test::More => 0, Test::Builder::Tester => 0, Text::Diff => 0, Algorithm::Diff => 0, }, ($] >= 5.005 ? ## Add these new keywords supported since 5.005 (ABSTRACT_FROM => 'Files.pm', # retrieve abstract from module AUTHOR => 'Phil Crow ') : () ), ); Test-Files-0.15/README100644 000452 000311 00000001265 13761371313 014173 0ustar00miejfedi000000 000000 Test/Files version 0.15 ======================= This module provides an extension of Test::More concerning files and directories tests considering their contents. For tests considering their attributes e.g. stat information please consult Test::File. INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES This module requires these other modules and libraries: File::Find File::Spec Test::Builder Text::Diff COPYRIGHT AND LICENCE Copyright (C) 2003 Phil Crow Copyright (C) 2020 Jurij Fajnberg This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Test-Files-0.15/TODO100644 000452 000311 00000004702 13761373360 014006 0ustar00miejfedi000000 000000 A user pointed out an error (in his opinion): compare_dirs_ok does not work properly on second level directories I have not verified that this error occurs compare_dirs_ok does not make sure that the first dir has all the files that appear in the second. It should call dir_contains_only_ok. The same user said that once compare_dirs_ok is fixed, there should be an option like --exclude in the standard diff. #----------------------------------------------------- Functions Schwern suggested which are not implemented yet: #----------------------------------------------------- dir_ok( "some/dir", { "foo" => "some/dir/foo would contain this", "bar" => "some/dir/bar would contain this", "baz/biff" => "some/dir/baz/biff would contain this" }); # I suggested using undef for the values here to request a check of structure # only, that is only file names would be examined, not contents. Yet, # Schwern had already suggested dir_contains_ok, which is probably more # directly intelligiable. #----------------------------------------------------- find_ok( "some/dir", sub { which will be run against all files in some/dir and returns true if they pass } ); #----------------------------------------------------- I suggested: dirs_agree("dir1", "dir2") Schwern suggested a new name for dirs_agree: compare_dirs_ok instead of dirs_agree (implemented in 0.03) (I'm extrapolating, he didn't make a direct suggestion, but his earlier suggestions point to something like this.) #----------------------------------------------------- After trying compare_dirs_ok I immediately wanted to be able to exclude some lines from the comparison. Namely, in my example, dates were the only differences. So, I still wanted the files to count as the same, even though the dates differed. That led to: compare_dirs_filter_ok($dir1, $dir2, \&filter, $name) (implemented in 0.04) filter is called for all lines of input, it must return the line with any needed changes. If the line should be omitted, it should return "". (implemented in 0.04) #----------------------------------------------------- I want compare_filer_ok($file1, $file2, $filter) to work like compare_dirs_filter but one file at a time (implemented in 0.06) #----------------------------------------------------- The version 0.15 causes a lot of warning being processed by Perl::Critic so that some style changes may improve further maintainability. Test-Files-0.15/t/040755 000452 000311 00000000000 13761421131 013547 5ustar00miejfedi000000 000000 Test-Files-0.15/t/01useok.t100644 000452 000311 00000000112 10306367716 015224 0ustar00miejfedi000000 000000 use strict; use Test::More tests => 1; BEGIN { use_ok('Test::Files'); } Test-Files-0.15/t/02file_ok.t100644 000452 000311 00000005130 10564625527 015517 0ustar00miejfedi000000 000000 use strict; use Test::Builder::Tester tests => 5; use File::Spec; use Test::Files; my $test_file = File::Spec->catfile( 't', '02file_ok.t' ); my $missing_file = File::Spec->catfile( 't', 'missing' ); my $ok_pass_file = File::Spec->catfile( 't', 'ok_pass.dat' ); #----------------------------------------------------------------- # Compare text to a file with same text. #----------------------------------------------------------------- test_out("ok 1 - passing text"); file_ok($ok_pass_file, <<"EOF", "passing text"); This file is for 03ok_pass.t EOF test_test("passing text"); #----------------------------------------------------------------- # Compare text to a missing file. #----------------------------------------------------------------- test_out("not ok 1 - absent file"); my $line = line_num(+3); test_diag(" Failed test ($test_file at line $line)", "$missing_file absent"); file_ok("$missing_file", "This file is really absent", "absent file"); test_test("absent file"); #----------------------------------------------------------------- # Compare text to a file with different text. #----------------------------------------------------------------- test_out("not ok 1 - failing text"); $line = line_num(+9); test_diag(" Failed test ($test_file at line $line)", '+---+----------------------+-----------+', '| |Got |Expected |', '| Ln| | |', '+---+----------------------+-----------+', '| 1|This file |This file |', '* 2|is for 03ok_pass.t\n |is wrong *', '+---+----------------------+-----------+' ); file_ok($ok_pass_file, "This file\nis wrong", "failing text"); test_test("failing text"); #----------------------------------------------------------------- # file_filter_ok with missing file #----------------------------------------------------------------- test_out("not ok 1 - absent filtered file"); $line = line_num(+3); test_diag(" Failed test ($test_file at line $line)", "$missing_file absent"); file_filter_ok( "$missing_file", "This file is really absent", \&stip_num, "absent filtered file", ); test_test("absent filtered file"); #----------------------------------------------------------------- # Compare file to string with filter. #----------------------------------------------------------------- test_out("ok 1 - passing filtered text"); file_filter_ok($ok_pass_file, <<"EOF", \&strip_num, "passing filtered text"); This file is for ok_pass.t EOF test_test("passing filtered text"); sub strip_num { my $line = shift; $line =~ s/\d+//; return $line; } Test-Files-0.15/t/03compare_ok.t100644 000452 000311 00000005433 10307074267 016227 0ustar00miejfedi000000 000000 use strict; use Test::Builder::Tester tests => 5; use File::Spec; use Test::Files; my $test_file = File::Spec->catfile( 't', '03compare_ok.t' ); my $missing_file = File::Spec->catfile( 't', 'missing' ); my $pass_file = File::Spec->catfile( 't', 'ok_pass.dat' ); my $absent_file = File::Spec->catfile( 't', 'absent' ); my $same_file = File::Spec->catfile( 't', 'ok_pass.same.dat' ); my $diff_file = File::Spec->catfile( 't', 'ok_pass.diff.dat' ); #----------------------------------------------------------------- # Compare two files with the same content. #----------------------------------------------------------------- test_out("ok 1 - passing file"); compare_ok($pass_file, $same_file, "passing file"); test_test("passing file"); #----------------------------------------------------------------- # Compare missing file to a file which is exists. #----------------------------------------------------------------- test_out("not ok 1 - first file missing"); my $line = line_num(+3); test_diag(" Failed test ($test_file at line $line)", "$missing_file absent"); compare_ok($missing_file, $pass_file, "first file missing"); test_test("first file missing"); #----------------------------------------------------------------- # Compare file to a file which is missing. #----------------------------------------------------------------- test_out("not ok 1 - second file missing"); $line = line_num(+3); test_diag(" Failed test ($test_file at line $line)", "$missing_file absent"); compare_ok($pass_file, $missing_file, "second file missing"); test_test("second file missing"); #----------------------------------------------------------------- # Compare two files, both of which are missing. #----------------------------------------------------------------- test_out("not ok 1 - both files missing"); $line = line_num(+4); test_diag(" Failed test ($test_file at line $line)", "$absent_file absent", "$missing_file absent"); compare_ok($absent_file, $missing_file, "both files missing"); test_test("both files missing"); #----------------------------------------------------------------- # Compare two files with the different content. #----------------------------------------------------------------- test_out("not ok 1 - failing file"); $line = line_num(+9); test_diag(" Failed test ($test_file at line $line)", '+---+--------------------+-------------------+', '| |Got |Expected |', '| Ln| | |', '+---+--------------------+-------------------+', '| 1|This file |This file |', '* 2|is for 03ok_pass.t |is for many tests *', '+---+--------------------+-------------------+' ); compare_ok($pass_file, $diff_file, "failing file"); test_test("failing file"); Test-Files-0.15/t/04dir_contains_ok.t100644 000452 000311 00000004221 10307074212 017236 0ustar00miejfedi000000 000000 use Test::Builder::Tester tests => 4; use File::Spec; use Test::Files; my $test_file = File::Spec->catfile( 't', '04dir_contains_ok.t' ); my $missing_dir = File::Spec->catdir ( 't', 'missing_dir' ); my $tlib_dir = File::Spec->catdir ( 't', 'lib' ); my $simple_dir = File::Spec->catdir ( 'Test', 'Simple' ); my $catch_file = File::Spec->catfile( 'Test', 'Simple', 'Catch.pm' ); my $simple_file = File::Spec->catfile( 'Test', 'Simple', 'Simple.pm' ); #----------------------------------------------------------------- # Compare file names in a directory to a list of those files. #----------------------------------------------------------------- test_out("ok 1 - passing"); dir_contains_ok( $tlib_dir, ['Test', $simple_dir, $catch_file], "passing" ); test_test("passing"); #----------------------------------------------------------------- # Compare directory to a directory which is absent. #----------------------------------------------------------------- test_out("not ok 1 - missing dir"); my $line = line_num(+3); test_diag(" Failed test ($test_file at line $line)", "$missing_dir absent"); dir_contains_ok($missing_dir, [qw(some files)], "missing dir"); test_test("missing dir"); #----------------------------------------------------------------- # Call dir_contains_ok with bad argument (not an array ref). #----------------------------------------------------------------- test_out("not ok 1 - anon. array expected"); $line = line_num(+3); test_diag(" Failed test ($test_file at line $line)", "dir_contains_ok requires array ref as second arg"); dir_contains_ok('t', "simple_arg", "anon. array expected"); test_test("anon. array expected"); #----------------------------------------------------------------- # Compare file names in a directory to a list which differs. #----------------------------------------------------------------- test_out("not ok 1 - failing"); $line = line_num(+3); test_diag(" Failed test ($test_file at line $line)", "failed to see these: A $simple_file"); dir_contains_ok( $tlib_dir, ['A', 'Test', $simple_dir, $simple_file], "failing" ); test_test("failing"); Test-Files-0.15/t/05dir_only_con.t100644 000452 000311 00000006501 10307074164 016561 0ustar00miejfedi000000 000000 use Test::Builder::Tester tests => 6; use File::Spec; use Test::Files; my $test_file = File::Spec->catfile( 't', '05dir_only_con.t' ); my $missing_dir = File::Spec->catdir ( 't', 'missing_dir' ); my $lib_dir = File::Spec->catdir ( 't', 'lib' ); my $simple_dir = File::Spec->catdir ( 'Test', 'Simple' ); my $catch_file = File::Spec->catfile( 'Test', 'Simple', 'Catch.pm' ); my $simple_file = File::Spec->catfile( 'Test', 'Simple', 'Simple.pm' ); #----------------------------------------------------------------- # Exclusively compare file names in a directory to a list of files. #----------------------------------------------------------------- test_out("ok 1 - passing"); dir_only_contains_ok( $lib_dir, [ 'Test', $simple_dir, $catch_file ], "passing" ); test_test("passing"); #----------------------------------------------------------------- # Compare absent directory to list of files. #----------------------------------------------------------------- test_out("not ok 1 - missing dir"); my $line = line_num(+3); test_diag(" Failed test ($test_file at line $line)", "$missing_dir absent"); dir_only_contains_ok($missing_dir, [qw(some files)], "missing dir"); test_test("missing dir"); #----------------------------------------------------------------- # Call dir_only_contains_ok with bad args (not an array ref). #----------------------------------------------------------------- test_out("not ok 1 - anon. array expected"); $line = line_num(+3); test_diag(" Failed test ($test_file at line $line)", "dir_only_contains_ok requires array ref as second arg"); dir_only_contains_ok('t', "simple_arg", "anon. array expected"); test_test("anon. array expected"); #----------------------------------------------------------------- # Exclusively compare file names in a direcory to a list which # is missing one of the files. #----------------------------------------------------------------- test_out("not ok 1 - failing because of missing file"); $line = line_num(+3); test_diag(" Failed test ($test_file at line $line)", "failed to see these: A"); dir_only_contains_ok( $lib_dir, [ 'A', 'Test', $simple_dir, $catch_file ], "failing because of missing file" ); test_test("failing because of missing file"); #----------------------------------------------------------------- # Exclusively compare file names in a directory to a list which # has does not have one of those names. #----------------------------------------------------------------- test_out("not ok 1 - failing because of extra file"); $line = line_num(+3); test_diag(" Failed test ($test_file at line $line)", "unexpectedly saw: $catch_file" ); dir_only_contains_ok( $lib_dir, [ 'Test', $simple_dir ], "failing because of extra file" ); test_test("failing because of extra file"); #----------------------------------------------------------------- # Exclusively compare file names in a directory to a list which # is different. #----------------------------------------------------------------- test_out("not ok 1 - failing both"); $line = line_num(+4); test_diag(" Failed test ($test_file at line $line)", "failed to see these: A $simple_file", "unexpectedly saw: $catch_file" ); dir_only_contains_ok( $lib_dir, [ 'A', 'Test', $simple_dir, $simple_file ], "failing both" ); test_test("failing both"); Test-Files-0.15/t/06compare_dirs.t100644 000452 000311 00000010605 10401172760 016547 0ustar00miejfedi000000 000000 use Test::Builder::Tester tests => 5; use Test::More; use File::Spec; use Test::Files; my $test_file = File::Spec->catfile( 't', '06compare_dirs.t' ); my $missing_dir = File::Spec->catdir ( 't', 'missing_dir' ); my $lib_dir = File::Spec->catdir ( 't', 'lib' ); my $lib_fail_dir = File::Spec->catdir ( 't', 'lib_fail' ); my $lib_pass_dir = File::Spec->catdir ( 't', 'lib_pass' ); my $time_dir = File::Spec->catdir ( 't', 'time' ); my $time3_dir = File::Spec->catdir ( 't', 'time3' ); my $catch = File::Spec->catfile( 't', 'lib', 'Test', 'Simple', 'Catch.pm' ); my $catch_fail = File::Spec->catfile( 't', 'lib_fail', 'Test', 'Simple', 'Catch.pm' ); my $t1 = File::Spec->catfile( 't', 'time', 't1' ); my $t2 = File::Spec->catfile( 't', 'time', 't2' ); my $t3 = File::Spec->catfile( 't', 'time', 't3' ); #----------------------------------------------------------------- # Compare file contents in directories which are the same. #----------------------------------------------------------------- test_out("ok 1 - passing"); compare_dirs_ok($lib_dir, $lib_pass_dir, "passing"); test_test("passing"); #----------------------------------------------------------------- # Compare file contents in a missing directory to an extant # directory. #----------------------------------------------------------------- test_out("not ok 1 - missing first dir"); my $line = line_num(+3); test_diag(" Failed test ($test_file at line $line)", "$missing_dir is not a valid directory"); compare_dirs_ok($missing_dir, $lib_dir, "missing first dir"); test_test("missing first dir"); #----------------------------------------------------------------- # Compare file contents in a directory to a missing directory. #----------------------------------------------------------------- test_out("not ok 1 - missing second dir"); $line = line_num(+3); test_diag(" Failed test ($test_file at line $line)", "$missing_dir is not a valid directory"); compare_dirs_ok($lib_dir, $missing_dir, "missing second dir"); test_test("missing second dir"); #----------------------------------------------------------------- # Compare file contents in a directory to a file contents in # another directory where one pair of files differ. #----------------------------------------------------------------- SKIP: { skip "test only for unix, i.e. not for $^O", 1 unless ( $^O =~ /nix|nux|solaris/ ); test_out("not ok 1 - failing due to text diff"); $line = line_num(+17); test_diag( " Failed test ($test_file at line $line)", '+---+-----------------------------------+---+---------------------------------+', "| |$catch | |$catch_fail |", '| Ln| | Ln| |', '+---+-----------------------------------+---+---------------------------------+', '| 12|$t->failure_output($err_fh); | 12|$t->failure_output($err_fh); |', '| 13|$t->todo_output($err_fh); | 13|$t->todo_output($err_fh); |', '| 14| | 14| |', '* 15|sub caught { return($out, $err) } * 15|sub caught { *', '| | * 16| return($out, $err) *', '| | * 17|} *', '| 16| | 18| |', '| 17|sub PRINT { | 19|sub PRINT { |', '| 18| my $self = shift; | 20| my $self = shift; |', '+---+-----------------------------------+---+---------------------------------+'); compare_dirs_ok($lib_dir, $lib_fail_dir, "failing due to text diff"); test_test("failing due to text diff"); } #----------------------------------------------------------------- # Compare file contents in directories with different files. #----------------------------------------------------------------- test_out("not ok 1 - failing due to structure diff"); $line = line_num(+5); test_diag(" Failed test ($test_file at line $line)", "$t1 absent", "$t2 absent", "$t3 absent"); compare_dirs_ok($time3_dir, $time_dir, "failing due to structure diff"); test_test("failing due to structure diff"); Test-Files-0.15/t/07comp_dir_f.t100644 000452 000311 00000010131 10401172770 016175 0ustar00miejfedi000000 000000 use strict; use Test::Builder::Tester tests => 5; use Test::More; use File::Spec; use Test::Files; my $test_file = File::Spec->catfile( 't', '07comp_dir_f.t' ); my $missing_dir = File::Spec->catdir ( 't', 'missing_dir' ); my $time_dir = File::Spec->catdir ( 't', 'time' ); my $time2_dir = File::Spec->catdir ( 't', 'time2' ); my $lib_fail_dir = File::Spec->catdir ( 't', 'lib_fail' ); my $stamp1 = File::Spec->catfile( 't', 'time', 'time_stamp.dat' ); my $stamp2 = File::Spec->catfile( 't', 'time2', 'time_stamp.dat' ); #----------------------------------------------------------------- # Compare (with a filter) file contents in directories which # are the same. #----------------------------------------------------------------- test_out("ok 1 - passing"); compare_dirs_filter_ok($time_dir, $time2_dir, \&four_to_one, "passing"); test_test("passing"); sub four_to_one { my $line = shift; $line =~ s/4/1/; return $line; } #----------------------------------------------------------------- # Compare (with a filter) file contents in directories when # first directory is missing. #----------------------------------------------------------------- test_out("not ok 1 - missing first dir"); my $line = line_num(+3); test_diag(" Failed test ($test_file at line $line)", "$missing_dir is not a valid directory"); compare_dirs_filter_ok($missing_dir, $time_dir, sub{}, "missing first dir"); test_test("missing first dir"); #----------------------------------------------------------------- # Compare (with a filter) file contents in directories when # second directory is missing. #----------------------------------------------------------------- test_out("not ok 1 - missing second dir"); $line = line_num(+3); test_diag(" Failed test ($test_file at line $line)", "$missing_dir is not a valid directory"); compare_dirs_filter_ok($time_dir, $missing_dir, sub{}, "missing second dir"); test_test("missing second dir"); #----------------------------------------------------------------- # Compare (with a filter) file contents in directories when # filter is not supplied (or is not a code ref). #----------------------------------------------------------------- test_out("not ok 1 - missing coderef"); $line = line_num(+3); test_diag(" Failed test ($test_file at line $line)", "Third argument to compare_dirs_filter_ok must be a code reference (or undef)"); compare_dirs_filter_ok($time_dir, $lib_fail_dir, "missing coderef"); test_test("missing coderef"); #----------------------------------------------------------------- # Compare (with a filter) file contents in directories when # filter is does nothing and files differ slightly. #----------------------------------------------------------------- SKIP: { skip "test only for unix, i.e. not for $^O", 1 unless ( $^O =~ /nix|nux|solaris/ ); test_out("not ok 1 - failing noop filter"); $line = line_num(+10); test_diag(" Failed test ($test_file at line $line)", '+---+----------------------------------------------------------+----------------------------------------------------------+', "| |$stamp1 |$stamp2 |", '| Ln| | |', '+---+----------------------------------------------------------+----------------------------------------------------------+', '| 1|This file |This file |', '| 2|is for 03ok_pass.t |is for 03ok_pass.t |', '* 3|Touched on: Wed Oct 15 12:38:12 CDT 2003, this afternoon |Touched on: Wed Oct 15 12:38:42 CDT 2003, this afternoon *', '+---+----------------------------------------------------------+----------------------------------------------------------+'); compare_dirs_filter_ok($time_dir, $time2_dir, \&noop, "failing noop filter"); test_test("failing noop filter"); } sub noop { return $_[0]; } Test-Files-0.15/t/08comp_filt.t100644 000452 000311 00000006022 10307102643 016052 0ustar00miejfedi000000 000000 use strict; use Test::Builder::Tester tests => 5; use File::Spec; use Test::Files; my $test_file = File::Spec->catfile( 't', '08comp_filt.t' ); my $ok_pass_dat = File::Spec->catfile( 't', 'ok_pass.dat' ); my $ok_diff_dat = File::Spec->catfile( 't', 'ok_pass.diff.dat' ); my $missing_dir = File::Spec->catdir ( 't', 'missing_dir' ); my $absent_dir = File::Spec->catdir ( 't', 'absent_dir' ); #----------------------------------------------------------------- # Compare (with a filter) file contents which # are the same except for one small difference. #----------------------------------------------------------------- test_out("ok 1 - passing similar"); compare_filter_ok($ok_pass_dat, $ok_diff_dat, \&stripper, "passing similar"); test_test("failing file"); sub stripper { my $line = shift; $line =~ s/is for .*//; return $line; } sub noop { return $_[0]; } #----------------------------------------------------------------- # Compare (with a filter) file contents when first file is missing. #----------------------------------------------------------------- test_out("not ok 1 - first file missing"); my $line = line_num(+3); test_diag(" Failed test ($test_file at line $line)", "$missing_dir absent"); compare_filter_ok($missing_dir, $ok_pass_dat, \&noop, "first file missing"); test_test("first file missing"); #----------------------------------------------------------------- # Compare (with a filter) file contents when second file is missing. #----------------------------------------------------------------- test_out("not ok 1 - second file missing"); $line = line_num(+3); test_diag(" Failed test ($test_file at line $line)", "$missing_dir absent"); compare_filter_ok($ok_pass_dat, $missing_dir, \&noop, "second file missing"); test_test("second file missing"); #----------------------------------------------------------------- # Compare (with a filter) file contents when both files are missing. #----------------------------------------------------------------- test_out("not ok 1 - both files missing"); $line = line_num(+4); test_diag(" Failed test ($test_file at line $line)", "$absent_dir absent", "$missing_dir absent"); compare_filter_ok($absent_dir, $missing_dir, \&noop, "both files missing"); test_test("both files missing"); #----------------------------------------------------------------- # Compare (with a filter) file contents when filter is missing. #----------------------------------------------------------------- test_out("not ok 1 - failing no filter"); $line = line_num(+9); test_diag(" Failed test ($test_file at line $line)", '+---+--------------------+-------------------+', '| |Got |Expected |', '| Ln| | |', '+---+--------------------+-------------------+', '| 1|This file |This file |', '* 2|is for 03ok_pass.t |is for many tests *', '+---+--------------------+-------------------+' ); compare_filter_ok($ok_pass_dat, $ok_diff_dat, \&noop, "failing no filter"); test_test("passing file"); Test-Files-0.15/t/lib/040755 000452 000311 00000000000 13761421131 014315 5ustar00miejfedi000000 000000 Test-Files-0.15/t/lib/Test/040755 000452 000311 00000000000 13761421131 015234 5ustar00miejfedi000000 000000 Test-Files-0.15/t/lib/Test/Simple/040755 000452 000311 00000000000 13761421131 016465 5ustar00miejfedi000000 000000 Test-Files-0.15/t/lib/Test/Simple/Catch.pm100644 000452 000311 00000001061 10306367716 020052 0ustar00miejfedi000000 000000 # For testing Test::Simple; package Test::Simple::Catch; use Symbol; my($out_fh, $err_fh) = (gensym, gensym); my $out = tie *$out_fh, __PACKAGE__; my $err = tie *$err_fh, __PACKAGE__; use Test::Builder; my $t = Test::Builder->new; $t->output($out_fh); $t->failure_output($err_fh); $t->todo_output($err_fh); sub caught { return($out, $err) } sub PRINT { my $self = shift; $$self .= join '', @_; } sub TIEHANDLE { my $class = shift; my $self = ''; return bless \$self, $class; } sub READ {} sub READLINE {} sub GETC {} sub FILENO {} 1; Test-Files-0.15/t/lib_fail/040755 000452 000311 00000000000 13761421131 015310 5ustar00miejfedi000000 000000 Test-Files-0.15/t/lib_fail/Test/040755 000452 000311 00000000000 13761421131 016227 5ustar00miejfedi000000 000000 Test-Files-0.15/t/lib_fail/Test/Simple/040755 000452 000311 00000000000 13761421131 017460 5ustar00miejfedi000000 000000 Test-Files-0.15/t/lib_fail/Test/Simple/Catch.pm100644 000452 000311 00000001065 10306367716 021051 0ustar00miejfedi000000 000000 # For testing Test::Simple; package Test::Simple::Catch; use Symbol; my($out_fh, $err_fh) = (gensym, gensym); my $out = tie *$out_fh, __PACKAGE__; my $err = tie *$err_fh, __PACKAGE__; use Test::Builder; my $t = Test::Builder->new; $t->output($out_fh); $t->failure_output($err_fh); $t->todo_output($err_fh); sub caught { return($out, $err) } sub PRINT { my $self = shift; $$self .= join '', @_; } sub TIEHANDLE { my $class = shift; my $self = ''; return bless \$self, $class; } sub READ {} sub READLINE {} sub GETC {} sub FILENO {} 1; Test-Files-0.15/t/lib_pass/040755 000452 000311 00000000000 13761421131 015343 5ustar00miejfedi000000 000000 Test-Files-0.15/t/lib_pass/Test/040755 000452 000311 00000000000 13761421131 016262 5ustar00miejfedi000000 000000 Test-Files-0.15/t/lib_pass/Test/Simple/040755 000452 000311 00000000000 13761421131 017513 5ustar00miejfedi000000 000000 Test-Files-0.15/t/lib_pass/Test/Simple/Catch.pm100644 000452 000311 00000001061 10306367716 021100 0ustar00miejfedi000000 000000 # For testing Test::Simple; package Test::Simple::Catch; use Symbol; my($out_fh, $err_fh) = (gensym, gensym); my $out = tie *$out_fh, __PACKAGE__; my $err = tie *$err_fh, __PACKAGE__; use Test::Builder; my $t = Test::Builder->new; $t->output($out_fh); $t->failure_output($err_fh); $t->todo_output($err_fh); sub caught { return($out, $err) } sub PRINT { my $self = shift; $$self .= join '', @_; } sub TIEHANDLE { my $class = shift; my $self = ''; return bless \$self, $class; } sub READ {} sub READLINE {} sub GETC {} sub FILENO {} 1; Test-Files-0.15/t/ok_pass.dat100644 000452 000311 00000000035 10306367717 015706 0ustar00miejfedi000000 000000 This file is for 03ok_pass.t Test-Files-0.15/t/ok_pass.diff.dat100644 000452 000311 00000000034 10306367717 016614 0ustar00miejfedi000000 000000 This file is for many tests Test-Files-0.15/t/ok_pass.same.dat100644 000452 000311 00000000035 10306367717 016632 0ustar00miejfedi000000 000000 This file is for 03ok_pass.t Test-Files-0.15/t/time/040755 000452 000311 00000000000 13761421131 014505 5ustar00miejfedi000000 000000 Test-Files-0.15/t/time/time_stamp.dat100644 000452 000311 00000000126 10306367716 017347 0ustar00miejfedi000000 000000 This file is for 03ok_pass.t Touched on: Wed Oct 15 12:38:12 CDT 2003, this afternoon Test-Files-0.15/t/time2/040755 000452 000311 00000000000 13761421131 014567 5ustar00miejfedi000000 000000 Test-Files-0.15/t/time2/time_stamp.dat100644 000452 000311 00000000126 10306367717 017432 0ustar00miejfedi000000 000000 This file is for 03ok_pass.t Touched on: Wed Oct 15 12:38:42 CDT 2003, this afternoon Test-Files-0.15/t/time3/040755 000452 000311 00000000000 13761421131 014570 5ustar00miejfedi000000 000000 Test-Files-0.15/t/time3/t1100644 000452 000311 00000000126 10306367716 015045 0ustar00miejfedi000000 000000 This file is for 03ok_pass.t Touched on: Wed Oct 15 12:38:12 CDT 2003, this afternoon Test-Files-0.15/t/time3/t2100644 000452 000311 00000000126 10306367716 015046 0ustar00miejfedi000000 000000 This file is for 03ok_pass.t Touched on: Wed Oct 15 12:38:12 CDT 2003, this afternoon Test-Files-0.15/t/time3/t3100644 000452 000311 00000000126 10306367716 015047 0ustar00miejfedi000000 000000 This file is for 03ok_pass.t Touched on: Wed Oct 15 12:38:12 CDT 2003, this afternoon Test-Files-0.15/t/time3/time_stamp.dat100644 000452 000311 00000000126 10306367716 017432 0ustar00miejfedi000000 000000 This file is for 03ok_pass.t Touched on: Wed Oct 15 12:38:12 CDT 2003, this afternoon