Browse Source

scripts/t: Add test cases for Dpkg::Conf

Guillem Jover 11 years ago
parent
commit
94340b6b3f
4 changed files with 115 additions and 2 deletions
  1. 1 0
      debian/changelog
  2. 1 0
      scripts/Makefile.am
  3. 90 2
      scripts/t/Dpkg_Conf.t
  4. 23 0
      scripts/t/Dpkg_Conf/config-mixed

+ 1 - 0
debian/changelog

@@ -108,6 +108,7 @@ dpkg (1.18.0) UNRELEASED; urgency=low
       directories with mode 000.
     - Fix dpkg-divert unit test to work when there is no /dev/full.
     - Skip test cases when there is no c++filt available.
+    - Add test cases for Dpkg::Conf.
   * Build system:
     - Bump gettext version to 0.19:
       + Use --add-location=file in msgmerge and xgettext commands.

+ 1 - 0
scripts/Makefile.am

@@ -276,6 +276,7 @@ test_data = \
 	t/Dpkg_Changelog/misplaced-tz \
 	t/Dpkg_Changelog/regressions \
 	t/Dpkg_Changelog/shadow \
+	t/Dpkg_Conf/config-mixed \
 	t/Dpkg_Control/control-1 \
 	t/Dpkg_Control/bogus-unsigned.dsc \
 	t/Dpkg_Control/bogus-armor-double.dsc \

+ 90 - 2
scripts/t/Dpkg_Conf.t

@@ -16,12 +16,100 @@
 use strict;
 use warnings;
 
-use Test::More tests => 1;
+use Test::More tests => 9;
 
 BEGIN {
     use_ok('Dpkg::Conf');
 }
 
-# TODO: Add actual test cases.
+my $srcdir = $ENV{srcdir} // '.';
+my $datadir = $srcdir . '/t/Dpkg_Conf';
+
+my ($conf, $count, @opts);
+
+my @expected_long_opts = (
+'--option-double-quotes=value double quotes',
+'--option-single-quotes=value single quotes',
+'--option-space=value words space',
+qw(
+--option-name=value-name
+--option-indent=value-indent
+--option-equal=value-equal=subvalue-equal
+--option-noequal=value-noequal
+--option-simple
+--option-dash=value-dash
+--l=v
+));
+my @expected_short_opts = qw(
+-o=vd
+-s
+);
+
+$conf = Dpkg::Conf->new();
+local $SIG{__WARN__} = sub { };
+$count = $conf->load("$datadir/config-mixed");
+delete $SIG{__WARN__};
+is($count, 10, 'Load a config file, only long options');
+
+@opts = $conf->get_options();
+is_deeply(\@opts, \@expected_long_opts, 'Parse long options');
+
+$conf = Dpkg::Conf->new(allow_short => 1);
+$count = $conf->load("$datadir/config-mixed");
+is($count, 12, 'Load a config file, mixed options');
+
+@opts = $conf->get_options();
+my @expected_mixed_opts = ( @expected_long_opts, @expected_short_opts );
+is_deeply(\@opts, \@expected_mixed_opts, 'Parse mixed options');
+
+my $expected_mixed_output = <<'MIXED';
+option-double-quotes = "value double quotes"
+option-single-quotes = "value single quotes"
+option-space = "value words space"
+option-name = "value-name"
+option-indent = "value-indent"
+option-equal = "value-equal=subvalue-equal"
+option-noequal = "value-noequal"
+option-simple
+option-dash = "value-dash"
+l = "v"
+-o = "vd"
+-s
+MIXED
+
+is($conf->output, $expected_mixed_output, 'Output mixed options');
+
+my $expected_filter;
+
+$expected_filter = <<'FILTER';
+l = "v"
+-o = "vd"
+-s
+FILTER
+
+$conf = Dpkg::Conf->new(allow_short => 1);
+$conf->load("$datadir/config-mixed");
+$conf->filter(remove => sub { $_[0] =~ m/^--option/ });
+is($conf->output, $expected_filter, 'Filter remove');
+
+$expected_filter = <<'FILTER';
+option-double-quotes = "value double quotes"
+option-single-quotes = "value single quotes"
+FILTER
+
+$conf = Dpkg::Conf->new(allow_short => 1);
+$conf->load("$datadir/config-mixed");
+$conf->filter(keep => sub { $_[0] =~ m/^--option-[a-z]+-quotes/ });
+is($conf->output, $expected_filter, 'Filter keep');
+
+$expected_filter = <<'FILTER';
+l = "v"
+FILTER
+
+$conf = Dpkg::Conf->new(allow_short => 1);
+$conf->load("$datadir/config-mixed");
+$conf->filter(remove => sub { $_[0] =~ m/^--option/ },
+              keep => sub { $_[0] =~ m/^--/ });
+is($conf->output, $expected_filter, 'Filter keep and remove');
 
 1;

+ 23 - 0
scripts/t/Dpkg_Conf/config-mixed

@@ -0,0 +1,23 @@
+# Comment followed by an empty line.
+
+option-double-quotes = "value double quotes"
+option-single-quotes = 'value single quotes'
+option-space  = 	 value words space	  
+
+option-name=value-name		  
+	  
+	  # Indented comment.
+	  option-indent = value-indent
+
+option-equal=value-equal=subvalue-equal
+option-noequal value-noequal
+option-simple
+
+# Fully spelled out option.
+--option-dash=value-dash
+
+# Long option with one character name.
+l=v
+# Short option.
+-o=vd
+-s