Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: https://cle.sk/repos/pub/cpan/Test-Environment/trunk@167 b0c1b02c-7ba7-4df7-b273-855bf36df2ab
- Loading branch information
jk
committed
Oct 13, 2007
0 parents
commit 7c0818c
Showing
13 changed files
with
367 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Revision history for Perl extension Test::Environment. | ||
|
||
0.01 Fri Oct 12 17:31:21 2007 | ||
- initial version | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Changes | ||
Makefile.PL | ||
MANIFEST | ||
README | ||
t/00_distribution.t | ||
t/00_signature.t | ||
t/01_Test-Environment.t | ||
t/02_Test-Environment-Plugin-PostreSQL.t | ||
lib/Test/Environment.pm | ||
lib/Test/Environment/Plugin/PostgreSQL.pm | ||
lib/Test/Environment/Plugin/Dump.pm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use 5.006; | ||
use ExtUtils::MakeMaker; | ||
|
||
WriteMakefile( | ||
NAME => 'Test::Environment', | ||
VERSION_FROM => 'lib/Test/Environment.pm', # finds $VERSION | ||
PREREQ_PM => { | ||
Carp::Clan => 0, | ||
Test::More => 0, | ||
}, | ||
($] >= 5.005 ? ## Add these new keywords supported since 5.005 | ||
(ABSTRACT_FROM => 'lib/Test/Environment.pm', # retrieve abstract from module | ||
AUTHOR => 'Jozef Kutej <jozef@kutej.net>') : ()), | ||
(MM->can('signature_target') ? (SIGN => 1) : ()), | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
Test-Environment version 0.01 | ||
============================= | ||
|
||
The README is used to introduce the module and provide instructions on | ||
how to install the module, any machine dependencies it may have (for | ||
example C compilers and installed libraries) and any other information | ||
that should be provided before the module is installed. | ||
|
||
A README file is required for CPAN modules since CPAN extracts the | ||
README file from a module distribution so that people browsing the | ||
archive can use it get an idea of the modules uses. It is usually a | ||
good idea to provide version information here so that people can | ||
decide whether fixes for the module are worth downloading. | ||
|
||
INSTALLATION | ||
|
||
To install this module type the following: | ||
|
||
perl Makefile.PL | ||
make | ||
make test | ||
make install | ||
|
||
DEPENDENCIES | ||
|
||
see Makefile.PL | ||
|
||
COPYRIGHT AND LICENCE | ||
|
||
Put the correct copyright and licence information here. | ||
|
||
Copyright (C) 2007 by Jozef Kutej | ||
|
||
This library is free software; you can redistribute it and/or modify | ||
it under the same terms as Perl itself, either Perl version 5.8.8 or, | ||
at your option, any later version of Perl 5 you may have available. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package Test::Environment; | ||
|
||
=head1 NAME | ||
Test::Environment - | ||
=cut | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Carp::Clan; | ||
use English '-no_match_vars'; | ||
use File::Basename; | ||
|
||
BEGIN { | ||
$ENV{'RUNNING_ENVIRONMENT'} = 'testing'; | ||
} | ||
|
||
=head2 import() | ||
=cut | ||
|
||
sub import { | ||
my $package = shift; | ||
my @args = @_; | ||
|
||
foreach my $plugin_name (@args) { | ||
croak 'bad plugin name' if $plugin_name !~ m{^\w+(::\w+)*$}xms; | ||
|
||
my $plugin_module_name = 'Test::Environment::Plugin::'.$plugin_name; | ||
eval 'use '.$plugin_module_name.';'; | ||
if ($EVAL_ERROR) { | ||
croak 'Failed to load "'.$plugin_module_name.'" - '.$EVAL_ERROR; | ||
} | ||
} | ||
} | ||
|
||
1; | ||
|
||
|
||
=head1 AUTHOR | ||
Jozef Kutej, E<lt>jk@E<gt> | ||
=head1 COPYRIGHT AND LICENSE | ||
Copyright (C) 2007 by Jozef Kutej | ||
This library is free software; you can redistribute it and/or modify | ||
it under the same terms as Perl itself, either Perl version 5.8.8 or, | ||
at your option, any later version of Perl 5 you may have available. | ||
=cut |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package Test::Environment::Plugin::Dump; | ||
|
||
=head1 NAME | ||
Test::Environment::Plugin::Dump - | ||
=cut | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use base qw{ Exporter }; | ||
our @EXPORT = qw{ | ||
dump_with_name | ||
}; | ||
|
||
use Carp::Clan; | ||
use File::Slurp; | ||
|
||
|
||
sub import { | ||
my $package = shift; | ||
|
||
# export symbols two levels up - to the Test::Environment caller | ||
__PACKAGE__->export_to_level(2, $package, @EXPORT); | ||
} | ||
|
||
|
||
our $dumps_folder = $FindBin::Bin.'/dumps'; | ||
sub dump_with_name { | ||
my $name = shift; | ||
|
||
croak 'please set dump name' if not defined $name; | ||
|
||
return read_file($dumps_folder.'/'.$name); | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package Test::Environment::Plugin::PostgreSQL; | ||
|
||
=head1 NAME | ||
Test::Environment::Plugin::PostgreSQL - | ||
=cut | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use base qw{ Exporter }; | ||
our @EXPORT = qw{ | ||
psql | ||
}; | ||
|
||
use Carp::Clan; | ||
|
||
sub import { | ||
my $package = shift; | ||
|
||
# export symbols two levels up - to the Test::Environment caller | ||
__PACKAGE__->export_to_level(2, $package, @EXPORT); | ||
} | ||
|
||
|
||
# let the psql command be executed easily | ||
sub psql { | ||
my %arg = @_; | ||
|
||
$ENV{'PGUSER'} = $arg{'username'} if exists $arg{'username'}; | ||
$ENV{'PGPASSWORD'} = $arg{'password'} if exists $arg{'password'}; | ||
$ENV{'PGDATABASE'} = $arg{'database'} if exists $arg{'database'}; | ||
$ENV{'PGHOST'} = $arg{'hostname'} if exists $arg{'hostname'}; | ||
$ENV{'PGPORT'} = $arg{'port'} if exists $arg{'port'}; | ||
|
||
# function paramaters | ||
my $command = $arg{'command'}; | ||
my $output_filename = $arg{'output_filename'}; | ||
my $execution_path = $arg{'execution_path'}; | ||
my $stderr_redirect = $arg{'stderr_redirect'}; | ||
my $egrep = $arg{'egrep'}; | ||
my $invert_match = $arg{'invert_match'}; | ||
|
||
# if there is no command return nothink to do more | ||
return if not defined $command; | ||
|
||
# if more commands then join them together | ||
if (ref $command eq 'ARRAY') { | ||
$command = join '; ', @{$command}; | ||
} | ||
$command .= ';' if ($command !~ m{;\s*$}xms); | ||
|
||
|
||
my @additional_parameters; | ||
if (defined $output_filename) { | ||
push(@additional_parameters, '-o', '"'.$output_filename.'"') | ||
} | ||
|
||
if (defined $stderr_redirect) { | ||
push(@additional_parameters, '2>'.$stderr_redirect) | ||
} | ||
|
||
if (defined $egrep) { | ||
push(@additional_parameters, | ||
'|', | ||
'grep', | ||
'-E', | ||
); | ||
push(@additional_parameters, '-v') if $invert_match; | ||
push(@additional_parameters, '"'.$egrep.'"'); | ||
} | ||
|
||
my @pre_parameters; | ||
if (defined $execution_path) { | ||
push(@pre_parameters, | ||
'cd', | ||
'"'.$execution_path.'"', | ||
';', | ||
); | ||
} | ||
|
||
#construct command, print and execute it then | ||
my @cmd = ( | ||
@pre_parameters, | ||
'psql', | ||
'-c', | ||
'"'.$command.'"', | ||
@additional_parameters, | ||
); | ||
my $cmd = join(' ', @cmd); | ||
print 'executing: ', $cmd, "\n"; | ||
my @ret = `$cmd`; | ||
|
||
return join('', @ret); | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
use Test::More; | ||
|
||
eval 'use Test::Distribution not => "sig"'; | ||
plan( skip_all => 'Test::Distribution not installed') if $@; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/perl | ||
|
||
use strict; | ||
use Test::More; | ||
|
||
if (!$ENV{TEST_SIGNATURE}) { | ||
plan skip_all => | ||
"Set the environment variable TEST_SIGNATURE to enable this test."; | ||
} | ||
elsif (!eval { require Module::Signature; 1 }) { | ||
plan skip_all => | ||
"Next time around, consider installing Module::Signature, ". | ||
"so you can verify the integrity of this distribution."; | ||
} | ||
elsif ( !-e 'SIGNATURE' ) { | ||
plan skip_all => "SIGNATURE not found"; | ||
} | ||
elsif ( -s 'SIGNATURE' == 0 ) { | ||
plan skip_all => "SIGNATURE file empty"; | ||
} | ||
elsif (!eval { require Socket; Socket::inet_aton('pgp.mit.edu') }) { | ||
plan skip_all => "Cannot connect to the keyserver to check module ". | ||
"signature"; | ||
} | ||
else { | ||
plan tests => 1; | ||
} | ||
|
||
my $ret = Module::Signature::verify(); | ||
SKIP: { | ||
skip "Module::Signature cannot verify", 1 | ||
if $ret eq Module::Signature::CANNOT_VERIFY(); | ||
|
||
cmp_ok $ret, '==', Module::Signature::SIGNATURE_OK(), "Valid signature"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Test::More; # 'no_plan'; | ||
BEGIN { plan tests => 2 }; | ||
|
||
BEGIN { use_ok 'Test::Environment' } | ||
|
||
is($ENV{'RUNNING_ENVIRONMENT'}, 'testing', 'check RUNNING_ENVIRONMENT environmental variable'); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Test::More; # 'no_plan'; | ||
BEGIN { plan tests => 3 }; | ||
|
||
use English '-no_match_vars'; | ||
|
||
BEGIN { | ||
use_ok 'Test::Environment', qw{ | ||
PostgreSQL | ||
}; | ||
} | ||
|
||
my $username = 'user1'; | ||
my $password = 'pass1'; | ||
|
||
psql( | ||
'username' => $username, | ||
'password' => $password, | ||
); | ||
|
||
is($ENV{'PGUSER'}, $username, 'check if psql set the postres PGUSER'); | ||
is($ENV{'PGPASSWORD'}, $password, 'check if psql set the postres PGPASSWORD'); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Test::More; # 'no_plan'; | ||
BEGIN { plan tests => 3 }; | ||
use Test::Differences; | ||
|
||
use English '-no_match_vars'; | ||
use File::Slurp 'read_file'; | ||
use FindBin; | ||
|
||
BEGIN { | ||
use_ok 'Test::Environment', qw{ | ||
Dump | ||
}; | ||
} | ||
|
||
my @dump = dump_with_name('dump01.txt'); | ||
|
||
eq_or_diff(\@dump, [ read_file($FindBin::Bin.'/dumps/dump01.txt') ], 'check reading of dump01.txt in array context'); | ||
eq_or_diff(join('', @dump), scalar read_file($FindBin::Bin.'/dumps/dump01.txt') , 'check reading of dump01.txt in scalar context'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Hell world! | ||
Everyone. |