]> git.donarmstrong.com Git - debbugs.git/blobdiff - t/lib/DebbugsTest.pm
abstract out create config in tests
[debbugs.git] / t / lib / DebbugsTest.pm
index e45d7db1e996f7832b8373777fb245918781e44f..6e33399d4e0f6ce0bfefd04a7dbdf586c62bd744 100644 (file)
@@ -57,7 +57,8 @@ BEGIN{
 sub create_debbugs_configuration {
      my %param = validate_with(params => \@_,
                               spec   => {debug => {type => BOOLEAN,
-                                                   default => 0,
+                                                   default => exists $ENV{DEBUG}?
+                                                   $ENV{DEBUG}:0,
                                                   },
                                          cleanup => {type => BOOLEAN,
                                                      optional => 1,
@@ -73,6 +74,7 @@ sub create_debbugs_configuration {
      $ENV{DEBBUGS_CONFIG_FILE}  ="$config_dir/debbugs_config";
      $ENV{PERL5LIB} = getcwd();
      $ENV{SENDMAIL_TESTDIR} = $sendmail_dir;
+     eval {
      my $sendmail_tester = getcwd().'/t/sendmail_tester';
      unless (-x $sendmail_tester) {
          die q(t/sendmail_tester doesn't exist or isn't executable. You may be in the wrong directory.);
@@ -82,6 +84,7 @@ sub create_debbugs_configuration {
 \$gSpoolDir='$spool_dir';
 \$gLibPath='@{[getcwd()]}/scripts';
 \$gTemplateDir='@{[getcwd()]}/templates';
+\$gWebDir='@{[getcwd()]}/html';
 \$gWebHost='localhost';
 1;
 END
@@ -93,7 +96,7 @@ END
 foo main foo
 END
                            "$config_dir/pseudo-packages.description" => '',
-                           "$config_dir/pseudo-packages.maint" => '',
+                           "$config_dir/pseudo-packages.maintainers" => '',
                           );
      while (my ($file,$contents) = each %files_to_create) {
          system('mkdir','-p',dirname($file));
@@ -111,12 +114,24 @@ END
            "$spool_dir/index.archive");
 
      # create the spool files and sub directories
-     map {system('mkdir','-p',"$spool_dir/$_"); }
-         map {('db-h/'.$_,'archive/'.$_)}
-              map { sprintf "%02d",$_ % 100} 0..99;
+     for my $dir (0..99) {
+         for my $archive (qw(db-h archive)) {
+             system('mkdir','-p',"$spool_dir/$archive/".sprintf('%02d',$dir));
+         }
+     }
      system('mkdir','-p',"$spool_dir/incoming");
      system('mkdir','-p',"$spool_dir/lock");
+     eval '
+END{
+     if ($ENV{DEBUG}) {
+         diag("spool_dir:   $spool_dir\n");
+         diag("config_dir:   $config_dir\n",);
+         diag("sendmail_dir: $sendmail_dir\n");
+     }
+}';
 
+     };
+     BAIL_OUT ($@) if ($@);
      return (spool_dir => $spool_dir,
             sendmail_dir => $sendmail_dir,
             config_dir => $config_dir,
@@ -145,6 +160,9 @@ sub send_message{
                                                     },
                                          body    => {type => SCALAR,
                                                     },
+                                         attachments => {type => ARRAYREF,
+                                                         default => [],
+                                                        },
                                          run_processall =>{type => BOOLEAN,
                                                            default => 1,
                                                           },
@@ -153,13 +171,17 @@ sub send_message{
      $ENV{LOCAL_PART} = $param{to};
      my ($rfd,$wfd);
      my $output='';
-     local $SIG{PIPE} = 'IGNORE';
-     local $SIG{CHLD} = sub {};
+     my $pipe_handler = $SIG{PIPE};
+     $SIG{PIPE} = 'IGNORE';
+     $SIG{CHLD} = 'DEFAULT';
      my $pid = open3($wfd,$rfd,$rfd,'scripts/receive')
          or die "Unable to start receive: $!";
      print {$wfd} create_mime_message($param{headers},
-                                        $param{body}) or die "Unable to to print to receive";
+                                     $param{body},
+                                     $param{attachments}) or
+                                         die "Unable to to print to receive";
      close($wfd) or die "Unable to close receive";
+     $SIG{PIPE} = $pipe_handler;
      my $err = $? >> 8;
      my $childpid = waitpid($pid,0);
      if ($childpid != -1) {
@@ -183,9 +205,11 @@ sub send_message{
      }
 }
 
+$SIG{CHLD} = sub {};
+
 {
      package DebbugsTest::HTTPServer;
-     use base qw(HTTP::Server::Simple::CGI);
+     use base qw(HTTP::Server::Simple::CGI HTTP::Server::Simple::CGI::Environment);
 
      our $child_pid = undef;
      our $webserver = undef;