[mb2md] 01/02: Add minimal test suite for build time and as-installed testing

Axel Beckert abe at deuxchevaux.org
Sun May 22 16:13:12 UTC 2016


This is an automated email from the git hooks/post-receive script.

abe pushed a commit to branch master
in repository mb2md.

commit 15c3fe166e8f0bc12e3ab40087f119cbc4c0d791
Author: Axel Beckert <abe at deuxchevaux.org>
Date:   Sun May 22 18:06:36 2016 +0200

    Add minimal test suite for build time and as-installed testing
    
    Add a one line patch to take home directory from $HOME if set.
    
    Reason: mb2md originally uses getpwuid($<) which is not easily
    overridable, e.g. for unit tests.
    
    Note: As of this commit, the test suite _fails_ due to
    https://bugs.debian.org/818678 -- will be fixed in the next commit.
---
 debian/changelog                                   |  2 +
 debian/control                                     |  1 +
 ...-and-destination-path-expansion-behave-mo.patch |  8 ++--
 debian/patches/series                              |  1 +
 .../use-$HOME-to-determine-home-directory.patch    | 14 ++++++
 debian/rules                                       |  3 ++
 debian/tests/control                               |  2 +
 debian/tests/data/example.mbox                     | 36 +++++++++++++++
 debian/tests/data/example.output                   |  5 +++
 debian/tests/run-testsuite.sh                      |  6 +++
 debian/tests/t/mb2md.t                             | 52 ++++++++++++++++++++++
 11 files changed, 126 insertions(+), 4 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 1da24c8..cc37984 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -14,6 +14,8 @@ mb2md (3.20-8) UNRELEASED; urgency=medium
     + The packaging is licensed under GPLv3 as Noël stated in a private,
       signed e-mail to me.
   * Refresh all patches to get rid of small line offsets.
+  * Add minimal test suite for build time and as-installed testing.
+    + Add patch to take home directory from $HOME if set.
 
  -- Salvatore Bonaccorso <carnil at debian.org>  Sat, 30 Jan 2016 20:07:36 +0100
 
diff --git a/debian/control b/debian/control
index 3592597..59a285b 100644
--- a/debian/control
+++ b/debian/control
@@ -11,6 +11,7 @@ Standards-Version: 3.9.8
 Vcs-Git: https://anonscm.debian.org/git/pkg-perl/packages/mb2md.git
 Vcs-Browser: https://anonscm.debian.org/cgit/pkg-perl/packages/mb2md.git
 Homepage: http://batleth.sapienti-sat.org/projects/mb2md/
+Testsuite: autopkgtest
 
 Package: mb2md
 Architecture: all
diff --git a/debian/patches/Make-source-and-destination-path-expansion-behave-mo.patch b/debian/patches/Make-source-and-destination-path-expansion-behave-mo.patch
index a773ad4..01fde0f 100644
--- a/debian/patches/Make-source-and-destination-path-expansion-behave-mo.patch
+++ b/debian/patches/Make-source-and-destination-path-expansion-behave-mo.patch
@@ -11,7 +11,7 @@ Author: Axel Beckert <abe at debian.org>
 
 --- a/mb2md-3.20.pl
 +++ b/mb2md-3.20.pl
-@@ -411,6 +411,7 @@
+@@ -412,6 +412,7 @@
  my $dest = undef;
  my $strip_ext = undef;
  my $use_cl = undef;	# defines whether we use the Content-Length: header if present
@@ -19,7 +19,7 @@ Author: Axel Beckert <abe at debian.org>
  
  # if option "-c" is given, we use the Content-Length: header if present
  # dangerous! may be unreliable, as the whole CL stuff is a bad idea
-@@ -443,7 +444,7 @@
+@@ -444,7 +445,7 @@
  	# it is a subdir of the users $home
  	# if it does start with a "/" then
  	# let's take $mbroot as a absolut path
