NAME Test::TempDir::Tiny - Temporary directories that stick around when tests fail VERSION version 0.001 SYNOPSIS # t/foo.t use Test::More; use Test::TempDir::Tiny; $dir = tempdir(); # ./tmp/t_foo_t/default_1/ $dir = tempdir("label"); # ./tmp/t_foo_t/label_1/ $dir = tempdir("label"); # ./tmp/t_foo_t/label_2/ DESCRIPTION This module works with Test::More to create temporary directories that stick around if tests fail. It is loosely based on Test::TempDir, but with less complexity, greater portability and zero non-core dependencies. (Capture::Tiny is recommended for testing.) The "tempdir" function is exported by default. When called, it constructs a directory tree to hold temporary directories. If the current directory is writable, the root for directories will be ./tmp. Otherwise, a File::Temp directory will be created wherever temporary directories are stored for your system. Every *.t file gets its own subdirectory under the root based on the test filename, but with slashes and periods replaced with underscores. For example, t/foo.t would get a test-file-specific subdirectory ./tmp/t_foo_t/. Directories created by "tempdir" get put in that directory. This makes it very easy to find files later if tests fail. When the test file exits, if all tests passed, then the test-file-specific directory is recursively removed. If a test failed and the root directory is ./tmp, the test-file-specific directory sticks around for inspection. (But if the root is a File::Temp directory, it is always discarded). If nothing is left in ./tmp (i.e. no other test file failed), then ./tmp is cleaned up as well. FUNCTIONS tempdir $dir = tempdir(); # .../default_1/ $dir = tempdir("label"); # .../label_1/ Creates a directory underneath a test-file-specific temporary directory and returns the absolute path to it. The function takes a single argument as a label for the directory or defaults to "default". An incremental counter value will be appended to allow a label to be used within a loop with distinct temporary directories: # t/foo.t for ( 1 .. 3 ) { tempdir("in loop"); } # creates: # ./tmp/t_foo_t/in_loop_1 # ./tmp/t_foo_t/in_loop_2 # ./tmp/t_foo_t/in_loop_3 If the label contains any characters besides alphanumerics, underscore and dash, they will be replaced with underscore. $dir = tempdir("a space"); # .../a_space_1/ $dir = tempdir("a!bang"); # .../a_bang_1/ The test-file-specific directory and all directories within it will be cleaned up with an END block if the current test file passes tests. SEE ALSO * File::Temp * Path::Tiny SUPPORT Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at . You will be notified automatically of any progress on your issue. Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. git clone https://github.com/dagolden/Test-TempDir-Tiny.git AUTHOR David Golden COPYRIGHT AND LICENSE This software is Copyright (c) 2014 by David Golden. This is free software, licensed under: The Apache License, Version 2.0, January 2004