Test-TempDir-Tiny-0.010/000755 000765 000024 00000000000 12632600316 015145 5ustar00davidstaff000000 000000 Test-TempDir-Tiny-0.010/Changes000644 000765 000024 00000003047 12632600316 016444 0ustar00davidstaff000000 000000 Revision history for Test-TempDir-Tiny 0.010 2015-12-11 11:58:50-05:00 America/New_York - No changes from 0.009 0.009 2015-12-09 15:40:36-05:00 America/New_York (TRIAL RELEASE) [Fixes] - More tainting fixes 0.007 2015-12-09 11:03:38-05:00 America/New_York (TRIAL RELEASE) [Fixes] - Cleanup fixed to work in taint mode [Changes] - Raised minimum Perl prerequisite to 5.8.1 again, as 5.6 doesn't have necessary features in "B" 0.005 2015-07-17 16:13:55-04:00 America/New_York (TRIAL RELEASE) [Added] - Added 'in_tempdir' function to run code reference in a temporary directory - Setting $ENV{PERL_TEST_TEMPDIR_TINY_NOCLEANUP} to a true value will prevent any directories from being cleaned up [Changes] - Lowered minimum Perl prerequisite to 5.6 0.004 2015-03-04 16:53:21-05:00 America/New_York [Changes] - Temporary directories are returned with platform-native separators - Drop Time::HiRes in favor of built-in select to implement a small sleep [Fixes] - Fixes tests on Windows 0.003 2015-01-04 06:30:28-05:00 America/New_York [Fixes] - Changed temp directory creation to avoid race conditions under parallel testing 0.002 2014-11-05 06:09:24-05:00 America/New_York [Tests] - Added tests for non-word characters [Documentation] - Noted that test-file-specific dirs are cleaned when reused - Improved synopsis examples 0.001 2014-11-04 17:07:17-05:00 America/New_York - First release Test-TempDir-Tiny-0.010/CONTRIBUTING.mkdn000644 000765 000024 00000005751 12632600316 017737 0ustar00davidstaff000000 000000 ## HOW TO CONTRIBUTE Thank you for considering contributing to this distribution. This file contains instructions that will help you work with the source code. The distribution is managed with Dist::Zilla. This means than many of the usual files you might expect are not in the repository, but are generated at release time, as is much of the documentation. Some generated files are kept in the repository as a convenience (e.g. Makefile.PL or cpanfile). Generally, **you do not need Dist::Zilla to contribute patches**. You do need Dist::Zilla to create a tarball. See below for guidance. ### Getting dependencies If you have App::cpanminus 1.6 or later installed, you can use `cpanm` to satisfy dependencies like this: $ cpanm --installdeps . Otherwise, look for either a `Makefile.PL` or `cpanfile` file for a list of dependencies to satisfy. ### Running tests You can run tests directly using the `prove` tool: $ prove -l $ prove -lv t/some_test_file.t For most of my distributions, `prove` is entirely sufficient for you to test any patches you have. I use `prove` for 99% of my testing during development. ### Code style and tidying Please try to match any existing coding style. If there is a `.perltidyrc` file, please install Perl::Tidy and use perltidy before submitting patches. If there is a `tidyall.ini` file, you can also install Code::TidyAll and run `tidyall` on a file or `tidyall -a` to tidy all files. ### Patching documentation Much of the documentation Pod is generated at release time. Some is generated boilerplate; other documentation is built from pseudo-POD directives in the source like C<=method> or C<=func>. If you would like to submit a documentation edit, please limit yourself to the documentation you see. If you see typos or documentation issues in the generated docs, please email or open a bug ticket instead of patching. ### Installing and using Dist::Zilla Dist::Zilla is a very powerful authoring tool, optimized for maintaining a large number of distributions with a high degree of automation, but it has a large dependency chain, a bit of a learning curve and requires a number of author-specific plugins. To install it from CPAN, I recommend one of the following approaches for the quickest installation: # using CPAN.pm, but bypassing non-functional pod tests $ cpan TAP::Harness::Restricted $ PERL_MM_USE_DEFAULT=1 HARNESS_CLASS=TAP::Harness::Restricted cpan Dist::Zilla # using cpanm, bypassing *all* tests $ cpanm -n Dist::Zilla In either case, it's probably going to take about 10 minutes. Go for a walk, go get a cup of your favorite beverage, take a bathroom break, or whatever. When you get back, Dist::Zilla should be ready for you. Then you need to install any plugins specific to this distribution: $ cpan `dzil authordeps` $ dzil authordeps | cpanm Once installed, here are some dzil commands you might try: $ dzil build $ dzil test $ dzil xtest You can learn more about Dist::Zilla at http://dzil.org/ Test-TempDir-Tiny-0.010/corpus/000755 000765 000024 00000000000 12632600316 016460 5ustar00davidstaff000000 000000 Test-TempDir-Tiny-0.010/cpanfile000644 000765 000024 00000002661 12632600316 016656 0ustar00davidstaff000000 000000 requires "B" => "0"; requires "Carp" => "0"; requires "Cwd" => "0"; requires "Exporter" => "5.57"; requires "File::Path" => "2.01"; requires "File::Spec::Functions" => "0"; requires "File::Temp" => "0"; requires "perl" => "5.008001"; requires "strict" => "0"; requires "warnings" => "0"; on 'test' => sub { requires "ExtUtils::MakeMaker" => "0"; requires "File::Copy" => "0"; requires "File::Spec" => "0"; requires "Test::More" => "0"; requires "perl" => "5.008001"; }; on 'test' => sub { recommends "CPAN::Meta" => "2.120900"; recommends "Capture::Tiny" => "0.12"; }; on 'configure' => sub { requires "ExtUtils::MakeMaker" => "6.17"; requires "perl" => "5.008001"; }; on 'develop' => sub { requires "Dist::Zilla" => "5"; requires "Dist::Zilla::Plugin::OnlyCorePrereqs" => "0"; requires "Dist::Zilla::Plugin::Prereqs" => "0"; requires "Dist::Zilla::PluginBundle::DAGOLDEN" => "0.072"; requires "English" => "0"; requires "File::Spec" => "0"; requires "File::Temp" => "0"; requires "IO::Handle" => "0"; requires "IPC::Open3" => "0"; requires "Pod::Coverage::TrustPod" => "0"; requires "Pod::Wordlist" => "0"; requires "Software::License::Apache_2_0" => "0"; requires "Test::CPAN::Meta" => "0"; requires "Test::More" => "0"; requires "Test::Pod" => "1.41"; requires "Test::Pod::Coverage" => "1.08"; requires "Test::Spelling" => "0.12"; requires "Test::Version" => "1"; requires "blib" => "1.01"; }; Test-TempDir-Tiny-0.010/dist.ini000644 000765 000024 00000000423 12632600316 016610 0ustar00davidstaff000000 000000 name = Test-TempDir-Tiny author = David Golden license = Apache_2_0 copyright_holder = David Golden copyright_year = 2014 [@DAGOLDEN] :version = 0.072 [Prereqs / TestRecommends] Capture::Tiny = 0.12 [OnlyCorePrereqs] check_dual_life_versions = 0 Test-TempDir-Tiny-0.010/lib/000755 000765 000024 00000000000 12632600316 015713 5ustar00davidstaff000000 000000 Test-TempDir-Tiny-0.010/LICENSE000644 000765 000024 00000026354 12632600316 016164 0ustar00davidstaff000000 000000 This software is Copyright (c) 2014 by David Golden. This is free software, licensed under: The Apache License, Version 2.0, January 2004 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Test-TempDir-Tiny-0.010/Makefile.PL000644 000765 000024 00000003042 12632600316 017116 0ustar00davidstaff000000 000000 # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.042. use strict; use warnings; use 5.008001; use ExtUtils::MakeMaker 6.17; my %WriteMakefileArgs = ( "ABSTRACT" => "Temporary directories that stick around when tests fail", "AUTHOR" => "David Golden ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.17" }, "DISTNAME" => "Test-TempDir-Tiny", "LICENSE" => "apache", "MIN_PERL_VERSION" => "5.008001", "NAME" => "Test::TempDir::Tiny", "PREREQ_PM" => { "B" => 0, "Carp" => 0, "Cwd" => 0, "Exporter" => "5.57", "File::Path" => "2.01", "File::Spec::Functions" => 0, "File::Temp" => 0, "strict" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "ExtUtils::MakeMaker" => 0, "File::Copy" => 0, "File::Spec" => 0, "Test::More" => 0 }, "VERSION" => "0.010", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "B" => 0, "Carp" => 0, "Cwd" => 0, "Exporter" => "5.57", "ExtUtils::MakeMaker" => 0, "File::Copy" => 0, "File::Path" => "2.01", "File::Spec" => 0, "File::Spec::Functions" => 0, "File::Temp" => 0, "Test::More" => 0, "strict" => 0, "warnings" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); Test-TempDir-Tiny-0.010/MANIFEST000644 000765 000024 00000001037 12632600316 016277 0ustar00davidstaff000000 000000 # This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.042. CONTRIBUTING.mkdn Changes LICENSE MANIFEST META.json META.yml Makefile.PL README corpus/01-fail.t corpus/01-pass.t cpanfile dist.ini lib/Test/TempDir/Tiny.pm perlcritic.rc t/00-report-prereqs.dd t/00-report-prereqs.t t/basic.t t/taint.t tidyall.ini xt/author/00-compile.t xt/author/critic.t xt/author/pod-coverage.t xt/author/pod-spell.t xt/author/pod-syntax.t xt/author/test-version.t xt/release/distmeta.t xt/release/minimum-version.t xt/release/portability.t Test-TempDir-Tiny-0.010/META.json000644 000765 000024 00000006004 12632600316 016566 0ustar00davidstaff000000 000000 { "abstract" : "Temporary directories that stick around when tests fail", "author" : [ "David Golden " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 5.042, CPAN::Meta::Converter version 2.150001", "license" : [ "apache_2_0" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Test-TempDir-Tiny", "no_index" : { "directory" : [ "corpus", "examples", "t", "xt" ], "package" : [ "DB" ] }, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.17", "perl" : "5.008001" } }, "develop" : { "requires" : { "Dist::Zilla" : "5", "Dist::Zilla::Plugin::OnlyCorePrereqs" : "0", "Dist::Zilla::Plugin::Prereqs" : "0", "Dist::Zilla::PluginBundle::DAGOLDEN" : "0.072", "English" : "0", "File::Spec" : "0", "File::Temp" : "0", "IO::Handle" : "0", "IPC::Open3" : "0", "Pod::Coverage::TrustPod" : "0", "Pod::Wordlist" : "0", "Software::License::Apache_2_0" : "0", "Test::CPAN::Meta" : "0", "Test::More" : "0", "Test::Pod" : "1.41", "Test::Pod::Coverage" : "1.08", "Test::Spelling" : "0.12", "Test::Version" : "1", "blib" : "1.01" } }, "runtime" : { "requires" : { "B" : "0", "Carp" : "0", "Cwd" : "0", "Exporter" : "5.57", "File::Path" : "2.01", "File::Spec::Functions" : "0", "File::Temp" : "0", "perl" : "5.008001", "strict" : "0", "warnings" : "0" } }, "test" : { "recommends" : { "CPAN::Meta" : "2.120900", "Capture::Tiny" : "0.12" }, "requires" : { "ExtUtils::MakeMaker" : "0", "File::Copy" : "0", "File::Spec" : "0", "Test::More" : "0", "perl" : "5.008001" } } }, "provides" : { "Test::TempDir::Tiny" : { "file" : "lib/Test/TempDir/Tiny.pm", "version" : "0.010" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/dagolden/Test-TempDir-Tiny/issues" }, "homepage" : "https://github.com/dagolden/Test-TempDir-Tiny", "repository" : { "type" : "git", "url" : "https://github.com/dagolden/Test-TempDir-Tiny.git", "web" : "https://github.com/dagolden/Test-TempDir-Tiny" } }, "version" : "0.010", "x_authority" : "cpan:DAGOLDEN", "x_contributors" : [ "Christian Walde ", "David Golden ", "Shawn Laffan " ] } Test-TempDir-Tiny-0.010/META.yml000644 000765 000024 00000002400 12632600316 016412 0ustar00davidstaff000000 000000 --- abstract: 'Temporary directories that stick around when tests fail' author: - 'David Golden ' build_requires: ExtUtils::MakeMaker: '0' File::Copy: '0' File::Spec: '0' Test::More: '0' perl: '5.008001' configure_requires: ExtUtils::MakeMaker: '6.17' perl: '5.008001' dynamic_config: 0 generated_by: 'Dist::Zilla version 5.042, CPAN::Meta::Converter version 2.150001' license: apache meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Test-TempDir-Tiny no_index: directory: - corpus - examples - t - xt package: - DB provides: Test::TempDir::Tiny: file: lib/Test/TempDir/Tiny.pm version: '0.010' requires: B: '0' Carp: '0' Cwd: '0' Exporter: '5.57' File::Path: '2.01' File::Spec::Functions: '0' File::Temp: '0' perl: '5.008001' strict: '0' warnings: '0' resources: bugtracker: https://github.com/dagolden/Test-TempDir-Tiny/issues homepage: https://github.com/dagolden/Test-TempDir-Tiny repository: https://github.com/dagolden/Test-TempDir-Tiny.git version: '0.010' x_authority: cpan:DAGOLDEN x_contributors: - 'Christian Walde ' - 'David Golden ' - 'Shawn Laffan ' Test-TempDir-Tiny-0.010/perlcritic.rc000644 000765 000024 00000001242 12632600316 017632 0ustar00davidstaff000000 000000 severity = 5 verbose = 8 [Variables::ProhibitPunctuationVars] allow = $@ $! [TestingAndDebugging::ProhibitNoStrict] allow = refs [Variables::ProhibitEvilVariables] variables = $DB::single # Turn these off [-BuiltinFunctions::ProhibitStringyEval] [-ControlStructures::ProhibitPostfixControls] [-ControlStructures::ProhibitUnlessBlocks] [-Documentation::RequirePodSections] [-InputOutput::ProhibitInteractiveTest] [-References::ProhibitDoubleSigils] [-RegularExpressions::RequireExtendedFormatting] [-InputOutput::ProhibitTwoArgOpen] [-Modules::ProhibitEvilModules] [-BuiltinFunctions::ProhibitSleepViaSelect] # Turn this on [Lax::ProhibitStringyEval::ExceptForRequire] Test-TempDir-Tiny-0.010/README000644 000765 000024 00000012543 12632600316 016032 0ustar00davidstaff000000 000000 NAME Test::TempDir::Tiny - Temporary directories that stick around when tests fail VERSION version 0.010 SYNOPSIS # t/foo.t use Test::More; use Test::TempDir::Tiny; # default tempdirs $dir = tempdir(); # ./tmp/t_foo_t/default_1/ $dir = tempdir(); # ./tmp/t_foo_t/default_2/ # labeled tempdirs $dir = tempdir("label"); # ./tmp/t_foo_t/label_1/ $dir = tempdir("label"); # ./tmp/t_foo_t/label_2/ # labels with spaces and non-word characters $dir = tempdir("bar baz") # ./tmp/t_foo_t/bar_baz_1/ $dir = tempdir("!!!bang") # ./tmp/t_foo_t/_bang_1/ # run code in a temporary directory in_tempdir "label becomes name" => sub { my $cwd = shift; # do stuff in a tempdir }; 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" and "in_tempdir" functions are exported by default. 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. The test-file-specific name is consistent from run-to-run. If an old directory already exists, it will be removed. 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 (unless it's a symlink). This module attempts to avoid race conditions due to parallel testing. In extreme cases, the test-file-specific subdirectory might be created as a regular File::Temp directory rather than in ./tmp. In such a case, a warning will be issued. 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 in platform-native form (i.e. with backslashes on Windows). 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 collapsed and replaced with a single 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. in_tempdir in_tempdir "label becomes name" => sub { my $cwd = shift; # this happens in tempdir }; Given a label and a code reference, creates a temporary directory based on the label (following the rules of "tempdir"), changes to that directory, runs the code, then changes back to the original directory. The temporary directory path is given as an argument to the code reference. When the code finishes (even if it dies), "in_tempdir" will change back to the original directory if it can, to the root if it can't, and will rethrow any fatal errors. ENVIRONMENT "PERL_TEST_TEMPDIR_TINY_NOCLEANUP" When this environment variable is true, directories will not be cleaned up, even if tests pass. 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 CONTRIBUTORS * Christian Walde * David Golden * Shawn Laffan 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 Test-TempDir-Tiny-0.010/t/000755 000765 000024 00000000000 12632600316 015410 5ustar00davidstaff000000 000000 Test-TempDir-Tiny-0.010/tidyall.ini000644 000765 000024 00000000240 12632600316 017304 0ustar00davidstaff000000 000000 ; Install Code::TidyAll ; run "tidyall -a" to tidy all files ; run "tidyall -g" to tidy only files modified from git [PerlTidy] select = {lib,t}/**/*.{pl,pm,t} Test-TempDir-Tiny-0.010/xt/000755 000765 000024 00000000000 12632600316 015600 5ustar00davidstaff000000 000000 Test-TempDir-Tiny-0.010/xt/author/000755 000765 000024 00000000000 12632600316 017102 5ustar00davidstaff000000 000000 Test-TempDir-Tiny-0.010/xt/release/000755 000765 000024 00000000000 12632600316 017220 5ustar00davidstaff000000 000000 Test-TempDir-Tiny-0.010/xt/release/distmeta.t000644 000765 000024 00000000172 12632600316 021217 0ustar00davidstaff000000 000000 #!perl # This file was automatically generated by Dist::Zilla::Plugin::MetaTests. use Test::CPAN::Meta; meta_yaml_ok(); Test-TempDir-Tiny-0.010/xt/release/minimum-version.t000644 000765 000024 00000000266 12632600316 022547 0ustar00davidstaff000000 000000 #!perl use Test::More; eval "use Test::MinimumVersion"; plan skip_all => "Test::MinimumVersion required for testing minimum versions" if $@; all_minimum_version_ok( qq{5.010} ); Test-TempDir-Tiny-0.010/xt/release/portability.t000644 000765 000024 00000000332 12632600316 021745 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More; eval 'use Test::Portability::Files'; plan skip_all => 'Test::Portability::Files required for testing portability' if $@; options(test_one_dot => 0); run_tests(); Test-TempDir-Tiny-0.010/xt/author/00-compile.t000644 000765 000024 00000002362 12632600316 021137 0ustar00davidstaff000000 000000 use 5.006; use strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::Compile 2.054 use Test::More; plan tests => 2; my @module_files = ( 'Test/TempDir/Tiny.pm' ); # fake home for cpan-testers use File::Temp; local $ENV{HOME} = File::Temp::tempdir( CLEANUP => 1 ); my $inc_switch = -d 'blib' ? '-Mblib' : '-Ilib'; use File::Spec; use IPC::Open3; use IO::Handle; open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!"; my @warnings; for my $lib (@module_files) { # see L my $stderr = IO::Handle->new; my $pid = open3($stdin, '>&STDERR', $stderr, $^X, $inc_switch, '-e', "require q[$lib]"); binmode $stderr, ':crlf' if $^O eq 'MSWin32'; my @_warnings = <$stderr>; waitpid($pid, 0); is($?, 0, "$lib loaded ok"); shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/ and not eval { require blib; blib->VERSION('1.01') }; if (@_warnings) { warn @_warnings; push @warnings, @_warnings; } } is(scalar(@warnings), 0, 'no warnings found') or diag 'got warnings: ', ( Test::More->can('explain') ? Test::More::explain(\@warnings) : join("\n", '', @warnings) ); Test-TempDir-Tiny-0.010/xt/author/critic.t000644 000765 000024 00000000435 12632600316 020546 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More; use English qw(-no_match_vars); eval "use Test::Perl::Critic"; plan skip_all => 'Test::Perl::Critic required to criticise code' if $@; Test::Perl::Critic->import( -profile => "perlcritic.rc" ) if -e "perlcritic.rc"; all_critic_ok(); Test-TempDir-Tiny-0.010/xt/author/pod-coverage.t000644 000765 000024 00000000334 12632600316 021642 0ustar00davidstaff000000 000000 #!perl # This file was automatically generated by Dist::Zilla::Plugin::PodCoverageTests. use Test::Pod::Coverage 1.08; use Pod::Coverage::TrustPod; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' }); Test-TempDir-Tiny-0.010/xt/author/pod-spell.t000644 000765 000024 00000000504 12632600316 021165 0ustar00davidstaff000000 000000 use strict; use warnings; use Test::More; # generated by Dist::Zilla::Plugin::Test::PodSpelling 2.007000 use Test::Spelling 0.12; use Pod::Wordlist; add_stopwords(); all_pod_files_spelling_ok( qw( bin lib ) ); __DATA__ David Golden dagolden Christian Walde walde xdg Shawn Laffan shawnlaffan lib Test TempDir Tiny Test-TempDir-Tiny-0.010/xt/author/pod-syntax.t000644 000765 000024 00000000252 12632600316 021374 0ustar00davidstaff000000 000000 #!perl # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use strict; use warnings; use Test::More; use Test::Pod 1.41; all_pod_files_ok(); Test-TempDir-Tiny-0.010/xt/author/test-version.t000644 000765 000024 00000000640 12632600316 021731 0ustar00davidstaff000000 000000 use strict; use warnings; use Test::More; # generated by Dist::Zilla::Plugin::Test::Version 1.05 use Test::Version; my @imports = qw( version_all_ok ); my $params = { is_strict => 0, has_version => 1, multiple => 0, }; push @imports, $params if version->parse( $Test::Version::VERSION ) >= version->parse('1.002'); Test::Version->import(@imports); version_all_ok; done_testing; Test-TempDir-Tiny-0.010/t/00-report-prereqs.dd000644 000765 000024 00000005626 12632600316 021141 0ustar00davidstaff000000 000000 do { my $x = { 'configure' => { 'requires' => { 'ExtUtils::MakeMaker' => '6.17', 'perl' => '5.008001' } }, 'develop' => { 'requires' => { 'Dist::Zilla' => '5', 'Dist::Zilla::Plugin::OnlyCorePrereqs' => '0', 'Dist::Zilla::Plugin::Prereqs' => '0', 'Dist::Zilla::PluginBundle::DAGOLDEN' => '0.072', 'English' => '0', 'File::Spec' => '0', 'File::Temp' => '0', 'IO::Handle' => '0', 'IPC::Open3' => '0', 'Pod::Coverage::TrustPod' => '0', 'Pod::Wordlist' => '0', 'Software::License::Apache_2_0' => '0', 'Test::CPAN::Meta' => '0', 'Test::More' => '0', 'Test::Pod' => '1.41', 'Test::Pod::Coverage' => '1.08', 'Test::Spelling' => '0.12', 'Test::Version' => '1', 'blib' => '1.01' } }, 'runtime' => { 'requires' => { 'B' => '0', 'Carp' => '0', 'Cwd' => '0', 'Exporter' => '5.57', 'File::Path' => '2.01', 'File::Spec::Functions' => '0', 'File::Temp' => '0', 'perl' => '5.008001', 'strict' => '0', 'warnings' => '0' } }, 'test' => { 'recommends' => { 'CPAN::Meta' => '2.120900', 'Capture::Tiny' => '0.12' }, 'requires' => { 'ExtUtils::MakeMaker' => '0', 'File::Copy' => '0', 'File::Spec' => '0', 'Test::More' => '0', 'perl' => '5.008001' } } }; $x; }Test-TempDir-Tiny-0.010/t/00-report-prereqs.t000644 000765 000024 00000012731 12632600316 021010 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; # This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.021 use Test::More tests => 1; use ExtUtils::MakeMaker; use File::Spec; # from $version::LAX my $lax_version_re = qr/(?: undef | (?: (?:[0-9]+) (?: \. | (?:\.[0-9]+) (?:_[0-9]+)? )? | (?:\.[0-9]+) (?:_[0-9]+)? ) | (?: v (?:[0-9]+) (?: (?:\.[0-9]+)+ (?:_[0-9]+)? )? | (?:[0-9]+)? (?:\.[0-9]+){2,} (?:_[0-9]+)? ) )/x; # hide optional CPAN::Meta modules from prereq scanner # and check if they are available my $cpan_meta = "CPAN::Meta"; my $cpan_meta_pre = "CPAN::Meta::Prereqs"; my $HAS_CPAN_META = eval "require $cpan_meta; $cpan_meta->VERSION('2.120900')" && eval "require $cpan_meta_pre"; ## no critic # Verify requirements? my $DO_VERIFY_PREREQS = 1; sub _max { my $max = shift; $max = ( $_ > $max ) ? $_ : $max for @_; return $max; } sub _merge_prereqs { my ($collector, $prereqs) = @_; # CPAN::Meta::Prereqs object if (ref $collector eq $cpan_meta_pre) { return $collector->with_merged_prereqs( CPAN::Meta::Prereqs->new( $prereqs ) ); } # Raw hashrefs for my $phase ( keys %$prereqs ) { for my $type ( keys %{ $prereqs->{$phase} } ) { for my $module ( keys %{ $prereqs->{$phase}{$type} } ) { $collector->{$phase}{$type}{$module} = $prereqs->{$phase}{$type}{$module}; } } } return $collector; } my @include = qw( ); my @exclude = qw( ); # Add static prereqs to the included modules list my $static_prereqs = do 't/00-report-prereqs.dd'; # Merge all prereqs (either with ::Prereqs or a hashref) my $full_prereqs = _merge_prereqs( ( $HAS_CPAN_META ? $cpan_meta_pre->new : {} ), $static_prereqs ); # Add dynamic prereqs to the included modules list (if we can) my ($source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; if ( $source && $HAS_CPAN_META ) { if ( my $meta = eval { CPAN::Meta->load_file($source) } ) { $full_prereqs = _merge_prereqs($full_prereqs, $meta->prereqs); } } else { $source = 'static metadata'; } my @full_reports; my @dep_errors; my $req_hash = $HAS_CPAN_META ? $full_prereqs->as_string_hash : $full_prereqs; # Add static includes into a fake section for my $mod (@include) { $req_hash->{other}{modules}{$mod} = 0; } for my $phase ( qw(configure build test runtime develop other) ) { next unless $req_hash->{$phase}; next if ($phase eq 'develop' and not $ENV{AUTHOR_TESTING}); for my $type ( qw(requires recommends suggests conflicts modules) ) { next unless $req_hash->{$phase}{$type}; my $title = ucfirst($phase).' '.ucfirst($type); my @reports = [qw/Module Want Have/]; for my $mod ( sort keys %{ $req_hash->{$phase}{$type} } ) { next if $mod eq 'perl'; next if grep { $_ eq $mod } @exclude; my $file = $mod; $file =~ s{::}{/}g; $file .= ".pm"; my ($prefix) = grep { -e File::Spec->catfile($_, $file) } @INC; my $want = $req_hash->{$phase}{$type}{$mod}; $want = "undef" unless defined $want; $want = "any" if !$want && $want == 0; my $req_string = $want eq 'any' ? 'any version required' : "version '$want' required"; if ($prefix) { my $have = MM->parse_version( File::Spec->catfile($prefix, $file) ); $have = "undef" unless defined $have; push @reports, [$mod, $want, $have]; if ( $DO_VERIFY_PREREQS && $HAS_CPAN_META && $type eq 'requires' ) { if ( $have !~ /\A$lax_version_re\z/ ) { push @dep_errors, "$mod version '$have' cannot be parsed ($req_string)"; } elsif ( ! $full_prereqs->requirements_for( $phase, $type )->accepts_module( $mod => $have ) ) { push @dep_errors, "$mod version '$have' is not in required range '$want'"; } } } else { push @reports, [$mod, $want, "missing"]; if ( $DO_VERIFY_PREREQS && $type eq 'requires' ) { push @dep_errors, "$mod is not installed ($req_string)"; } } } if ( @reports ) { push @full_reports, "=== $title ===\n\n"; my $ml = _max( map { length $_->[0] } @reports ); my $wl = _max( map { length $_->[1] } @reports ); my $hl = _max( map { length $_->[2] } @reports ); if ($type eq 'modules') { splice @reports, 1, 0, ["-" x $ml, "", "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s\n", -$ml, $_->[0], $hl, $_->[2]) } @reports; } else { splice @reports, 1, 0, ["-" x $ml, "-" x $wl, "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s %*s\n", -$ml, $_->[0], $wl, $_->[1], $hl, $_->[2]) } @reports; } push @full_reports, "\n"; } } } if ( @full_reports ) { diag "\nVersions for all modules listed in $source (including optional ones):\n\n", @full_reports; } if ( @dep_errors ) { diag join("\n", "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n", "The following REQUIRED prerequisites were not satisfied:\n", @dep_errors, "\n" ); } pass; # vim: ts=4 sts=4 sw=4 et: Test-TempDir-Tiny-0.010/t/basic.t000644 000765 000024 00000007335 12632600316 016666 0ustar00davidstaff000000 000000 use 5.006; use strict; use warnings; use Cwd qw/abs_path/; use File::Copy qw/copy/; use File::Spec; use File::Temp; use Test::More; # make Capture::Tiny optional BEGIN { my $class = "Capture::Tiny"; # hide from scanners eval "use $class 'capture'"; ## no critic if ($@) { *capture = sub(&) { diag "START SUBTEST OUTPUT"; shift->(); diag "END SUBTEST OUTPUT"; return '(not captured)'; }; } } sub _unixify { ( my $path = shift ) =~ s{\\}{/}g; return $path; } # dogfood use Test::TempDir::Tiny; plan tests => 15; my $cwd = abs_path('.'); my $lib = abs_path('lib'); my $perl = abs_path($^X); # default directory my $dir = tempdir(); my $root = Test::TempDir::Tiny::_root_dir(); my $unix_root = _unixify($root); ok( -d $root, "root dir exists" ); like( _unixify($dir), qr{$unix_root/t_basic_t/default_1$}, "default directory created" ); my $dir2 = tempdir(); like( _unixify($dir2), qr{$unix_root/t_basic_t/default_2$}, "second default directory created" ); # non-word chars my $bang = tempdir("!!bang!!"); like( _unixify($bang), qr{$unix_root/t_basic_t/_bang__1$}, "!!bang!! directory created" ); # set up pass/fail dirs my $passing = _unixify( tempdir("passing") ); mkdir "$passing/t"; copy "corpus/01-pass.t", "$passing/t/01-pass.t"; like( _unixify($passing), qr{$unix_root/t_basic_t/passing_1$}, "passing directory created" ); my $failing = _unixify( tempdir("failing") ); mkdir "$failing/t"; copy "corpus/01-fail.t", "$failing/t/01-fail.t" or die $!; like( _unixify($failing), qr{$unix_root/t_basic_t/failing_1$}, "failing directory created" ); # passing chdir $passing; my ( $out, $err, $rc ) = capture { system( $perl, "-I$lib", qw/-MTest::Harness -e runtests(@ARGV)/, 't/01-pass.t' ) }; chdir $cwd; ok( !-d "$passing/tmp/t_01-pass_t", "passing test directory was cleaned up" ) or diag "OUT: $out"; ok( !-d "$passing/tmp", "passing root directory was cleaned up" ); # failing chdir $failing; ( $out, $err, $rc ) = capture { system( $perl, "-I$lib", qw/-MTest::Harness -e runtests(@ARGV)/, 't/01-fail.t' ) }; chdir $cwd; ok( -d "$failing/tmp/t_01-fail_t", "failing test directory was not cleaned up" ) or diag "OUT: $out"; ok( -d "$failing/tmp", "failing root directory was not cleaned up" ); # can't do some tests portably if Perl or lib has spaces in path if ( $perl !~ /\s/ && $lib !~ /\s/ ) { # test when not in dist directory with t my $without_t_dir = abs_path( File::Temp::tempdir( TMPDIR => 1, CLEANUP => 1 ) ); chdir $without_t_dir; my $tmpdir1 = qx/$perl -I$lib -MTest::TempDir::Tiny -wl -e print -e tempdir/; my $real_temp = _unixify( abs_path( File::Spec->tmpdir ) ); like( _unixify($tmpdir1), qr{^$real_temp}, "without t, tempdir is in File::Spec->tmpdir" ); # test when *inside* a t directory mkdir "t"; chdir "t"; my $tmpdir2 = qx/$perl -I$lib -MTest::TempDir::Tiny -wl -e print -e tempdir/; my $expect = _unixify( File::Spec->catdir( $without_t_dir, 'tmp' ) ); like( _unixify($tmpdir2), qr{^$expect}, "inside t, tempdir is in ../tmp" ); chdir $cwd; } # in_tempdir my $from_sub; in_tempdir "this is a test" => sub { my $arg = _unixify( shift @_ ); my $cur = _unixify( abs_path(".") ); is( $arg, $cur, "in_tempdir passes tempdir as argument" ); like( $cur, qr{$unix_root/t_basic_t/this_is_a_test_1}, "cwd is correct" ); }; is( abs_path("."), $cwd, "back to original dir after in_tempdir" ); # # This file is part of Test-TempDir-Tiny # # This software is Copyright (c) 2014 by David Golden. # # This is free software, licensed under: # # The Apache License, Version 2.0, January 2004 # # vim: ts=4 sts=4 sw=4 et: Test-TempDir-Tiny-0.010/t/taint.t000644 000765 000024 00000000271 12632600316 016714 0ustar00davidstaff000000 000000 #!perl -T use 5.006; use strict; use warnings; use Test::More; use Test::TempDir::Tiny; plan tests => 1; my $work_dir = tempdir(); ok(-d $work_dir, 'Check if directory is created'); Test-TempDir-Tiny-0.010/lib/Test/000755 000765 000024 00000000000 12632600316 016632 5ustar00davidstaff000000 000000 Test-TempDir-Tiny-0.010/lib/Test/TempDir/000755 000765 000024 00000000000 12632600316 020176 5ustar00davidstaff000000 000000 Test-TempDir-Tiny-0.010/lib/Test/TempDir/Tiny.pm000644 000765 000024 00000030473 12632600316 021466 0ustar00davidstaff000000 000000 use 5.008001; use strict; use warnings; package Test::TempDir::Tiny; # ABSTRACT: Temporary directories that stick around when tests fail our $VERSION = '0.010'; use Exporter 5.57 qw/import/; our @EXPORT = qw/tempdir in_tempdir/; use Carp qw/confess/; use Cwd qw/abs_path/; use Errno qw/EEXIST ENOENT/; { no warnings 'numeric'; # loading File::Path has non-numeric warnings on 5.8 use File::Path 2.01 qw/remove_tree/; } use File::Spec::Functions qw/catdir/; use File::Temp; my ( $ROOT_DIR, $TEST_DIR, %COUNTER ); my ( $ORIGINAL_PID, $ORIGINAL_CWD, $TRIES, $DELAY, $SYSTEM_TEMP ) = ( $$, abs_path("."), 100, 50 / 1000, 0 ); sub _untaint { my $thing = shift; ($thing) = $thing =~ /^(.*)$/; return $thing; } #pod =func tempdir #pod #pod $dir = tempdir(); # .../default_1/ #pod $dir = tempdir("label"); # .../label_1/ #pod #pod Creates a directory underneath a test-file-specific temporary directory and #pod returns the absolute path to it in platform-native form (i.e. with backslashes #pod on Windows). #pod #pod The function takes a single argument as a label for the directory or defaults #pod to "default". An incremental counter value will be appended to allow a label to #pod be used within a loop with distinct temporary directories: #pod #pod # t/foo.t #pod #pod for ( 1 .. 3 ) { #pod tempdir("in loop"); #pod } #pod #pod # creates: #pod # ./tmp/t_foo_t/in_loop_1 #pod # ./tmp/t_foo_t/in_loop_2 #pod # ./tmp/t_foo_t/in_loop_3 #pod #pod If the label contains any characters besides alphanumerics, underscore #pod and dash, they will be collapsed and replaced with a single underscore. #pod #pod $dir = tempdir("a space"); # .../a_space_1/ #pod $dir = tempdir("a!bang"); # .../a_bang_1/ #pod #pod The test-file-specific directory and all directories within it will be cleaned #pod up with an END block if the current test file passes tests. #pod #pod =cut sub tempdir { my $label = defined( $_[0] ) ? $_[0] : 'default'; $label =~ tr{a-zA-Z0-9_-}{_}cs; _init() unless $ROOT_DIR && $TEST_DIR; my $suffix = ++$COUNTER{$label}; my $subdir = catdir( $TEST_DIR, "${label}_${suffix}" ); mkdir _untaint($subdir) or confess("Couldn't create $subdir: $!"); return $subdir; } #pod =func in_tempdir #pod #pod in_tempdir "label becomes name" => sub { #pod my $cwd = shift; #pod # this happens in tempdir #pod }; #pod #pod Given a label and a code reference, creates a temporary directory based on the #pod label (following the rules of L), changes to that directory, runs the #pod code, then changes back to the original directory. #pod #pod The temporary directory path is given as an argument to the code reference. #pod #pod When the code finishes (even if it dies), C will change back to the #pod original directory if it can, to the root if it can't, and will rethrow any #pod fatal errors. #pod #pod =cut sub in_tempdir { my ( $label, $code ) = @_; my $wantarray = wantarray; my $cwd = abs_path("."); my $tempdir = tempdir($label); chdir $tempdir or die "Can't chdir to '$tempdir'"; my (@ret); my $ok = eval { $code->($tempdir); 1 }; my $err = $@; chdir $cwd or chdir "/" or die "Can't chdir to either '$cwd' or '/'"; confess( $err || "error from eval was lost" ) if !$ok; return; } sub _inside_t_dir { -d "../t" && abs_path(".") eq abs_path("../t"); } sub _init { my $DEFAULT_ROOT = catdir( $ORIGINAL_CWD, "tmp" ); if ( -d 't' && ( -w $DEFAULT_ROOT || -w '.' ) ) { $ROOT_DIR = $DEFAULT_ROOT; } elsif ( _inside_t_dir() && ( -w '../$DEFAULT_ROOT' || -w '..' ) ) { $ROOT_DIR = catdir( $ORIGINAL_CWD, "..", "tmp" ); } else { $ROOT_DIR = File::Temp::tempdir( TMPDIR => 1, CLEANUP => 1 ); $SYSTEM_TEMP = 1; } # TEST_DIR is based on .t path under ROOT_DIR ( my $dirname = $0 ) =~ tr{:\\/.}{_}; $TEST_DIR = catdir( $ROOT_DIR, $dirname ); # If it exists from a previous run, clear it out if ( -d $TEST_DIR ) { remove_tree( _untaint($TEST_DIR), { safe => 0, keep_root => 1 } ); return; } # Need to create directory, but constructing nested directories can never # be atomic, so we have to retry if the tempdir root gets deleted out from # under us (perhaps by a parallel test) for my $n ( 1 .. $TRIES ) { # Failing to mkdir is OK as long as error is EEXIST if ( !mkdir( _untaint($ROOT_DIR) ) ) { confess("Couldn't create $ROOT_DIR: $!") unless $! == EEXIST; } # Normalize after we know it exists, because abs_path might fail on # some platforms if it doesn't exist $ROOT_DIR = abs_path($ROOT_DIR); # If mkdir succeeds, we're done if ( mkdir _untaint($TEST_DIR) ) { # similarly normalize only after we're sure it exists $TEST_DIR = abs_path($TEST_DIR); return; } # Anything other than ENOENT is a real error if ( $! != ENOENT ) { confess("Couldn't create $TEST_DIR: $!"); } # ENOENT means $ROOT_DIR was removed from under us or is not a # directory. Only the latter case is a real error. if ( -e $ROOT_DIR && !-d _ ) { confess("$ROOT_DIR is not a directory"); } select( undef, undef, undef, $DELAY ) if $n < $TRIES; } warn "Couldn't create $TEST_DIR in $TRIES tries.\n" . "Using a regular tempdir instead.\n"; # Because fallback isn't under root, we let File::Temp clean it up. $TEST_DIR = File::Temp::tempdir( TMPDIR => 1, CLEANUP => 1 ); return; } # Relatively safe to untainted paths for these operations as they won't # be evaluated or passed to the shell. sub _cleanup { return if $ENV{PERL_TEST_TEMPDIR_TINY_NOCLEANUP}; if ( $ROOT_DIR && -d $ROOT_DIR ) { # always cleanup if root is in system temp directory, otherwise # only clean up if exiting with non-zero value if ( $SYSTEM_TEMP or not $? ) { chdir _untaint($ORIGINAL_CWD) or chdir "/" or warn "Can't chdir to '$ORIGINAL_CWD' or '/'. Cleanup might fail."; remove_tree( _untaint($TEST_DIR), { safe => 0 } ) if -d $TEST_DIR; } # Remove root unless it's a symlink, which a user might create to # force it to another drive. Removal will fail if there are any # children, but we ignore errors as other tests might be running # in parallel and have tempdirs there. rmdir _untaint($ROOT_DIR) unless -l $ROOT_DIR; } } # for testing sub _root_dir { return $ROOT_DIR } END { # only clean up in original process, not children if ( $$ == $ORIGINAL_PID ) { # our clean up must run after Test::More sets $? in its END block require B; push @{ B::end_av()->object_2svref }, \&_cleanup; } } 1; # vim: ts=4 sts=4 sw=4 et: __END__ =pod =encoding UTF-8 =head1 NAME Test::TempDir::Tiny - Temporary directories that stick around when tests fail =head1 VERSION version 0.010 =head1 SYNOPSIS # t/foo.t use Test::More; use Test::TempDir::Tiny; # default tempdirs $dir = tempdir(); # ./tmp/t_foo_t/default_1/ $dir = tempdir(); # ./tmp/t_foo_t/default_2/ # labeled tempdirs $dir = tempdir("label"); # ./tmp/t_foo_t/label_1/ $dir = tempdir("label"); # ./tmp/t_foo_t/label_2/ # labels with spaces and non-word characters $dir = tempdir("bar baz") # ./tmp/t_foo_t/bar_baz_1/ $dir = tempdir("!!!bang") # ./tmp/t_foo_t/_bang_1/ # run code in a temporary directory in_tempdir "label becomes name" => sub { my $cwd = shift; # do stuff in a tempdir }; =head1 DESCRIPTION This module works with L to create temporary directories that stick around if tests fail. It is loosely based on L, but with less complexity, greater portability and zero non-core dependencies. (L is recommended for testing.) The L and L functions are exported by default. If the current directory is writable, the root for directories will be F<./tmp>. Otherwise, a L directory will be created wherever temporary directories are stored for your system. Every F<*.t> file gets its own subdirectory under the root based on the test filename, but with slashes and periods replaced with underscores. For example, F would get a test-file-specific subdirectory F<./tmp/t_foo_t/>. Directories created by L get put in that directory. This makes it very easy to find files later if tests fail. The test-file-specific name is consistent from run-to-run. If an old directory already exists, it will be removed. 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 F<./tmp>, the test-file-specific directory sticks around for inspection. (But if the root is a L directory, it is always discarded). If nothing is left in F<./tmp> (i.e. no other test file failed), then F<./tmp> is cleaned up as well (unless it's a symlink). This module attempts to avoid race conditions due to parallel testing. In extreme cases, the test-file-specific subdirectory might be created as a regular L directory rather than in F<./tmp>. In such a case, a warning will be issued. =head1 FUNCTIONS =head2 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 in platform-native form (i.e. with backslashes on Windows). 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 collapsed and replaced with a single 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. =head2 in_tempdir in_tempdir "label becomes name" => sub { my $cwd = shift; # this happens in tempdir }; Given a label and a code reference, creates a temporary directory based on the label (following the rules of L), changes to that directory, runs the code, then changes back to the original directory. The temporary directory path is given as an argument to the code reference. When the code finishes (even if it dies), C will change back to the original directory if it can, to the root if it can't, and will rethrow any fatal errors. =head1 ENVIRONMENT =head2 C When this environment variable is true, directories will not be cleaned up, even if tests pass. =head1 SEE ALSO =over 4 =item * L =item * L =back =for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan =head1 SUPPORT =head2 Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at L. You will be notified automatically of any progress on your issue. =head2 Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. L git clone https://github.com/dagolden/Test-TempDir-Tiny.git =head1 AUTHOR David Golden =head1 CONTRIBUTORS =for stopwords Christian Walde David Golden Shawn Laffan =over 4 =item * Christian Walde =item * David Golden =item * Shawn Laffan =back =head1 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 =cut Test-TempDir-Tiny-0.010/corpus/01-fail.t000644 000765 000024 00000001400 12632600316 017771 0ustar00davidstaff000000 000000 use strict; use warnings; use Test::More; use Test::TempDir::Tiny; sub _unixify { (my $path = shift) =~ s{\\}{/}g; return $path; } my @cases = ( [ undef, 'default_1' ], [ 'label' => 'label_1' ], [ 'label' => 'label_2' ], [ 'with.*!$crud' => 'with_crud_1' ], ); plan tests => 1 + @cases; for my $c (@cases) { my ( $input, $dir ) = @$c; my $got = tempdir($input); my $expect = "t_01-fail_t/$dir"; like( _unixify($got), qr/\Q$expect\E$/, "$dir" ); } fail("just give up already, OK"); # # This file is part of Test-TempDir-Tiny # # This software is Copyright (c) 2014 by David Golden. # # This is free software, licensed under: # # The Apache License, Version 2.0, January 2004 # # vim: ts=4 sts=4 sw=4 et: Test-TempDir-Tiny-0.010/corpus/01-pass.t000644 000765 000024 00000001340 12632600316 020027 0ustar00davidstaff000000 000000 use strict; use warnings; use Test::More; use Test::TempDir::Tiny; sub _unixify { (my $path = shift) =~ s{\\}{/}g; return $path; } my @cases = ( [ undef, 'default_1' ], [ 'label' => 'label_1' ], [ 'label' => 'label_2' ], [ 'with.*!$crud' => 'with_crud_1' ], ); plan tests => scalar @cases; for my $c (@cases) { my ( $input, $dir ) = @$c; my $got = tempdir($input); my $expect = "t_01-pass_t/$dir"; like( _unixify($got), qr/\Q$expect\E$/, "$dir" ); } # # This file is part of Test-TempDir-Tiny # # This software is Copyright (c) 2014 by David Golden. # # This is free software, licensed under: # # The Apache License, Version 2.0, January 2004 # # vim: ts=4 sts=4 sw=4 et: