]> err.no Git - dpkg/commitdiff
Add non-regression tests for Dpkg::Control and Dpkg::Cdata
authorRaphael Hertzog <hertzog@debian.org>
Sat, 29 Dec 2007 18:34:24 +0000 (19:34 +0100)
committerRaphael Hertzog <hertzog@debian.org>
Tue, 1 Jan 2008 19:26:52 +0000 (20:26 +0100)
ChangeLog
scripts/t/700_Dpkg_Control.t [new file with mode: 0644]
scripts/t/700_Dpkg_Control/control-1 [new file with mode: 0644]

index f27de5cf1646e8d1de3d5a08e57c1ad1a06a663c..5a71bec40d93c9b54ac6ab8127c7e93f7d868fb8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -27,6 +27,9 @@
 
        * scripts/Dpkg/Cdata.pm, scripts/Dpkg/Control.pm: Add two new
        module to parse and manipulate files like debian/control.
+       * scripts/t/600_Dpkg_Control.t,
+       scripts/t/600_Dpkg_Control/control-1: Add non-regression tests for
+       Dpkg::Control and Dpkg::Cdata.
 
 2007-12-28  Raphael Hertzog  <hertzog@debian.org>
 
diff --git a/scripts/t/700_Dpkg_Control.t b/scripts/t/700_Dpkg_Control.t
new file mode 100644 (file)
index 0000000..bff3e36
--- /dev/null
@@ -0,0 +1,63 @@
+# -*- mode: cperl;-*-
+
+use Test::More tests => 9;
+
+use strict;
+use warnings;
+use IO::String;
+
+use_ok('Dpkg::Control');
+
+my $srcdir = $ENV{srcdir} || '.';
+$srcdir .= '/t/700_Dpkg_Control';
+
+my $c = Dpkg::Control->new("$srcdir/control-1");
+
+my $io = IO::String->new();
+$c->dump($io);
+is(${$io->string_ref()},
+'Source: mysource
+My-Field-One: myvalue1
+My-Field-Two: myvalue2
+Long-Field: line1
+ line 2 line 2 line 2
+ line 3 line 3 line 3
+Empty-Field: 
+
+Package: mypackage1
+Depends: libc6
+
+Package: mypackage2
+Depends: hello
+
+Package: mypackage3
+Depends: hello
+Description: short one
+ long one
+ very long one
+', "Dump of $srcdir/control-1");
+
+my $src = $c->get_source();
+is($src->{'my-field-one'}, 'myvalue1', "Access field through badly capitalized field name");
+is($src->{'long-field'}, 
+'line1
+ line 2 line 2 line 2
+ line 3 line 3 line 3', "Get multi-line field");
+is($src->{'Empty-field'}, "", "Get empty field");
+
+my $pkg = $c->get_pkg_by_idx(1);
+is($pkg->{package}, 'mypackage1', 'Name of first package');
+
+$pkg = $c->get_pkg_by_name("mypackage3");
+is($pkg->{package}, 'mypackage3', 'Name of third package');
+is($pkg->{Depends}, 'hello', 'Name of third package');
+
+$pkg = $c->get_pkg_by_idx(2);
+$io = IO::String->new();
+tied(%{$pkg})->dump($io);
+
+is(${$io->string_ref()},
+'Package: mypackage2
+Depends: hello
+', "Dump of second binary package of $srcdir/control-1");
+
diff --git a/scripts/t/700_Dpkg_Control/control-1 b/scripts/t/700_Dpkg_Control/control-1
new file mode 100644 (file)
index 0000000..31f35cd
--- /dev/null
@@ -0,0 +1,22 @@
+Source: mysource
+# This is a comment
+my-field-one: myvalue1
+my-field-two: myvalue2
+long-field: line1
+ line 2 line 2 line 2
+ line 3 line 3 line 3
+empty-field: 
+     
+# First package
+Package: mypackage1
+Depends: libc6
+
+# Second package
+Package: mypackage2
+Depends: hello
+
+Package: mypackage3
+Depends: hello
+Description: short one
+ long one
+ very long one