factor test setup code into a module
[scpubgit/App-EzPz.git] / lib / App / EzPz / TestSetup.pm
1 package App::EzPz::TestSetup;
2
3 use IO::All;
4 use IPC::System::Simple qw(run);
5 use Cwd;
6 use Exporter;
7 use strictures 1;
8
9 our @EXPORT = qw(create_install create_list);
10
11 sub create_install {
12   die "Usage: ezpz-create-test-ezmlm-install ezmlm-source.tgz build-dir install-dir"
13     unless @_ == 3;
14   
15   my ($ezmlm_tarball_path, $build_dir_path, $install_to_path) = @ARGV;
16   
17   my $ezmlm_tarball = io->file(io->file($ezmlm_tarball_path)->rel2abs);
18   
19   my $orig_cwd = io->dir(cwd);
20   
21   my $build_dir = io->dir($build_dir_path)->absolute;
22   my $install_to = io->dir($install_to_path)->absolute;
23   
24   unless ($build_dir->exists) {
25     $build_dir->mkpath;
26     $build_dir->chdir;
27     run 'tar', 'xzf', $ezmlm_tarball;
28     $orig_cwd->chdir;
29   }
30   
31   my ($src_dir) = ($build_dir->all_dirs)[0];
32   
33   die "No source dir found in ${build_dir}" unless $src_dir;
34   
35   foreach my $type (qw(bin etc lib man qmail)) {
36     $src_dir->catfile("conf-${type}")->print($install_to->catdir($type)."\n");
37   }
38   
39   $src_dir->chdir;
40   
41   run make => 'clean';
42   run 'make';
43   run make => 'man';
44   run './ezmlm-test';
45   $install_to->catdir('bin')->mkpath;
46   run make => 'install';
47 }
48
49 sub create_list {
50   die "Usage: ezpz-create-test-ezmlm-list ezmlm-bindir list-base-dir list-name"
51     unless @_ == 3;
52   
53   my ($ezmlm_bin_path, $list_base_path, $list_name) = @_;
54   
55   my $ezmlm_bin = io->dir($ezmlm_bin_path)->absolute;
56   
57   my $list_base = io->dir($list_base_path)->absolute;
58   
59   run(
60     $ezmlm_bin->catfile('ezmlm-make'),
61     $list_base->catdir($list_name),
62     $list_base->catfile("dot-qmail-for-${list_name}"),
63     $list_name,
64     'example.com'
65   );