Test::Directory - Perl extension for maintaining test directories. |
Test::Directory - Perl extension for maintaining test directories.
use Test::Directory use My::Module
my $dir = Test::Directory->new($path); $dir->touch($src_file); My::Module::something( $dir->path($src_file), $dir->path($dst_file) ); $dir->has_ok($dst_file); #did my module create dst? $dir->hasnt_ok($src_file); #is source still there?
Testing code can involve making sure that files are created and deleted as expected. Doing this manually can be error prone, as it's easy to forget a file, or miss that some unexpected file was added. This module simplifies maintaining test directories by tracking their status as they are modified or tested with this API, making it simple to test both individual files, as well as to verify that there are no missing or unknown files.
The idea is to use this API to create a temporary directory and populate an initial set of files. Then, whenever something in the directory is changes, use the test methods to verify that the change happened as expected. At any time, it is simple to verify that the contents of the directory are exactly as expected.
Test::Directory implements an object-oriented interface for managing test directories. It tracks which files it knows about (by creating or testing them via its API), and can report if any files were missing or unexpectedly added.
There are two flavors of methods for interacting with the directory. Utility methods simply return a value (i.e. the number of files/errors) with no output, while the Test functions use the Test::Builder manpage to produce the approriate test results and diagnostics for the test harness.
The directory will be automatically cleaned up when the object goes out of scope; see the clean method below for details.
$path will be created (or the constructor will die). If $path is undefined, a unique path will be automatically generated; otherwise it is an error for $path to already exist.
For portability, this method implicitly splits the path on UNIX-style / seperators, and rejoins it with the local directory seperator.
Absent any seperator substitution, the returned value would be equivalent to $file.
This method is used internally by the corresponding test methods.
This method is used internally by the corresponding test methods.
Note that replacing a file with a directory, or vice versa, would require calling both check_file and check_directory to update the state to reflect both changes.
This method is called automatically when the object goes out of scope.
The test methods validate the state of the test directory, calling the Test::Builder manpage's ok and diag methods to generate output.
$dir->touch('my-file.txt'); system ('gzip', $dir->path('my-file.txt')); $dir->has ('my-file.txt.gz', '.gz file is added'); $dir->hasnt('my-file.txt', '.txt file is removed'); $dir->is_ok; #verify no other changes to $dir
Steve Sanbeg, <sanbeg@cpan.org
Copyright (C) 2013 by Steve Sanbeg
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available.
Test::Directory - Perl extension for maintaining test directories. |