File(3p)

NAME
Test::File -- test file attributes

SYNOPSIS
use Test::File;

DESCRIPTION
This modules provides a collection of test utilities for file attributes.

Some file attributes depend on the owner of the process testing the file in the same way the file test operators do. For instance, root (or super-user or Administrator) may always be able to read files no matter the permissions.

Some attributes don't make sense outside of Unix, either, so some 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. :)

  Functions

file_exists_ok( FILENAME [, NAME ] )
    Ok if the file exists, and not ok otherwise.

file_not_exists_ok( FILENAME [, NAME ] )
    Ok if the file does not exist, and not okay if it does exist.

file_empty_ok( FILENAME [, NAME ] )
    Ok if the file exists and has empty size, not ok if the file does not exist or exists with non-zero size.

file_not_empty_ok( FILENAME [, NAME ] )
    Ok if the file exists and has non-zero size, not ok if the file does not exist or exists with zero size.

file_size_ok( FILENAME, SIZE [, NAME ]  )
    Ok if the file exists and has SIZE size in bytes (exactly), not ok if the file does not exist or exists with size other than SIZE.

file_max_size_ok( FILENAME, MAX [, NAME ] )
    Ok if the file exists and has size less than or equal to MAX bytes, not ok if the file does not exist or exists with size greater than MAX bytes.

file_min_size_ok( FILENAME, MIN [, NAME ] )
    Ok if the file exists and has size greater than or equal to MIN bytes, not ok if the file does not exist or exists with size less than MIN bytes.

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.

    This function using the current value of $/ as the line ending and counts the lines by reading them and counting how many it read.

file_line_count_isnt( FILENAME, COUNT [, NAME ]  )
    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 $/ as the line ending and counts the lines by reading them and counting how many it read.

file_line_count_between( FILENAME, MIN, MAX, [, NAME ]  )
    Ok if the file exists and has a line count between MIN and MAX, inclusively.

    This function using the current value of $/ as the line ending and counts the lines by reading them and counting how many it read.

file_readable_ok( FILENAME [, NAME ] )
    Ok if the file exists and is readable, not ok if the file does not exist or is not readable.

file_not_readable_ok( FILENAME [, NAME ] )
    Ok if the file exists and is not readable, not ok if the file does not exist or is readable.

file_writeable_ok( FILENAME [, NAME ] )
    Ok if the file exists and is writeable, not ok if the file does not exist or is not writeable.

file_not_writeable_ok( FILENAME [, NAME ] )
    Ok if the file exists and is not writeable, not ok if the file does not exist or is writeable.

file_executable_ok( FILENAME [, NAME ] )
    Ok if the file exists and is executable, not ok if the file does not exist or is not executable.

    This test automatically skips if it thinks it is on a Windows platform.

file_not_executable_ok( FILENAME [, NAME ] )
    Ok if the file exists and is not executable, not ok if the file does not exist or is executable.

    This test automatically skips if it thinks it is on a Windows platform.

file_mode_is( FILENAME, MODE [, NAME ] )
    Ok if the file exists and the mode matches, not ok if the file does not exist or the mode does not match.

    This test automatically skips if it thinks it is on a Windows platform.

    Contributed by Shawn Sorichetti "<ssoriche@coloredblocks.net>"

file_mode_isnt( FILENAME, MODE [, NAME ] )
    Ok if the file exists and mode does not match, not ok if the file does not exist or mode does match.

    This test automatically skips if it thinks it is on a Windows platform.

    Contributed by Shawn Sorichetti "<ssoriche@coloredblocks.net>"

file_is_symlink_ok( FILENAME [, NAME] )
    Ok is 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.

symlink_target_exists_ok( SYMLINK [, TARGET] [, NAME] )
    Ok is 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.

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.

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. 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.

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. 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.

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. 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.

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

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

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

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

TO DO
* check properties for other users (readable_by_root, for instance)

* check times

* check number of links to file

* check path parts (directory, filename, extension)

SEE ALSO
Test::Builder, Test::More

SOURCE AVAILABILITY
This source is part of a SourceForge project which always has the latest sources in CVS, as well as all of the previous releases.

        http://sourceforge.net/projects/brian-d-foy/

If, for some reason, I disappear from the world, one of the other members of the project can shepherd this module appropriately.

AUTHOR
brian d foy, "<bdfoy@cpan.org>"

CREDITS
Shawn Sorichetti "<ssoriche@coloredblocks.net>" provided some functions.

Tom Metro helped me figure out some Windows capabilities.

Dylan Martin added "owner_is" and "owner_isnt"

David Wheeler added "file_line_count_is".

COPYRIGHT AND LICENSE
Copyright (c) 2002-2008 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.