summaryrefslogtreecommitdiff
path: root/pkgtools
diff options
context:
space:
mode:
authorschmonz <schmonz@pkgsrc.org>2013-01-19 22:51:11 +0000
committerschmonz <schmonz@pkgsrc.org>2013-01-19 22:51:11 +0000
commit285febe2ebaf4b1544259ff76fd8a992d6c0be6c (patch)
treebd1a8f6142140f8e67285fd8bf07c1f101c22414 /pkgtools
parent1debd8c4370a8a95ba507e2b1434729f366f69ae (diff)
downloadpkgsrc-285febe2ebaf4b1544259ff76fd8a992d6c0be6c.tar.gz
Make it possible to easily write automated tests:
* minimally adapt pkglint(1) into a "modulino" for testability * verify it still runs normally as a program * create a test script with a few very simple test cases * hook it up to 'make test' * verify that the tests really fail if I go breaking the code under test Meta-addresses PR pkg/46570. New BUILD_DEPENDS, but no functional change, so no PKGREVISION bump. Approved by wiz@.
Diffstat (limited to 'pkgtools')
-rw-r--r--pkgtools/pkglint/Makefile11
-rw-r--r--pkgtools/pkglint/files/pkglint.pl4
-rw-r--r--pkgtools/pkglint/files/pkglint.t28
3 files changed, 38 insertions, 5 deletions
diff --git a/pkgtools/pkglint/Makefile b/pkgtools/pkglint/Makefile
index ab2320adc43..a38dd5a0eb4 100644
--- a/pkgtools/pkglint/Makefile
+++ b/pkgtools/pkglint/Makefile
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.423 2012/12/11 14:57:59 ryoon Exp $
+# $NetBSD: Makefile,v 1.424 2013/01/19 22:51:11 schmonz Exp $
# Note: if you update the version number, please have a look at the
# changes between the CVS tag "pkglint_current" and HEAD.
@@ -16,6 +16,8 @@ DEPENDS+= p5-Digest-SHA1-[0-9]*:../../security/p5-Digest-SHA1
DEPENDS+= p5-enum>=1.016:../../devel/p5-enum
DEPENDS+= p5-pkgsrc-Dewey>=1.0:../../pkgtools/p5-pkgsrc-Dewey
+BUILD_DEPENDS+= p5-Test-Trap-[0-9]*:../../devel/p5-Test-Trap
+
PKG_INSTALLATION_TYPES= overwrite pkgviews
WRKSRC= ${WRKDIR}
@@ -28,7 +30,7 @@ AUTO_MKDIRS= yes
SUBST_CLASSES+= pkglint
SUBST_STAGE.pkglint= post-configure
-SUBST_FILES.pkglint+= pkglint.pl
+SUBST_FILES.pkglint+= pkglint.pl pkglint.t
SUBST_FILES.pkglint+= plist-clash.pl
.if defined(BATCH)
SUBST_SED.pkglint+= -e s\|@PKGSRCDIR@\|/usr/pkgsrc\|g
@@ -50,7 +52,10 @@ quick-install:
${MAKE} do-extract subst-pkglint do-install selftest clean
do-extract:
- cd ${FILESDIR} && ${CP} pkglint.0 pkglint.1 pkglint.pl plist-clash.pl ${WRKSRC}
+ cd ${FILESDIR} && ${CP} pkglint.0 pkglint.1 pkglint.pl pkglint.t plist-clash.pl ${WRKSRC}
+
+do-test:
+ cd ${WRKSRC} && prove pkglint.t
do-install:
${INSTALL_SCRIPT} ${WRKSRC}/pkglint.pl ${DESTDIR}${PREFIX}/bin/pkglint
diff --git a/pkgtools/pkglint/files/pkglint.pl b/pkgtools/pkglint/files/pkglint.pl
index a82519ae8e4..a487c69e8e5 100644
--- a/pkgtools/pkglint/files/pkglint.pl
+++ b/pkgtools/pkglint/files/pkglint.pl
@@ -1,5 +1,5 @@
#! @PERL@
-# $NetBSD: pkglint.pl,v 1.847 2012/09/15 10:55:15 wiz Exp $
+# $NetBSD: pkglint.pl,v 1.848 2013/01/19 22:51:11 schmonz Exp $
#
# pkglint - static analyzer and checker for pkgsrc packages
@@ -8495,4 +8495,4 @@ sub main() {
PkgLint::Logging::print_summary_and_exit($opt_quiet);
}
-main();
+main() unless caller();
diff --git a/pkgtools/pkglint/files/pkglint.t b/pkgtools/pkglint/files/pkglint.t
new file mode 100644
index 00000000000..54f7656d537
--- /dev/null
+++ b/pkgtools/pkglint/files/pkglint.t
@@ -0,0 +1,28 @@
+#! @PERL@
+# $NetBSD: pkglint.t,v 1.1 2013/01/19 22:51:11 schmonz Exp $
+#
+
+package PkgLint::Test; # pkglint.pl uses 'main', so we mustn't
+
+use Test::More tests => 3;
+use Test::Trap;
+
+use warnings;
+use strict;
+
+require 'pkglint.pl'; # so we can test its internals
+
+sub test_main() {
+ my $unit = \&main::main;
+
+ my @r = trap { $unit->() };
+ is($trap->exit, 1, q{exit code was 1});
+ like($trap->stdout, qr/^ERROR:.+how to check/, q{message on stdout});
+ is($trap->stderr, '', q{nothing on stderr});
+}
+
+sub main() {
+ test_main();
+}
+
+main();