From: Matt S Trout Date: Sun, 15 Jul 2012 21:50:15 +0000 (+0000) Subject: factor test setup code into a module X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FApp-EzPz.git;a=commitdiff_plain;h=6b4ac75f6057d5775e1380ac845b602bef755cba factor test setup code into a module --- diff --git a/bin/ezpz-create-test-ezmlm-list b/bin/ezpz-create-test-ezmlm-list index 972b3ca..8e0cb5b 100755 --- a/bin/ezpz-create-test-ezmlm-list +++ b/bin/ezpz-create-test-ezmlm-list @@ -1,23 +1,7 @@ #!/usr/bin/env perl use lib (-d 'lib' ? ('lib') : ()); -use IO::All; -use IPC::System::Simple qw(run); +use App::EzPz::TestSetup; use strictures 1; -die "Usage: ezpz-create-test-ezmlm-list ezmlm-bindir list-base-dir list-name" - unless @ARGV == 3; - -my ($ezmlm_bin_path, $list_base_path, $list_name) = @ARGV; - -my $ezmlm_bin = io->dir($ezmlm_bin_path)->absolute; - -my $list_base = io->dir($list_base_path)->absolute; - -run( - $ezmlm_bin->catfile('ezmlm-make'), - $list_base->catdir($list_name), - $list_base->catfile("dot-qmail-for-${list_name}"), - $list_name, - 'example.com' -); +create_list(@ARGV); diff --git a/lib/App/EzPz/TestSetup.pm b/lib/App/EzPz/TestSetup.pm new file mode 100644 index 0000000..4cd3552 --- /dev/null +++ b/lib/App/EzPz/TestSetup.pm @@ -0,0 +1,65 @@ +package App::EzPz::TestSetup; + +use IO::All; +use IPC::System::Simple qw(run); +use Cwd; +use Exporter; +use strictures 1; + +our @EXPORT = qw(create_install create_list); + +sub create_install { + die "Usage: ezpz-create-test-ezmlm-install ezmlm-source.tgz build-dir install-dir" + unless @_ == 3; + + my ($ezmlm_tarball_path, $build_dir_path, $install_to_path) = @ARGV; + + my $ezmlm_tarball = io->file(io->file($ezmlm_tarball_path)->rel2abs); + + my $orig_cwd = io->dir(cwd); + + my $build_dir = io->dir($build_dir_path)->absolute; + my $install_to = io->dir($install_to_path)->absolute; + + unless ($build_dir->exists) { + $build_dir->mkpath; + $build_dir->chdir; + run 'tar', 'xzf', $ezmlm_tarball; + $orig_cwd->chdir; + } + + my ($src_dir) = ($build_dir->all_dirs)[0]; + + die "No source dir found in ${build_dir}" unless $src_dir; + + foreach my $type (qw(bin etc lib man qmail)) { + $src_dir->catfile("conf-${type}")->print($install_to->catdir($type)."\n"); + } + + $src_dir->chdir; + + run make => 'clean'; + run 'make'; + run make => 'man'; + run './ezmlm-test'; + $install_to->catdir('bin')->mkpath; + run make => 'install'; +} + +sub create_list { + die "Usage: ezpz-create-test-ezmlm-list ezmlm-bindir list-base-dir list-name" + unless @_ == 3; + + my ($ezmlm_bin_path, $list_base_path, $list_name) = @_; + + my $ezmlm_bin = io->dir($ezmlm_bin_path)->absolute; + + my $list_base = io->dir($list_base_path)->absolute; + + run( + $ezmlm_bin->catfile('ezmlm-make'), + $list_base->catdir($list_name), + $list_base->catfile("dot-qmail-for-${list_name}"), + $list_name, + 'example.com' + );