@@ -28,7 +28,7 @@ Author: Axel Beckert <abe at debian.org>
  
  	# check if the given source is a mbox file
  	if (-f $opts{s})
-@@ -493,13 +494,13 @@
+@@ -494,13 +495,13 @@
  
  # if the destination is relative to the home dir,
  # check that the home dir exists
@@ -44,7 +44,7 @@ Author: Axel Beckert <abe at debian.org>
  # get rid of trailing /'s
  $dest =~ s/\/$//;
  
-@@ -755,6 +756,7 @@
+@@ -756,6 +757,7 @@
          # Change to the target mailbox directory.
  
          chdir "$maildir" ;
diff --git a/debian/patches/series b/debian/patches/series
index 2107c0d..39da2b2 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1,4 +1,5 @@
 fix-dash-r-option.patch
 better-separator-line-detection.patch
 fix-uw-imap-misspellings.patch
+use-$HOME-to-determine-home-directory.patch
 Make-source-and-destination-path-expansion-behave-mo.patch
diff --git a/debian/patches/use-$HOME-to-determine-home-directory.patch b/debian/patches/use-$HOME-to-determine-home-directory.patch
new file mode 100644
index 0000000..7c0fd80
--- /dev/null
+++ b/debian/patches/use-$HOME-to-determine-home-directory.patch
@@ -0,0 +1,14 @@
+Description: Use $HOME to determine home directory
+ The home directory needs to be overridable for the test suite.
+Author: Axel Beckert <abe at debian.org>
+
+--- a/mb2md-3.20.pl
++++ b/mb2md-3.20.pl
+@@ -402,6 +402,7 @@
+ 
+ # Get uid, username and home dir
+ my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $homedir, $shell) = getpwuid($<);
++$homedir = $ENV{HOME} if exists $ENV{HOME} and defined($ENV{HOME});
+ 
+ # Get arguments and determine source
+ # and target directories.
diff --git a/debian/rules b/debian/rules
index 758f0d5..e2e75e8 100755
--- a/debian/rules
+++ b/debian/rules
@@ -7,3 +7,6 @@
 
 override_dh_auto_build:
 	/usr/bin/docbook-to-man debian/mb2md.sgml > debian/mb2md.1
