diff --git a/Changes b/Changes new file mode 100644 index 0000000..c2e8eed --- /dev/null +++ b/Changes @@ -0,0 +1,4 @@ +Revision history for Perl extension Test-InDistDir + +1.112071 2011-07-26 19:46:24 Europe/Berlin + - original version diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..66fc177 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +This software is Copyright (c) 2011 by Christian Walde. + +This is free software, licensed under: + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE, Version 2, December 2004 + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2004 Sam Hocevar + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..3d792cf --- /dev/null +++ b/MANIFEST @@ -0,0 +1,17 @@ +Changes +LICENSE +MANIFEST +META.json +META.yml +Makefile.PL +README.mkdn +dist.ini +lib/Test/InDistDir.pm +t/00-compile.t +t/basic.t +xt/release/distmeta.t +xt/release/kwalitee.t +xt/release/pod-coverage.t +xt/release/pod-syntax.t +xt/release/portability.t +xt/release/test-version.t diff --git a/META.json b/META.json new file mode 100644 index 0000000..6eda4cd --- /dev/null +++ b/META.json @@ -0,0 +1,68 @@ +{ + "abstract" : "test environment setup for development with IDE", + "author" : [ + "Christian Walde " + ], + "dynamic_config" : 0, + "generated_by" : "Dist::Zilla version 4.200013, CPAN::Meta::Converter version 2.110930", + "license" : [ + "unrestricted" + ], + "meta-spec" : { + "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", + "version" : "2" + }, + "name" : "Test-InDistDir", + "no_index" : { + "directory" : [ + "t", + "xt", + "examples", + "corpus" + ], + "package" : [ + "DB" + ] + }, + "prereqs" : { + "configure" : { + "requires" : { + "ExtUtils::MakeMaker" : "6.30" + } + }, + "runtime" : { + "requires" : { + "File::Spec" : 0, + "perl" : "5.006" + } + }, + "test" : { + "requires" : { + "File::Find" : 0, + "File::Temp" : 0, + "Test::More" : 0 + } + } + }, + "provides" : { + "Test::InDistDir" : { + "file" : "lib/Test/InDistDir.pm", + "version" : "1.112071" + } + }, + "release_status" : "stable", + "resources" : { + "bugtracker" : { + "mailto" : "bug-test-indistdir at rt.cpan.org", + "web" : "http://rt.cpan.org/Public/Dist/Display.html?Name=Test-InDistDir" + }, + "homepage" : "https://github.com/wchristian/Test-InDistDir", + "repository" : { + "type" : "git", + "url" : "https://github.com/wchristian/Test-InDistDir", + "web" : "https://github.com/wchristian/Test-InDistDir" + } + }, + "version" : "1.112071" +} + diff --git a/META.yml b/META.yml new file mode 100644 index 0000000..9cba918 --- /dev/null +++ b/META.yml @@ -0,0 +1,37 @@ +--- +abstract: 'test environment setup for development with IDE' +author: + - 'Christian Walde ' +build_requires: + File::Find: 0 + File::Temp: 0 + Test::More: 0 +configure_requires: + ExtUtils::MakeMaker: 6.30 +dynamic_config: 0 +generated_by: 'Dist::Zilla version 4.200013, CPAN::Meta::Converter version 2.110930' +license: unrestricted +meta-spec: + url: http://module-build.sourceforge.net/META-spec-v1.4.html + version: 1.4 +name: Test-InDistDir +no_index: + directory: + - t + - xt + - examples + - corpus + package: + - DB +provides: + Test::InDistDir: + file: lib/Test/InDistDir.pm + version: 1.112071 +requires: + File::Spec: 0 + perl: 5.006 +resources: + bugtracker: http://rt.cpan.org/Public/Dist/Display.html?Name=Test-InDistDir + homepage: https://github.com/wchristian/Test-InDistDir + repository: https://github.com/wchristian/Test-InDistDir +version: 1.112071 diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..7951aa8 --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,55 @@ + +use strict; +use warnings; + +use 5.006; + +use ExtUtils::MakeMaker 6.30; + + + +my %WriteMakefileArgs = ( + 'ABSTRACT' => 'test environment setup for development with IDE', + 'AUTHOR' => 'Christian Walde ', + 'BUILD_REQUIRES' => { + 'File::Find' => '0', + 'File::Temp' => '0', + 'Test::More' => '0' + }, + 'CONFIGURE_REQUIRES' => { + 'ExtUtils::MakeMaker' => '6.30' + }, + 'DISTNAME' => 'Test-InDistDir', + 'EXE_FILES' => [], + 'LICENSE' => 'unrestricted', + 'NAME' => 'Test::InDistDir', + 'PREREQ_PM' => { + 'File::Spec' => '0' + }, + 'VERSION' => '1.112071', + 'test' => { + 'TESTS' => 't/*.t' + } +); + + +unless ( eval { ExtUtils::MakeMaker->VERSION(6.56) } ) { + my $br = delete $WriteMakefileArgs{BUILD_REQUIRES}; + my $pp = $WriteMakefileArgs{PREREQ_PM}; + for my $mod ( keys %$br ) { + if ( exists $pp->{$mod} ) { + $pp->{$mod} = $br->{$mod} if $br->{$mod} > $pp->{$mod}; + } + else { + $pp->{$mod} = $br->{$mod}; + } + } +} + +delete $WriteMakefileArgs{CONFIGURE_REQUIRES} + unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; + +WriteMakefile(%WriteMakefileArgs); + + + diff --git a/README.mkdn b/README.mkdn new file mode 100644 index 0000000..a4a4087 --- /dev/null +++ b/README.mkdn @@ -0,0 +1,63 @@ +# NAME + +Test::InDistDir - test environment setup for development with IDE + +# VERSION + +version 1.112071 + +# SYNOPSIS + + use Test::More; + use Test::InDistDir; + + # when this is run from inside t/ with a default @INC, it will now be in the + # dist dir and include ./lib in @INC + +# DESCRIPTION + +This module helps run test scripts in IDEs like Komodo. + +When running test scripts in an IDE i have to set up a project file defining the +dist dir to run tests in and a lib dir to load additional modules from. Often I +didn't feel like doing that, especially when i only wanted to do a small patch +to a dist. In those cases i added a BEGIN block to mangle the environment for +me. + +This module basically is that BEGIN block. It automatically moves up one +directory when it cannot see the test script in "t/$scriptname" and includes +'lib' in @INC when there's no blib present. That way the test ends up with +almost the same environment it'd get from EUMM/prove/etc., even when it's +actually run inside the t/ directory. + +At the same time it will still function correctly when called by +EUMM/prove/etc., since it does not change the environment in those cases. + +# SUPPORT + +## Bugs / Feature Requests + +Please report any bugs or feature requests by email to `bug-test-indistdir at rt.cpan.org`, or through +the web interface at [http://rt.cpan.org/Public/Dist/Display.html?Name=Test-InDistDir](http://rt.cpan.org/Public/Dist/Display.html?Name=Test-InDistDir). You will be automatically notified of any +progress on the request by the system. + +## Source Code + +This is open source software. The code repository is available for +public review and contribution under the terms of the license. + +[https://github.com/wchristian/Test-InDistDir](https://github.com/wchristian/Test-InDistDir) + + git clone https://github.com/wchristian/Test-InDistDir + +# AUTHOR + +Christian Walde + +# COPYRIGHT AND LICENSE + +This software is Copyright (c) 2011 by Christian Walde. + +This is free software, licensed under: + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE, Version 2, December 2004 \ No newline at end of file diff --git a/dist.ini b/dist.ini new file mode 100644 index 0000000..415db74 --- /dev/null +++ b/dist.ini @@ -0,0 +1,89 @@ +name = Test-InDistDir +author = Christian Walde +license = WTFPL_2 +copyright_holder = Christian Walde +copyright_year = 2011 + +; version provider +[AutoVersion] ; builds a version automatically from the date + +; choose files to include +[GatherDir] ; everything under top dir +[PruneCruft] ; default stuff to skip +[ManifestSkip] ; if -f MANIFEST.SKIP, skip those, too + +; file modifications +[OurPkgVersion] ; add $VERSION = ... to all files +[PodWeaver] ; generate Pod +config_plugin = @DAGOLDEN ; my own plugin allows Pod::WikiDoc + +; generated files +[License] ; boilerplate license +[ReadmeMarkdownFromPod] ; from Pod (runs after PodWeaver) +[CopyReadmeFromBuild] ; for the repo + +; t tests +[CompileTests] ; make sure .pm files all compile +fake_home = 1 ; fakes $ENV{HOME} just in case + +; xt tests +[MetaTests] ; xt/release/meta-yaml.t +[PodSyntaxTests] ; xt/release/pod-syntax.t +[PodCoverageTests] ; xt/release/pod-coverage.t +[PortabilityTests] ; xt/release/portability.t (of file name) +[KwaliteeTests] ; xt/release/kwalitee.t +[Test::Version] ; xt/release/test-version.t + +; metadata +[AutoPrereqs] ; find prereqs from code +[MinimumPerl] ; determine minimum perl version +[GithubMeta] + +[MetaNoIndex] ; sets 'no_index' in META +directory = t +directory = xt +directory = examples +directory = corpus +package = DB ; just in case + +[Bugtracker] ; defaults to RT + +[MetaProvides::Package] ; add 'provides' to META files +meta_noindex = 1 ; respect prior no_index directives + +[MetaYAML] ; generate META.yml (v1.4) +[MetaJSON] ; generate META.json (v2) + +; build system +[ExecDir] ; include 'bin/*' as executables +[ShareDir] ; include 'share/' for File::ShareDir +[MakeMaker] ; create Makefile.PL + +; manifest (after all generated files) +[Manifest] ; create MANIFEST + +; before release +[Git::Check] ; ensure all files checked in +allow_dirty = README.mkdn + +[CheckPrereqsIndexed] ; ensure prereqs are on CPAN +[CheckChangesHasContent] ; ensure Changes has been updated +[CheckExtraTests] ; ensure xt/ tests pass +[TestRelease] ; ensure t/ tests pass +[ConfirmRelease] ; prompt before uploading + +; releaser +[UploadToCPAN] ; uploads to CPAN + +; after release +[NextRelease] + +[Git::Commit] +allow_dirty = Changes +allow_dirty = README.mkdn + +[Git::Tag] ; tag repo with custom tag +tag_format = release-%v + +[Git::Push] ; push repo to remote +push_to = origin diff --git a/lib/Test/InDistDir.pm b/lib/Test/InDistDir.pm new file mode 100644 index 0000000..f3dcd1e --- /dev/null +++ b/lib/Test/InDistDir.pm @@ -0,0 +1,93 @@ +use strict; +use warnings; +package Test::InDistDir; + +our $VERSION = '1.112071'; # VERSION +# ABSTRACT: test environment setup for development with IDE + + +use lib; +use File::Spec; + +sub import { + my $script = ( File::Spec->splitpath( $0 ) )[-1]; + + chdir ".." if !-f "t/$script"; + lib->import( 'lib' ) if !grep { /\bblib\b/ } @INC; + + return; +} + +1; + +__END__ +=pod + +=head1 NAME + +Test::InDistDir - test environment setup for development with IDE + +=head1 VERSION + +version 1.112071 + +=head1 SYNOPSIS + + use Test::More; + use Test::InDistDir; + + # when this is run from inside t/ with a default @INC, it will now be in the + # dist dir and include ./lib in @INC + +=head1 DESCRIPTION + +This module helps run test scripts in IDEs like Komodo. + +When running test scripts in an IDE i have to set up a project file defining the +dist dir to run tests in and a lib dir to load additional modules from. Often I +didn't feel like doing that, especially when i only wanted to do a small patch +to a dist. In those cases i added a BEGIN block to mangle the environment for +me. + +This module basically is that BEGIN block. It automatically moves up one +directory when it cannot see the test script in "t/$scriptname" and includes +'lib' in @INC when there's no blib present. That way the test ends up with +almost the same environment it'd get from EUMM/prove/etc., even when it's +actually run inside the t/ directory. + +At the same time it will still function correctly when called by +EUMM/prove/etc., since it does not change the environment in those cases. + +=for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders + +=head1 SUPPORT + +=head2 Bugs / Feature Requests + +Please report any bugs or feature requests by email to C, or through +the web interface at L. You will be automatically notified of any +progress on the request by the system. + +=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/wchristian/Test-InDistDir + +=head1 AUTHOR + +Christian Walde + +=head1 COPYRIGHT AND LICENSE + +This software is Copyright (c) 2011 by Christian Walde. + +This is free software, licensed under: + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE, Version 2, December 2004 + +=cut + diff --git a/t/00-compile.t b/t/00-compile.t new file mode 100644 index 0000000..6ce3690 --- /dev/null +++ b/t/00-compile.t @@ -0,0 +1,59 @@ +#!perl + +use strict; +use warnings; + +use Test::More; + + + +use File::Find; +use File::Temp qw{ tempdir }; + +my @modules; +find( + sub { + return if $File::Find::name !~ /\.pm\z/; + my $found = $File::Find::name; + $found =~ s{^lib/}{}; + $found =~ s{[/\\]}{::}g; + $found =~ s/\.pm$//; + # nothing to skip + push @modules, $found; + }, + 'lib', +); + +my @scripts; +if ( -d 'bin' ) { + find( + sub { + return unless -f; + my $found = $File::Find::name; + # nothing to skip + push @scripts, $found; + }, + 'bin', + ); +} + +my $plan = scalar(@modules) + scalar(@scripts); +$plan ? (plan tests => $plan) : (plan skip_all => "no tests to run"); + +{ + # fake home for cpan-testers + local $ENV{HOME} = tempdir( CLEANUP => 1 ); + + like( qx{ $^X -Ilib -e "require $_; print '$_ ok'" }, qr/^\s*$_ ok/s, "$_ loaded ok" ) + for sort @modules; + + SKIP: { + eval "use Test::Script 1.05; 1;"; + skip "Test::Script needed to test script compilation", scalar(@scripts) if $@; + foreach my $file ( @scripts ) { + my $script = $file; + $script =~ s!.*/!!; + script_compiles( $file, "$script script compiles" ); + } + } +} diff --git a/t/basic.t b/t/basic.t new file mode 100644 index 0000000..169c2db --- /dev/null +++ b/t/basic.t @@ -0,0 +1,23 @@ +use strict; +use warnings; +package basic; + +use Test::More; +use File::Spec; + +require_ok("Test::InDistDir"); +can_ok( "Test::InDistDir", "import" ); + +chdir "t" if -d "t"; +@INC = grep { !/\bblib\b/ and !/\blib\b/ } @INC; + +my $script = ( File::Spec->splitpath( $0 ) )[-1]; + +ok( !-f "t/$script", "test script not visible" ); + +Test::InDistDir->import; + +ok( -f "t/$script", "we moved up one directory, so test script is visible" ); +ok( scalar( grep { /\blib\b/ } @INC ), "lib was added to INC" ); + +done_testing; diff --git a/xt/release/distmeta.t b/xt/release/distmeta.t new file mode 100644 index 0000000..b46c7fc --- /dev/null +++ b/xt/release/distmeta.t @@ -0,0 +1,7 @@ +#!perl + +use Test::More; + +eval "use Test::CPAN::Meta"; +plan skip_all => "Test::CPAN::Meta required for testing META.yml" if $@; +meta_yaml_ok(); diff --git a/xt/release/kwalitee.t b/xt/release/kwalitee.t new file mode 100644 index 0000000..d4651a7 --- /dev/null +++ b/xt/release/kwalitee.t @@ -0,0 +1,8 @@ +#!perl + +use Test::More; + +eval "use Test::Kwalitee"; +plan skip_all => "Test::Kwalitee required for testing kwalitee" + if $@; + diff --git a/xt/release/pod-coverage.t b/xt/release/pod-coverage.t new file mode 100644 index 0000000..b52218b --- /dev/null +++ b/xt/release/pod-coverage.t @@ -0,0 +1,13 @@ +#!perl + +use Test::More; + +eval "use Test::Pod::Coverage 1.08"; +plan skip_all => "Test::Pod::Coverage 1.08 required for testing POD coverage" + if $@; + +eval "use Pod::Coverage::TrustPod"; +plan skip_all => "Pod::Coverage::TrustPod required for testing POD coverage" + if $@; + +all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' }); diff --git a/xt/release/pod-syntax.t b/xt/release/pod-syntax.t new file mode 100644 index 0000000..8a22900 --- /dev/null +++ b/xt/release/pod-syntax.t @@ -0,0 +1,7 @@ +#!perl +use Test::More; + +eval "use Test::Pod 1.41"; +plan skip_all => "Test::Pod 1.41 required for testing POD" if $@; + +all_pod_files_ok(); diff --git a/xt/release/portability.t b/xt/release/portability.t new file mode 100644 index 0000000..e57e66e --- /dev/null +++ b/xt/release/portability.t @@ -0,0 +1,8 @@ +#!perl + +use Test::More; + +eval "use Test::Portability::Files"; +plan skip_all => "Test::Portability::Files required for testing portability" + if $@; +run_tests(); diff --git a/xt/release/test-version.t b/xt/release/test-version.t new file mode 100644 index 0000000..b5b6f14 --- /dev/null +++ b/xt/release/test-version.t @@ -0,0 +1,12 @@ +#!/usr/bin/perl +use 5.006; +use strict; +use warnings; +use Test::More; + +eval "use Test::Version 0.04"; +plan skip_all => "Test::Version 0.04 required for testing versions" + if $@; + +version_all_ok(); +done_testing;