Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Code to address issue #1 #2

Merged
merged 10 commits into from

1 participant

@barefootcoder
Collaborator

Added dir_exists_ok() and dir_contains_ok(), as well as made a number of minor documentation fixes. All separate commits so they can be merged separately if desired.

barefootcoder added some commits
@barefootcoder barefootcoder code to address Github issue #1
added function dir_exists_ok()
added tests for same
added POD for same
updated MANIFEST/test_manifest
e85efbb
@barefootcoder barefootcoder remove debugging in test (wasn't working anyway) 1185f59
@barefootcoder barefootcoder added dir_contains_ok()
also mentioned in GitHub #1
also added tests (natch)
2f88ed1
@barefootcoder barefootcoder minor doco changes
a few grammatical fixes
made some things consistent
pulled the "optional NAME parameter" stuff to outside the individual function descriptions
noted my contributions similar to other contributors are credited
08a4269
barefootcoder added some commits
@barefootcoder barefootcoder fixed END blocks for test files
I just realized why test_files/ wasn't getting cleaned up whenever I had a syntax error:
the "cd .." wasn't in the END block
fixed that up and made the formatting consistent across test files
46b9a4c
@barefootcoder barefootcoder first cut at file_contains_like
this addresses GitHub issue #3
code and tests; added to test_manifest and MANIFEST
added POD
still need to allow multiple tests on the contents
also should add file_contains_unlike
cba254e
@barefootcoder barefootcoder this tab/space inconsistency was bugging me ... cb7052c
@barefootcoder barefootcoder refactored to make it easy to add file_contains_unlike 158baef
@barefootcoder barefootcoder implemented file_contains_unlike (for GitHub #3) a3f00b4
@barefootcoder barefootcoder file_contains_(un)?like now accept multiple patterns
for GitHub #3
if PATTERN is an arrayref, will test multiple patterns against the file contents
saves having to read the file contents over and over
updated tests and POD, natch
5f9b7c9
@barefootcoder barefootcoder merged commit 7255a11 into briandfoy:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 30, 2011
  1. @barefootcoder

    code to address Github issue #1

    barefootcoder authored
    added function dir_exists_ok()
    added tests for same
    added POD for same
    updated MANIFEST/test_manifest
  2. @barefootcoder
  3. @barefootcoder

    added dir_contains_ok()

    barefootcoder authored
    also mentioned in GitHub #1
    also added tests (natch)
  4. @barefootcoder

    minor doco changes

    barefootcoder authored
    a few grammatical fixes
    made some things consistent
    pulled the "optional NAME parameter" stuff to outside the individual function descriptions
    noted my contributions similar to other contributors are credited
Commits on Jan 2, 2012
  1. @barefootcoder

    fixed END blocks for test files

    barefootcoder authored
    I just realized why test_files/ wasn't getting cleaned up whenever I had a syntax error:
    the "cd .." wasn't in the END block
    fixed that up and made the formatting consistent across test files
  2. @barefootcoder

    first cut at file_contains_like

    barefootcoder authored
    this addresses GitHub issue #3
    code and tests; added to test_manifest and MANIFEST
    added POD
    still need to allow multiple tests on the contents
    also should add file_contains_unlike
Commits on Jan 3, 2012
  1. @barefootcoder
  2. @barefootcoder
  3. @barefootcoder
  4. @barefootcoder

    file_contains_(un)?like now accept multiple patterns

    barefootcoder authored
    for GitHub #3
    if PATTERN is an arrayref, will test multiple patterns against the file contents
    saves having to read the file contents over and over
    updated tests and POD, natch
This page is out of date. Refresh to see the latest.
View
2  MANIFEST
@@ -6,6 +6,7 @@ Makefile.PL
MANIFEST This list of files
README
t/dm_skeleton.t
+t/file_contains.t
t/file_sizes.t
t/line_counters.t
t/link_counts.t
@@ -19,6 +20,7 @@ t/pod_coverage.t
t/prereq.t
t/rt/30346.t
t/setup_common
+t/test_dirs.t
t/test_files.t
t/test_manifest
t/win32.t
View
268 lib/File.pm
@@ -16,10 +16,12 @@ use Test::Builder;
file_is_symlink_ok
symlink_target_exists_ok symlink_target_is
symlink_target_dangles_ok
+ dir_exists_ok dir_contains_ok
link_count_is_ok link_count_gt_ok link_count_lt_ok
owner_is owner_isnt
group_is group_isnt
- file_line_count_is file_line_count_isnt file_line_count_between
+ file_line_count_is file_line_count_isnt file_line_count_between
+ file_contains_like file_contains_unlike
);
$VERSION = '1.28';
@@ -53,6 +55,9 @@ tests automatically skip if they think they won't work on the
platform. If you have a way to make these functions work on Windows,
for instance, please send me a patch. :)
+The optional NAME parameter for every function allows you to specify a name for the test. If not
+supplied, a reasonable default will be generated.
+
=head2 Functions
=cut
@@ -322,9 +327,9 @@ sub file_min_size_ok
=item file_line_count_is( FILENAME, COUNT [, NAME ] )
Ok if the file exists and has COUNT lines (exactly), not ok if the
-file does not exist or exists with a line count than COUNT.
+file does not exist or exists with a line count other than COUNT.
-This function using the current value of C<$/> as the line ending and
+This function uses the current value of C<$/> as the line ending and
counts the lines by reading them and counting how many it read.
=cut
@@ -396,7 +401,7 @@ Ok if the file exists and doesn't have exactly COUNT lines, not ok if the
file does not exist or exists with a line count of COUNT. Read that
carefully: the file must exist for this test to pass!
-This function using the current value of C<$/> as the line ending and
+This function uses the current value of C<$/> as the line ending and
counts the lines by reading them and counting how many it read.
=cut
@@ -447,7 +452,7 @@ sub file_line_count_isnt
Ok if the file exists and has a line count between MIN and MAX, inclusively.
-This function using the current value of C<$/> as the line ending and
+This function uses the current value of C<$/> as the line ending and
counts the lines by reading them and counting how many it read.
=cut
@@ -500,7 +505,133 @@ sub file_line_count_between
}
}
-
+
+=item file_contains_like ( FILENAME, PATTERN [, NAME ] )
+
+Ok if the file exists and its contents (as one big string) match
+PATTERN, not ok if the file does not exist, is not readable, or exists
+but doesn't match PATTERN.
+
+Since the file contents are read into memory, you should not use this
+for large files. Besides memory consumption, test diagnostics for
+failing tests might be difficult to decipher. However, for short
+files this works very well.
+
+Because the entire contents are treated as one large string, you can
+make a pattern that tests multiple lines. Don't forget that you may
+need to use the /s modifier for such patterns:
+
+ # make sure file has one or more paragraphs with CSS class X
+ file_contains_like($html_file, qr{<p class="X">.*?</p>}s);
+
+Contrariwise, if you need to match at the beginning or end of a line
+inside the file, use the /m modifier:
+
+ # make sure file has a setting for foo
+ file_contains_like($config_file, qr/^ foo \s* = \s* \w+ $/mx);
+
+If you want to test your file contents against multiple patterns, but
+don't want to have the file read in repeatedly, you can pass an
+arrayref of patterns instead of a single pattern, like so:
+
+ # make sure our template has rendered correctly
+ file_contains_like($template_out,
+ [
+ qr/^ $title_line $/mx,
+ map { qr/^ $_ $/mx } @chapter_headings,
+ qr/^ $footer_line $/mx,
+ ]);
+
+Please note that if you do this, and your file does not exist or is
+not readable, you'll only get one test failure instead of a failure
+for each pattern. This could cause your test plan to be off, although
+you may not care at that point because your test failed anyway. If
+you do care, either skip the test plan altogether by employing
+L<Test::More>'s C<done_testing()> function, or use
+L</file_readable_ok> in conjunction with a C<SKIP> block.
+
+Contributed by Buddy Burden C<< <barefoot@cpan.org> >>.
+
+=item file_contains_unlike ( FILENAME, PATTERN [, NAME ] )
+
+Ok if the file exists and its contents (as one big string) do B<not>
+match PATTERN, not ok if the file does not exist, is not readable, or
+exists but matches PATTERN.
+
+All notes and caveats for L</file_contains_like> apply to this
+function as well.
+
+Contributed by Buddy Burden C<< <barefoot@cpan.org> >>.
+
+=cut
+
+sub file_contains_like
+ {
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+ _file_contains(like => "contains", @_);
+ }
+
+sub file_contains_unlike
+ {
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+ _file_contains(unlike => "doesn't contain", @_);
+ }
+
+sub _file_contains
+ {
+ my $method = shift;
+ my $verb = shift;
+ my $filename = _normalize( shift );
+ my $patterns = shift;
+ my $name = shift;
+
+ my (@patterns, %patterns);
+ if (ref $patterns eq 'ARRAY')
+ {
+ @patterns = @$patterns;
+ %patterns = map { $_ => $name || "$filename $verb $_" } @patterns;
+ }
+ else
+ {
+ @patterns = ($patterns);
+ %patterns = ( $patterns => $name || "$filename $verb $patterns" );
+ }
+
+ # for purpose of checking the file's existence, just use the first
+ # test name as the name
+ $name = $patterns{$patterns[0]};
+
+ unless( -e $filename )
+ {
+ $Test->diag( "File [$filename] does not exist!" );
+ return $Test->ok(0, $name);
+ }
+
+ unless( -r $filename )
+ {
+ $Test->diag( "File [$filename] is not readable!" );
+ return $Test->ok(0, $name);
+ }
+
+ # do the slurp
+ my $file_contents;
+ {
+ unless (open(FH, $filename))
+ {
+ $Test->diag( "Could not open [$filename]: \$! is [$!]!" );
+ return $Test->ok( 0, $name );
+ }
+ local $/ = undef;
+ $file_contents = <FH>;
+ close FH;
+ }
+
+ foreach my $p (@patterns)
+ {
+ $Test->$method($file_contents, $p, $patterns{$p});
+ }
+ }
+
=item file_readable_ok( FILENAME [, NAME ] )
Ok if the file exists and is readable, not ok
@@ -745,14 +876,12 @@ sub file_mode_isnt
}
}
-=item file_is_symlink_ok( FILENAME [, NAME] )
+=item file_is_symlink_ok( FILENAME [, NAME ] )
-Ok is FILENAME is a symlink, even if it points to a non-existent
+Ok if FILENAME is a symlink, even if it points to a non-existent
file. This test automatically skips if the operating system does
not support symlinks. If the file does not exist, the test fails.
-The optional NAME parameter is the name of the test.
-
=cut
sub file_is_symlink_ok
@@ -778,15 +907,13 @@ sub file_is_symlink_ok
}
}
-=item symlink_target_exists_ok( SYMLINK [, TARGET] [, NAME] )
+=item symlink_target_exists_ok( SYMLINK [, TARGET] [, NAME ] )
-Ok is FILENAME is a symlink and it points to a existing file. With the
+Ok if FILENAME is a symlink and it points to a existing file. With the
optional TARGET argument, the test fails if SYMLINK's target is not
TARGET. This test automatically skips if the operating system does not
support symlinks. If the file does not exist, the test fails.
-The optional NAME parameter is the name of the test.
-
=cut
sub symlink_target_exists_ok
@@ -829,14 +956,12 @@ sub symlink_target_exists_ok
$Test->ok( 1, $name );
}
-=item symlink_target_dangles_ok( SYMLINK [, NAME] )
+=item symlink_target_dangles_ok( SYMLINK [, NAME ] )
Ok if FILENAME is a symlink and if it doesn't point to a existing
file. This test automatically skips if the operating system does not
support symlinks. If the file does not exist, the test fails.
-The optional NAME parameter is the name of the test.
-
=cut
sub symlink_target_dangles_ok
@@ -868,14 +993,12 @@ sub symlink_target_dangles_ok
$Test->ok( 1, $name );
}
-=item symlink_target_is( SYMLINK, TARGET [, NAME] )
+=item symlink_target_is( SYMLINK, TARGET [, NAME ] )
Ok if FILENAME is a symlink and if points to TARGET. This test
automatically skips if the operating system does not support symlinks.
If the file does not exist, the test fails.
-The optional NAME parameter is the name of the test.
-
=cut
sub symlink_target_is
@@ -919,14 +1042,12 @@ sub symlink_target_is
}
}
-=item symlink_target_is_absolute_ok( SYMLINK [, NAME] )
+=item symlink_target_is_absolute_ok( SYMLINK [, NAME ] )
Ok if FILENAME is a symlink and if its target is an absolute path.
This test automatically skips if the operating system does not support
symlinks. If the file does not exist, the test fails.
-The optional NAME parameter is the name of the test.
-
=cut
=pod
@@ -965,16 +1086,79 @@ if (defined( $link_abs ) && defined( $to_abs ) && $link_abs eq $to_abs) {
}
}
+=item dir_exists_ok( DIRECTORYNAME [, NAME ] )
+
+Ok if the file exists and is a directory, not ok if the file doesn't exist, or exists but isn't a
+directory.
+
+Contributed by Buddy Burden C<< <barefoot@cpan.org> >>.
+
+=cut
+
+sub dir_exists_ok
+ {
+ my $filename = _normalize( shift );
+ my $name = shift || "$filename is a directory";
+
+ unless( -e $filename )
+ {
+ $Test->diag( "File [$filename] does not exist!" );
+ return $Test->ok(0, $name);
+ }
+
+ my $ok = -d $filename;
+
+ if( $ok )
+ {
+ $Test->ok(1, $name);
+ }
+ else
+ {
+ $Test->diag( "File [$filename] exists but is not a directory!" );
+ $Test->ok(0, $name);
+ }
+ }
+
+=item dir_contains_ok( DIRECTORYNAME, FILENAME [, NAME ] )
+
+Ok if the directory exists and contains the file, not ok if the directory doesn't exist, or exists
+but doesn't contain the file.
+
+Contributed by Buddy Burden C<< <barefoot@cpan.org> >>.
+
=cut
-=item link_count_is_ok( FILE, LINK_COUNT [, NAME] )
+sub dir_contains_ok
+ {
+ my $dirname = _normalize( shift );
+ my $filename = _normalize( shift );
+ my $name = shift || "directory $dirname contains file $filename";
+
+ unless( -d $dirname )
+ {
+ $Test->diag( "Directory [$dirname] does not exist!" );
+ return $Test->ok(0, $name);
+ }
+
+ my $ok = -e File::Spec->catfile($dirname, $filename);
+
+ if( $ok )
+ {
+ $Test->ok(1, $name);
+ }
+ else
+ {
+ $Test->diag( "File [$filename] does not exist in directory $dirname!" );
+ $Test->ok(0, $name);
+ }
+ }
+
+=item link_count_is_ok( FILE, LINK_COUNT [, NAME ] )
Ok if the link count to FILE is LINK_COUNT. LINK_COUNT is interpreted
as an integer. A LINK_COUNT that evaluates to 0 returns Ok if the file
does not exist.
-The optional NAME parameter is the name of the test.
-
=cut
@@ -997,14 +1181,12 @@ sub link_count_is_ok
$Test->ok( 1, $name );
}
-=item link_count_gt_ok( FILE, LINK_COUNT [, NAME] )
+=item link_count_gt_ok( FILE, LINK_COUNT [, NAME ] )
Ok if the link count to FILE is greater than LINK_COUNT. LINK_COUNT is
interpreted as an integer. A LINK_COUNT that evaluates to 0 returns Ok
if the file has at least one link.
-The optional NAME parameter is the name of the test.
-
=cut
sub link_count_gt_ok
@@ -1027,14 +1209,12 @@ sub link_count_gt_ok
$Test->ok( 1, $name );
}
-=item link_count_lt_ok( FILE, LINK_COUNT [, NAME] )
+=item link_count_lt_ok( FILE, LINK_COUNT [, NAME ] )
Ok if the link count to FILE is less than LINK_COUNT. LINK_COUNT is
interpreted as an integer. A LINK_COUNT that evaluates to 0 returns Ok
if the file has at least one link.
-The optional NAME parameter is the name of the test.
-
=cut
sub link_count_lt_ok
@@ -1091,14 +1271,12 @@ sub _dm_skeleton
return;
}
-=item owner_is( FILE , OWNER [, NAME] )
+=item owner_is( FILE , OWNER [, NAME ] )
Ok if FILE's owner is the same as OWNER. OWNER may be a text user name
or a numeric userid. Test skips on Dos, and Mac OS <= 9.
If the file does not exist, the test fails.
-The optional NAME parameter is the name of the test.
-
Contributed by Dylan Martin
=cut
@@ -1142,14 +1320,12 @@ sub owner_is
return $Test->ok( 0, $name );
}
-=item owner_isnt( FILE, OWNER [, NAME] )
+=item owner_isnt( FILE, OWNER [, NAME ] )
Ok if FILE's owner is not the same as OWNER. OWNER may be a text user name
or a numeric userid. Test skips on Dos and Mac OS <= 9. If the file
does not exist, the test fails.
-The optional NAME parameter is the name of the test.
-
Contributed by Dylan Martin
=cut
@@ -1179,15 +1355,13 @@ sub owner_isnt
return $Test->ok( 0, $name );
}
-=item group_is( FILE , GROUP [, NAME] )
+=item group_is( FILE , GROUP [, NAME ] )
Ok if FILE's group is the same as GROUP. GROUP may be a text group name or
a numeric group id. Test skips on Dos, Mac OS <= 9 and any other operating
systems that do not support getpwuid() and friends. If the file does not
exist, the test fails.
-The optional NAME parameter is the name of the test.
-
Contributed by Dylan Martin
=cut
@@ -1232,15 +1406,13 @@ sub group_is
return $Test->ok( 0, $name );
}
-=item group_isnt( FILE , GROUP [, NAME] )
+=item group_isnt( FILE , GROUP [, NAME ] )
Ok if FILE's group is not the same as GROUP. GROUP may be a text group name or
a numeric group id. Test skips on Dos, Mac OS <= 9 and any other operating
systems that do not support getpwuid() and friends. If the file does not
exist, the test fails.
-The optional NAME parameter is the name of the test.
-
Contributed by Dylan Martin
=cut
@@ -1340,13 +1512,17 @@ some functions.
Tom Metro helped me figure out some Windows capabilities.
-Dylan Martin added C<owner_is> and C<owner_isnt>
+Dylan Martin added C<owner_is> and C<owner_isnt>.
David Wheeler added C<file_line_count_is>.
+Buddy Burden C<< <barefoot@cpan.org> >> provided C<dir_exists_ok>,
+C<dir_contains_ok>, C<file_contains_like>, and
+C<file_contains_unlike>.
+
=head1 COPYRIGHT AND LICENSE
-Copyright (c) 2002-2009 brian d foy. All rights reserved.
+Copyright (c) 2002-2011 brian d foy. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
View
7 t/dm_skeleton.t
@@ -74,9 +74,8 @@ test_test();
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
-chdir '..' or print "bail out! Could not change directories: $!";
-
END {
-unlink glob( "test_files/*" );
-rmdir "test_files";
+ chdir '..' or print "bail out! Could not change directories: $!";
+ unlink glob( "test_files/*" );
+ rmdir "test_files";
}
View
161 t/file_contains.t
@@ -0,0 +1,161 @@
+use strict;
+use warnings;
+
+use Test::Builder::Tester;
+use Test::More 0.88;
+use Test::File;
+
+
+my $test_directory = 'test_files';
+require "t/setup_common" unless -d $test_directory;
+
+chdir $test_directory or print "bail out! Could not change directories: $!";
+
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+
+my $file = 'min_file';
+my $contents = do { open FH, $file; local $/; <FH> }; close FH;
+my $pattern1 = 'x' x 11; $pattern1 = qr/^ $pattern1 $/mx;
+my $pattern2 = 'x' x 40; $pattern2 = qr/^ $pattern2 $/mx;
+my $bad_pattern = 'x' x 20; $bad_pattern = qr/^ $bad_pattern $/mx;
+
+
+# like : single pattern
+
+test_out( "ok 1 - min_file contains $pattern1" );
+file_contains_like( $file, $pattern1 );
+test_test();
+
+test_out( "not ok 1 - bmoogle contains $pattern1" );
+test_diag( 'File [bmoogle] does not exist!' );
+test_fail(+1);
+file_contains_like( 'bmoogle', $pattern1 );
+test_test();
+
+test_out( "not ok 1 - not_readable contains $pattern1" );
+test_diag( 'File [not_readable] is not readable!' );
+test_fail(+1);
+file_contains_like( 'not_readable', $pattern1 );
+test_test();
+
+test_out( "not ok 1 - min_file contains $bad_pattern" );
+test_fail(+2);
+like_diag($contents, $bad_pattern, "doesn't match");
+file_contains_like( 'min_file', $bad_pattern );
+test_test();
+
+
+# unlike : single pattern
+
+test_out( "ok 1 - min_file doesn't contain $bad_pattern" );
+file_contains_unlike( $file, $bad_pattern );
+test_test();
+
+test_out( "not ok 1 - bmoogle doesn't contain $bad_pattern" );
+test_diag( 'File [bmoogle] does not exist!' );
+test_fail(+1);
+file_contains_unlike( 'bmoogle', $bad_pattern );
+test_test();
+
+test_out( "not ok 1 - not_readable doesn't contain $bad_pattern" );
+test_diag( 'File [not_readable] is not readable!' );
+test_fail(+1);
+file_contains_unlike( 'not_readable', $bad_pattern );
+test_test();
+
+test_out( "not ok 1 - min_file doesn't contain $pattern1" );
+test_fail(+2);
+like_diag($contents, $pattern1, "matches");
+file_contains_unlike( 'min_file', $pattern1 );
+test_test();
+
+
+# like : multiple patterns
+
+test_out( "ok 1 - min_file contains $pattern1" );
+test_out( "ok 2 - min_file contains $pattern2" );
+file_contains_like( $file, [ $pattern1, $pattern2 ] );
+test_test();
+
+test_out( "ok 1 - file has the goods" );
+test_out( "ok 2 - file has the goods" );
+file_contains_like( $file, [ $pattern1, $pattern2 ], 'file has the goods' );
+test_test();
+
+test_out( "not ok 1 - bmoogle contains $pattern1" );
+test_diag( 'File [bmoogle] does not exist!' );
+test_fail(+1);
+file_contains_like( 'bmoogle', [ $pattern1, $pattern2 ] );
+test_test();
+
+test_out( "not ok 1 - not_readable contains $pattern1" );
+test_diag( 'File [not_readable] is not readable!' );
+test_fail(+1);
+file_contains_like( 'not_readable', [ $pattern1, $pattern2 ] );
+test_test();
+
+test_out( "ok 1 - min_file contains $pattern1" );
+test_out( "not ok 2 - min_file contains $bad_pattern" );
+test_fail(+2);
+like_diag($contents, $bad_pattern, "doesn't match");
+file_contains_like( 'min_file', [ $pattern1, $bad_pattern ] );
+test_test();
+
+
+# unlike : multiple patterns
+
+test_out( "ok 1 - min_file doesn't contain $bad_pattern" );
+test_out( "ok 2 - min_file doesn't contain $bad_pattern" );
+file_contains_unlike( $file, [ $bad_pattern, $bad_pattern ] );
+test_test();
+
+test_out( "ok 1 - file has the goods" );
+test_out( "ok 2 - file has the goods" );
+file_contains_unlike( $file, [ $bad_pattern, $bad_pattern ], 'file has the goods' );
+test_test();
+
+test_out( "not ok 1 - bmoogle doesn't contain $bad_pattern" );
+test_diag( 'File [bmoogle] does not exist!' );
+test_fail(+1);
+file_contains_unlike( 'bmoogle', [ $bad_pattern, $bad_pattern ] );
+test_test();
+
+test_out( "not ok 1 - not_readable doesn't contain $bad_pattern" );
+test_diag( 'File [not_readable] is not readable!' );
+test_fail(+1);
+file_contains_unlike( 'not_readable', [ $bad_pattern, $bad_pattern ] );
+test_test();
+
+test_out( "ok 1 - min_file doesn't contain $bad_pattern" );
+test_out( "not ok 2 - min_file doesn't contain $pattern1" );
+test_fail(+2);
+like_diag($contents, $pattern1, "matches");
+file_contains_unlike( 'min_file', [ $bad_pattern, $pattern1 ] );
+test_test();
+
+
+done_testing();
+
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+
+END {
+ chdir '..' or print "bail out! Could not change directories: $!";
+ unlink glob( "test_files/*" );
+ rmdir "test_files";
+}
+
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+
+sub like_diag
+{
+ my ($string, $pattern, $verb) = @_;
+
+ my $diag = ' ' x 18 . "'$string'\n";
+ $diag .= sprintf("%17s '%s'", $verb, $pattern);
+ $diag =~ s/^/# /mg;
+
+ test_err($diag);
+}
View
7 t/file_sizes.t
@@ -163,9 +163,8 @@ test_test();
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
-chdir '..' or print "bail out! Could not change directories: $!";
-
END {
-unlink glob( "test_files/*" );
-rmdir "test_files";
+ chdir '..' or print "bail out! Could not change directories: $!";
+ unlink glob( "test_files/*" );
+ rmdir "test_files";
}
View
7 t/line_counters.t
@@ -189,9 +189,8 @@ test_test();
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
-chdir '..' or print "bail out! Could not change directories: $!";
-
END {
-unlink glob( "test_files/*" );
-rmdir "test_files";
+ chdir '..' or print "bail out! Could not change directories: $!";
+ unlink glob( "test_files/*" );
+ rmdir "test_files";
}
View
7 t/link_counts.t
@@ -84,9 +84,8 @@ test_test();
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
-chdir '..' or print "bail out! Could not change directories: $!";
-
END {
-unlink glob( "test_files/*" );
-rmdir "test_files";
+ chdir '..' or print "bail out! Could not change directories: $!";
+ unlink glob( "test_files/*" );
+ rmdir "test_files";
}
View
6 t/owner.t
@@ -189,7 +189,9 @@ test_diag(
group_isnt( $filename, $file_group_name, $name );
test_test( $name );
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+
END {
-unlink glob( "test_files/*" );
-rmdir "test_files";
+ unlink glob( "test_files/*" );
+ rmdir "test_files";
}
View
64 t/test_dirs.t
@@ -0,0 +1,64 @@
+use strict;
+use warnings;
+
+use Test::Builder::Tester;
+use Test::More 0.88;
+use Test::File;
+
+
+my $test_directory = 'test_files';
+require "t/setup_common" unless -d $test_directory;
+
+chdir $test_directory or print "bail out! Could not change directories: $!";
+mkdir 'test_dir', 0700;
+open FH, '> test_dir/subdir_file'; close FH;
+
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+
+test_out( 'ok 1 - test_dir is a directory' );
+dir_exists_ok( 'test_dir' );
+test_test();
+
+test_out( 'not ok 1 - bmoogle is a directory' );
+test_diag( 'File [bmoogle] does not exist!' );
+test_fail(+1);
+dir_exists_ok( 'bmoogle' );
+test_test();
+
+test_out( 'not ok 1 - readable is a directory' );
+test_diag( 'File [readable] exists but is not a directory!' );
+test_fail(+1);
+dir_exists_ok( 'readable' );
+test_test();
+
+
+test_out( 'ok 1 - directory test_dir contains file subdir_file' );
+dir_contains_ok( 'test_dir', 'subdir_file' );
+test_test();
+
+test_out( 'not ok 1 - directory bmoogle contains file subdir_file' );
+test_diag( 'Directory [bmoogle] does not exist!' );
+test_fail(+1);
+dir_contains_ok( 'bmoogle', 'subdir_file' );
+test_test();
+
+test_out( 'not ok 1 - directory test_dir contains file bmoogle' );
+test_diag( 'File [bmoogle] does not exist in directory test_dir!' );
+test_fail(+1);
+dir_contains_ok( 'test_dir', 'bmoogle' );
+test_test();
+
+
+done_testing();
+
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+
+END {
+ chdir '..' or print "bail out! Could not change directories: $!";
+ unlink glob( "test_files/test_dir/*" );
+ rmdir "test_files/test_dir";
+ unlink glob( "test_files/*" );
+ rmdir "test_files";
+}
View
7 t/test_files.t
@@ -128,9 +128,8 @@ test_test();
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
-chdir '..' or print "bail out! Could not change directories: $!";
-
END {
-unlink glob( "test_files/*" );
-rmdir "test_files";
+ chdir '..' or print "bail out! Could not change directories: $!";
+ unlink glob( "test_files/*" );
+ rmdir "test_files";
}
View
2  t/test_manifest
@@ -6,9 +6,11 @@ dm_skeleton.t
win32.t
obviously_non_multi_user.t
test_files.t
+test_dirs.t
links.t
link_counts.t
line_counters.t
file_sizes.t
+file_contains.t
owner.t
rt/30346.t
Something went wrong with that request. Please try again.