+
+override_dh_auto_test:
+	debian/tests/run-testsuite.sh perl `pwd`/mb2md-3.20.pl
diff --git a/debian/tests/control b/debian/tests/control
new file mode 100644
index 0000000..da210b5
--- /dev/null
+++ b/debian/tests/control
@@ -0,0 +1,2 @@
+Tests: run-testsuite.sh
+Depends: @
diff --git a/debian/tests/data/example.mbox b/debian/tests/data/example.mbox
new file mode 100644
index 0000000..96b0a9e
--- /dev/null
+++ b/debian/tests/data/example.mbox
@@ -0,0 +1,36 @@
+From mb2md at localhost  Sun May 22 15:48:49 2016
+Return-Path: <mb2md at localhost>
+X-Original-To: mb2md at localhost
+Delivered-To: mb2md at localhost.localdomain
+Received: from c-cactus2 (localhost [IPv6:::1])
+	by localhost (Postfix) with ESMTP id 3rCNLT5v5Bz82
+	for <mb2md at localhost>; Sun, 22 May 2016 15:48:49 +0200 (CEST)
+Date: Sun, 22 May 2016 15:48:49 +0200
+To: mb2md at localhost.localdomain
+From: mb2md at localhost
+Subject: test Sun, 22 May 2016 15:48:49 +0200
+X-Mailer: swaks v20130209.0 jetmore.org/john/code/swaks/
+Message-Id: <3rCNLT5v5Bz82 at localhost>
+Content-Length: 23
+Lines: 1
+
+This is a test mailing
+
+From mb2md at localhost  Sun May 22 15:49:20 2016
+Return-Path: <mb2md at localhost>
+X-Original-To: mb2md at localhost
+Delivered-To: mb2md at localhost.localdomain
+Received: from c-cactus2 (localhost [IPv6:::1])
+	by localhost (Postfix) with ESMTP id 3rCNM419rZz82
+	for <mb2md at localhost>; Sun, 22 May 2016 15:49:20 +0200 (CEST)
+Date: Sun, 22 May 2016 15:49:20 +0200
+To: mb2md at localhost.localdomain
+From: mb2md at localhost
+Subject: test Sun, 22 May 2016 15:49:20 +0200
+X-Mailer: swaks v20130209.0 jetmore.org/john/code/swaks/
+Message-Id: <3rCNM419rZz82 at localhost>
+Content-Length: 23
+Lines: 1
+
+This is a test mailing
+
diff --git a/debian/tests/data/example.output b/debian/tests/data/example.output
new file mode 100644
index 0000000..8e89629
--- /dev/null
+++ b/debian/tests/data/example.output
@@ -0,0 +1,5 @@
+Converting <prefix>/example.mbox to maildir: <prefix>/example.maildir
+Source Mbox is <prefix>/example.mbox
+Target Maildir is <prefix>/example.maildir 
+2 messages.
+
diff --git a/debian/tests/run-testsuite.sh b/debian/tests/run-testsuite.sh
new file mode 100755
index 0000000..f4f1910
--- /dev/null
+++ b/debian/tests/run-testsuite.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+MB2MD=${@:-/usr/bin/mb2md}
+export MB2MD
+
+prove -v debian/tests/t/*.t
diff --git a/debian/tests/t/mb2md.t b/debian/tests/t/mb2md.t
new file mode 100755
index 0000000..5e98e24
--- /dev/null
+++ b/debian/tests/t/mb2md.t
@@ -0,0 +1,52 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use 5.010;
+
+use Test::More;
+use Test::Command::Simple;
+use Path::Tiny qw(path cwd);
+use Cwd;
+
+my $mb2md = $ENV{MB2MD} || 'md2md';
+
+my $output_template       = path('debian/tests/data/example.output')->slurp;
+my $tempdir               = Path::Tiny->tempdir();
+my $fakehome = $ENV{HOME} = "$tempdir/home";
+my $dir1                  = "$tempdir/1";
+my $dir2                  = "$tempdir/2";
+
+foreach my $dir ($fakehome, $dir1, $dir2) {
+    ok(path($dir)->mkpath, "Created '$dir'");
+    is(ref(path('debian/tests/data/example.mbox')->copy("$dir/")),
+       'Path::Tiny',
+       "Successfully copied example.mbox to fake home directory $dir/");
+}
+
+sub replace_prefix {
+    my ($string, $prefix) = @_;
+    $prefix .= '/' if ($prefix ne '' and $prefix !~ m(/$));
+    $string =~ s:<prefix>/:$prefix:g;
+    return $string;
+}
+
+# Without prefix, i.e. relative to $HOME
+run_ok("$mb2md -s example.mbox -d example.maildir");
+is(stdout, replace_prefix($output_template, $fakehome), 'Stdout as expected');
+is(stderr, '', 'No stderr');
+
+# With absolute paths
+run_ok("$mb2md -s $dir1/example.mbox -d $dir1/example.maildir");
+is(stdout, replace_prefix($output_template, $dir1), 'Stdout as expected');
+is(stderr, '', 'No stderr');
+
+# With ./ prefix
+my $cwd = cwd;
+ok(chdir($dir2), "Change to directory '$dir2'.");
+run_ok("$mb2md -s ./example.mbox -d ./example.maildir");
+ok(chdir($cwd), "Change to directory back to '$cwd'.");
+is(stdout, replace_prefix($output_template, '.'), 'Stdout as expected');
+is(stderr, '', 'No stderr');
+
+done_testing();

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/mb2md.git



More information about the Pkg-perl-cvs-commits mailing list