Test-Files-0.14/0000755000076400007640000000000010602503115012070 5ustar philphilTest-Files-0.14/Files.pm0000644000076400007640000003305610602503044013500 0ustar philphilpackage Test::Files; use Test::Builder; use Text::Diff; use File::Find; use File::Spec; 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.14'; 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 (index(ref $list, 'ARRAY') < 0) { return(0, "$function requires array ref as second arg"); return; } 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) =~ /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 Test::Builder Test::More Text::Diff Algorithm::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 =head1 COPYRIGHT AND LICENSE Copyright 2003-2007 by Phil Crow 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.14/Changes0000644000076400007640000001113210602503112013356 0ustar philphilRevision history for Perl extension Test::Files. 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.14/Makefile.PL0000644000076400007640000000135510316112601014044 0ustar philphiluse 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.14/TODO0000644000076400007640000000440010322034265012562 0ustar philphilA 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) Test-Files-0.14/MANIFEST0000644000076400007640000000077510307102660013234 0ustar philphilChanges Files.pm MANIFEST Makefile.PL README TODO 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/time/time_stamp.dat t/time2/time_stamp.dat t/time3/t1 t/time3/t2 t/time3/t3 t/time3/time_stamp.dat t/ok_pass.dat t/ok_pass.diff.dat t/ok_pass.same.dat META.yml Module meta-data (added by MakeMaker) Test-Files-0.14/META.yml0000664000076400007640000000074010602503115013344 0ustar philphil# http://module-build.sourceforge.net/META-spec.html #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# name: Test-Files version: 0.14 version_from: Files.pm installdirs: site requires: Algorithm::Diff: 0 Test::Builder: 0 Test::Builder::Tester: 0 Test::More: 0 Text::Diff: 0 distribution_type: module generated_by: ExtUtils::MakeMaker version 6.30 Test-Files-0.14/README0000644000076400007640000000205610306367716012773 0ustar philphilTest/Files version 0.01 ======================= The README is used to introduce the module and provide instructions on how to install the module, any machine dependencies it may have (for example C compilers and installed libraries) and any other information that should be provided before the module is installed. A README file is required for CPAN modules since CPAN extracts the README file from a module distribution so that people browsing the archive can use it get an idea of the modules uses. It is usually a good idea to provide version information here so that people can decide whether fixes for the module are worth downloading. 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: blah blah blah COPYRIGHT AND LICENCE Put the correct copyright and licence information here. Copyright (C) 2003 Phil Crow This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Test-Files-0.14/t/0000755000076400007640000000000010602503115012333 5ustar philphilTest-Files-0.14/t/03compare_ok.t0000644000076400007640000000543310307074267015024 0ustar philphiluse 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.14/t/lib/0000755000076400007640000000000010602503115013101 5ustar philphilTest-Files-0.14/t/lib/Test/0000755000076400007640000000000010602503115014020 5ustar philphilTest-Files-0.14/t/lib/Test/Simple/0000755000076400007640000000000010602503115015251 5ustar philphilTest-Files-0.14/t/lib/Test/Simple/Catch.pm0000644000076400007640000000106110306367716016647 0ustar philphil# 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.14/t/ok_pass.dat0000644000076400007640000000003510306367717014503 0ustar philphilThis file is for 03ok_pass.t Test-Files-0.14/t/ok_pass.same.dat0000644000076400007640000000003510306367717015427 0ustar philphilThis file is for 03ok_pass.t Test-Files-0.14/t/06compare_dirs.t0000644000076400007640000001060510401172760015344 0ustar philphiluse 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.14/t/time3/0000755000076400007640000000000010602503115013354 5ustar philphilTest-Files-0.14/t/time3/t30000644000076400007640000000012610306367716013644 0ustar philphilThis file is for 03ok_pass.t Touched on: Wed Oct 15 12:38:12 CDT 2003, this afternoon Test-Files-0.14/t/time3/t10000644000076400007640000000012610306367716013642 0ustar philphilThis file is for 03ok_pass.t Touched on: Wed Oct 15 12:38:12 CDT 2003, this afternoon Test-Files-0.14/t/time3/time_stamp.dat0000644000076400007640000000012610306367716016227 0ustar philphilThis file is for 03ok_pass.t Touched on: Wed Oct 15 12:38:12 CDT 2003, this afternoon Test-Files-0.14/t/time3/t20000644000076400007640000000012610306367716013643 0ustar philphilThis file is for 03ok_pass.t Touched on: Wed Oct 15 12:38:12 CDT 2003, this afternoon Test-Files-0.14/t/01useok.t0000644000076400007640000000011210306367716014021 0ustar philphiluse strict; use Test::More tests => 1; BEGIN { use_ok('Test::Files'); } Test-Files-0.14/t/08comp_filt.t0000644000076400007640000000602210307102643014647 0ustar philphiluse 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.14/t/02file_ok.t0000644000076400007640000000513010564625527014314 0ustar philphiluse 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.14/t/07comp_dir_f.t0000644000076400007640000001013110401172770014772 0ustar philphiluse 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.14/t/lib_pass/0000755000076400007640000000000010602503115014127 5ustar philphilTest-Files-0.14/t/lib_pass/Test/0000755000076400007640000000000010602503115015046 5ustar philphilTest-Files-0.14/t/lib_pass/Test/Simple/0000755000076400007640000000000010602503115016277 5ustar philphilTest-Files-0.14/t/lib_pass/Test/Simple/Catch.pm0000644000076400007640000000106110306367716017675 0ustar philphil# 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.14/t/time2/0000755000076400007640000000000010602503115013353 5ustar philphilTest-Files-0.14/t/time2/time_stamp.dat0000644000076400007640000000012610306367717016227 0ustar philphilThis file is for 03ok_pass.t Touched on: Wed Oct 15 12:38:42 CDT 2003, this afternoon Test-Files-0.14/t/04dir_contains_ok.t0000644000076400007640000000422110307074212016033 0ustar philphiluse 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.14/t/time/0000755000076400007640000000000010602503115013271 5ustar philphilTest-Files-0.14/t/time/time_stamp.dat0000644000076400007640000000012610306367716016144 0ustar philphilThis file is for 03ok_pass.t Touched on: Wed Oct 15 12:38:12 CDT 2003, this afternoon Test-Files-0.14/t/lib_fail/0000755000076400007640000000000010602503115014074 5ustar philphilTest-Files-0.14/t/lib_fail/Test/0000755000076400007640000000000010602503115015013 5ustar philphilTest-Files-0.14/t/lib_fail/Test/Simple/0000755000076400007640000000000010602503115016244 5ustar philphilTest-Files-0.14/t/lib_fail/Test/Simple/Catch.pm0000644000076400007640000000106510306367716017646 0ustar philphil# 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.14/t/ok_pass.diff.dat0000644000076400007640000000003410306367717015411 0ustar philphilThis file is for many tests Test-Files-0.14/t/05dir_only_con.t0000644000076400007640000000650110307074164015356 0ustar philphiluse 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");