]> err.no Git - dpkg/commitdiff
Add a test target to scripts/Makefile.am
authorFrank Lichtenheld <djpig@debian.org>
Sun, 8 Jul 2007 20:17:55 +0000 (20:17 +0000)
committerFrank Lichtenheld <djpig@debian.org>
Sun, 8 Jul 2007 20:17:55 +0000 (20:17 +0000)
Add a simple test target copied from a MakeMaker
generated Makefile and add Dpkg::Version testscript,
like the code copied from Debbugs bzr

scripts/Makefile.am
scripts/t/02_version_dpkg.t [new file with mode: 0644]

index 93e32273873be8048e878bcea9b7f7a9e74f4471..277a5219b923d103230d654f46436a031be53df8 100644 (file)
@@ -99,3 +99,9 @@ install-data-local:
 uninstall-local:
        rm -f $(DESTDIR)$(sysconfdir)/alternatives/README
        rm -f $(DESTDIR)$(sbindir)/install-info
+
+TEST_FILES= t/*.t
+TEST_VERBOSE= 0
+
+test:
+       PERL_DL_NONLAZY=1 $(PERL) "-MExtUtils::Command::MM" "-e" "test_harness($(TEST_VERBOSE), '.')" $(TEST_FILES)
diff --git a/scripts/t/02_version_dpkg.t b/scripts/t/02_version_dpkg.t
new file mode 100644 (file)
index 0000000..c541550
--- /dev/null
@@ -0,0 +1,51 @@
+# -*- mode: cperl;-*-
+
+use Test::More;
+
+use warnings;
+use strict;
+
+use utf8;
+use Encode;
+
+# Default cmp '>'
+my @versions = ({a      => '1.0-1',
+                b      => '2.0-2',
+                result => -1,
+                relation => 'lt',
+               },
+               {a      => '2.2~rc-4',
+                b      => '2.2-1',
+                result => -1,
+                relation => 'lt',
+               },
+               {a      => '2.2-1',
+                b      => '2.2~rc-4',
+                result => 1,
+                relation => 'gt',
+               },
+               {a      => '1.0000-1',
+                b      => '1.0-1',
+                result => 0,
+                relation => 'eq',
+               },
+              );
+
+plan tests => @versions * 2 + 1;
+
+sub dpkg_vercmp{
+     my ($a,$b,$cmp) = @_;
+     $cmp = 'gt' if not defined $cmp;
+     return system('dpkg','--compare-versions',$a,$cmp,$b) == 0;
+}
+
+
+use_ok('Dpkg::Version');
+
+for my $version_cmp (@versions) {
+     ok(Dpkg::Version::vercmp($$version_cmp{a},$$version_cmp{b}) == $$version_cmp{result},
+       "Version $$version_cmp{a} $$version_cmp{relation} $$version_cmp{b} ok");
+     ok(dpkg_vercmp($$version_cmp{a},$$version_cmp{b},$$version_cmp{relation}),
+       "Dpkg concures: Version $$version_cmp{a} $$version_cmp{relation} $$version_cmp{b}");
+}
+