diff options
author | Guillem Jover <guillem@debian.org> | 2016-05-13 17:10:33 +0200 |
---|---|---|
committer | Guillem Jover <guillem@debian.org> | 2016-07-03 18:44:24 +0200 |
commit | 0d159ba9b5da8bd5dfcb9e9110ba3e4c2867b0fe (patch) | |
tree | 2d06cb942ad9152ed4ab0dbfc871717408d0d649 | |
parent | fc55edbf31dc9d8649229fdca441cb63844424d9 (diff) | |
download | dpkg-0d159ba9b5da8bd5dfcb9e9110ba3e4c2867b0fe.tar.gz |
Dpkg::Control: Add new autopkgtest control files support
Add new CTRL_TESTS control types, new Dpkg::Control::Tests and
Dpkg::Control::Tests::Entry modules, add support for the fields that
can appear on these control files, and update Dpkg::Index to handle
them as well.
[niels@thykier.net: Fix logic inversion. ]
-rw-r--r-- | debian/changelog | 4 | ||||
-rw-r--r-- | scripts/Dpkg/Control.pm | 13 | ||||
-rw-r--r-- | scripts/Dpkg/Control/FieldsCore.pm | 24 | ||||
-rw-r--r-- | scripts/Dpkg/Control/Tests.pm | 83 | ||||
-rw-r--r-- | scripts/Dpkg/Control/Tests/Entry.pm | 91 | ||||
-rw-r--r-- | scripts/Dpkg/Control/Types.pm | 3 | ||||
-rw-r--r-- | scripts/Dpkg/Index.pm | 7 | ||||
-rw-r--r-- | scripts/Makefile.am | 6 | ||||
-rw-r--r-- | scripts/t/Dpkg_Control_Tests.t | 71 | ||||
-rw-r--r-- | scripts/t/Dpkg_Control_Tests/tests-missing-fields | 7 | ||||
-rw-r--r-- | scripts/t/Dpkg_Control_Tests/tests-plain-text | 6 | ||||
-rw-r--r-- | scripts/t/Dpkg_Control_Tests/tests-valid | 18 |
12 files changed, 330 insertions, 3 deletions
diff --git a/debian/changelog b/debian/changelog index d48c6de84..894160dc1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -25,6 +25,10 @@ dpkg (1.18.8) UNRELEASED; urgency=medium supported. Add regression tests to avoid similar changes in the future. Closes: #824938 - Add support for system and user config loading in Dpkg::Conf. + - Add support for autopkgtest control files, with new CTRL_TESTS control + type, new recognized fields to Dpkg::Control::Fields, and new modules + Dpkg::Control::Tests and Dpkg::Control::Tests::Entry. Also update + Dpkg::Index to support these. * Test suite: - Bump perlcritic ValuesAndExpressions::RequireNumberSeparators minimum to 99999. diff --git a/scripts/Dpkg/Control.pm b/scripts/Dpkg/Control.pm index b3d4e7143..81ad162ac 100644 --- a/scripts/Dpkg/Control.pm +++ b/scripts/Dpkg/Control.pm @@ -18,7 +18,7 @@ package Dpkg::Control; use strict; use warnings; -our $VERSION = '1.01'; +our $VERSION = '1.02'; our @EXPORT = qw( CTRL_UNKNOWN CTRL_INFO_SRC @@ -35,6 +35,7 @@ our @EXPORT = qw( CTRL_COPYRIGHT_HEADER CTRL_COPYRIGHT_FILES CTRL_COPYRIGHT_LICENSE + CTRL_TESTS ); use Exporter qw(import); @@ -134,6 +135,10 @@ machine readable format. Corresponds to a license control block in a F<debian/copyright> file in machine readable format. +=item CTRL_TESTS + +Corresponds to a package tests control file in F<debian/tests/control>. + =back =head1 METHODS @@ -193,6 +198,8 @@ sub set_options { $$self->{name} = g_('files stanza of copyright file'); } elsif ($t == CTRL_COPYRIGHT_HEADER) { $$self->{name} = g_('license stanza of copyright file'); + } elsif ($t == CTRL_TESTS) { + $$self->{name} = g_("package's tests control file"); } elsif ($t == CTRL_REPO_RELEASE) { $$self->{name} = sprintf(g_("repository's %s file"), 'Release'); } elsif ($t == CTRL_INDEX_SRC) { @@ -233,6 +240,10 @@ sub get_type { =head1 CHANGES +=head2 Version 1.02 (dpkg 1.18.8) + +New type: CTRL_TESTS. + =head2 Version 1.01 (dpkg 1.18.5) New types: CTRL_REPO_RELEASE, CTRL_COPYRIGHT_HEADER, CTRL_COPYRIGHT_FILES, diff --git a/scripts/Dpkg/Control/FieldsCore.pm b/scripts/Dpkg/Control/FieldsCore.pm index 1f01ae0b0..0c7ce4b1f 100644 --- a/scripts/Dpkg/Control/FieldsCore.pm +++ b/scripts/Dpkg/Control/FieldsCore.pm @@ -153,6 +153,10 @@ our %FIELDS = ( 'Changes' => { allowed => ALL_CHANGES, }, + 'Classes' => { + allowed => CTRL_TESTS, + separator => FIELD_SEP_COMMA, + }, 'Closes' => { allowed => ALL_CHANGES, separator => FIELD_SEP_SPACE, @@ -187,7 +191,7 @@ our %FIELDS = ( allowed => ALL_CHANGES | CTRL_REPO_RELEASE, }, 'Depends' => { - allowed => ALL_PKG, + allowed => ALL_PKG | CTRL_TESTS, separator => FIELD_SEP_COMMA, dependency => 'normal', dep_order => 2, @@ -213,6 +217,10 @@ our %FIELDS = ( 'Essential' => { allowed => ALL_PKG, }, + 'Features' => { + allowed => CTRL_TESTS, + separator => FIELD_SEP_SPACE, + }, 'Filename' => { allowed => CTRL_INDEX_PKG, separator => FIELD_SEP_LINE | FIELD_SEP_SPACE, @@ -291,6 +299,10 @@ our %FIELDS = ( dependency => 'union', dep_order => 8, }, + 'Restrictions' => { + allowed => CTRL_TESTS, + separator => FIELD_SEP_SPACE, + }, 'Section' => { allowed => CTRL_INFO_SRC | CTRL_INDEX_SRC | ALL_PKG, }, @@ -328,6 +340,16 @@ our %FIELDS = ( 'Task' => { allowed => ALL_PKG, }, + 'Test-Command' => { + allowed => CTRL_TESTS, + }, + 'Tests' => { + allowed => CTRL_TESTS, + separator => FIELD_SEP_SPACE, + }, + 'Tests-Directory' => { + allowed => CTRL_TESTS, + }, 'Testsuite' => { allowed => ALL_SRC, separator => FIELD_SEP_COMMA, diff --git a/scripts/Dpkg/Control/Tests.pm b/scripts/Dpkg/Control/Tests.pm new file mode 100644 index 000000000..439eee8c8 --- /dev/null +++ b/scripts/Dpkg/Control/Tests.pm @@ -0,0 +1,83 @@ +# Copyright © 2016 Guillem Jover <guillem@debian.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +package Dpkg::Control::Tests; + +use strict; +use warnings; + +our $VERSION = '1.00'; + +use Dpkg::Control; +use Dpkg::Control::Tests::Entry; +use Dpkg::Index; + +use parent qw(Dpkg::Index); + +=encoding utf8 + +=head1 NAME + +Dpkg::Control::Tests - parse files like debian/tests/control + +=head1 DESCRIPTION + +It provides an object to access data of files that follow the same +syntax as F<debian/tests/control>. + +=head1 METHODS + +All the methods of Dpkg::Index are available. Those listed below are either +new or overridden with a different behavior. + +=over 4 + +=item $c = Dpkg::Control::Tests->new(%opts) + +Create a new Dpkg::Control::Tests object, which inherits from Dpkg::Index. + +=cut + +sub new { + my ($this, %opts) = @_; + my $class = ref($this) || $this; + my $self = Dpkg::Index->new(type => CTRL_TESTS, %opts); + + return bless $self, $class; +} + +=item $item = $tests->new_item() + +Creates a new item. + +=cut + +sub new_item { + my $self = shift; + + return Dpkg::Control::Tests::Entry->new(); +} + +=back + +=head1 CHANGES + +=head2 Version 1.00 (dpkg 1.18.8) + +Mark the module as public. + +=cut + +1; diff --git a/scripts/Dpkg/Control/Tests/Entry.pm b/scripts/Dpkg/Control/Tests/Entry.pm new file mode 100644 index 000000000..392493c2a --- /dev/null +++ b/scripts/Dpkg/Control/Tests/Entry.pm @@ -0,0 +1,91 @@ +# Copyright © 2016 Guillem Jover <guillem@debian.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +package Dpkg::Control::Tests::Entry; + +use strict; +use warnings; + +our $VERSION = '1.00'; + +use Dpkg::Gettext; +use Dpkg::ErrorHandling; +use Dpkg::Control; + +use parent qw(Dpkg::Control); + +=encoding utf8 + +=head1 NAME + +Dpkg::Control::Tests::Entry - represents a test suite entry + +=head1 DESCRIPTION + +This object represents a test suite entry. + +=head1 METHODS + +All the methods of Dpkg::Control are available. Those listed below are either +new or overridden with a different behavior. + +=over 4 + +=item $entry = Dpkg::Control::Tests::Entry->new() + +Creates a new object. It does not represent a real control test entry +until one has been successfully parsed or built from scratch. + +=cut + +sub new { + my ($this, %opts) = @_; + my $class = ref($this) || $this; + + my $self = Dpkg::Control->new(type => CTRL_TESTS, %opts); + bless $self, $class; + return $self; +} + +=item $entry->parse($fh, $desc) + +Parse a control test entry from a filehandle. + +=cut + +sub parse { + my ($self, $fh, $desc) = @_; + + return if not $self->SUPER::parse($fh, $desc); + + if (not exists $self->{'Tests'} and not exists $self->{'Test-Command'}) { + $self->parse_error($desc, g_('block lacks either %s or %s fields'), + 'Tests', 'Test-Command'); + } + + return 1; +} + +=back + +=head1 CHANGES + +=head2 Version 1.00 (dpkg 1.18.8) + +Mark the module as public. + +=cut + +1; diff --git a/scripts/Dpkg/Control/Types.pm b/scripts/Dpkg/Control/Types.pm index 938659bfb..e144dd942 100644 --- a/scripts/Dpkg/Control/Types.pm +++ b/scripts/Dpkg/Control/Types.pm @@ -33,6 +33,7 @@ our @EXPORT = qw( CTRL_COPYRIGHT_HEADER CTRL_COPYRIGHT_FILES CTRL_COPYRIGHT_LICENSE + CTRL_TESTS ); use Exporter qw(import); @@ -83,6 +84,8 @@ use constant { CTRL_COPYRIGHT_FILES => 4096, # License control block in debian/copyright. CTRL_COPYRIGHT_LICENSE => 8192, + # Package test suite control file in debian/tests/control. + CTRL_TESTS => 16384, }; =head1 CHANGES diff --git a/scripts/Dpkg/Index.pm b/scripts/Dpkg/Index.pm index 6456209de..089a1d34f 100644 --- a/scripts/Dpkg/Index.pm +++ b/scripts/Dpkg/Index.pm @@ -78,7 +78,8 @@ contain one item with a given key. The function used depends on the type: for CTRL_INFO_PKG, CTRL_INDEX_SRC, CTRL_INDEX_PKG and CTRL_PKG_DEB it's simply the Package field; for CTRL_PKG_SRC and CTRL_INFO_SRC, it's the Source field; for CTRL_CHANGELOG it's the Source and the Version -fields (concatenated with an intermediary "_"); for CTRL_FILE_CHANGES it's +fields (concatenated with an intermediary "_"); for CTRL_TESTS is either +the Tests or Test-Command fields; for CTRL_FILE_CHANGES it's the Source, Version and Architecture fields (concatenated with "_"); for CTRL_FILE_VENDOR it's the Vendor field; for CTRL_FILE_STATUS it's the Package and Architecture fields (concatenated with "_"). Otherwise it's @@ -109,6 +110,10 @@ sub set_options { $self->{get_key_func} = sub { return $_[0]->{Files}; }; } elsif ($t == CTRL_COPYRIGHT_LICENSE) { $self->{get_key_func} = sub { return $_[0]->{License}; }; + } elsif ($t == CTRL_TESTS) { + $self->{get_key_func} = sub { + return $_[0]->{Tests} || $_[0]->{'Test-Command'}; + }; } elsif ($t == CTRL_FILE_CHANGES) { $self->{get_key_func} = sub { return $_[0]->{Source} . '_' . $_[0]->{Version} . '_' . diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 152c2e4cb..7b1ac36d5 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -72,6 +72,8 @@ nobase_dist_perllib_DATA = \ Dpkg/Control/Info.pm \ Dpkg/Control/HashCore.pm \ Dpkg/Control/Hash.pm \ + Dpkg/Control/Tests.pm \ + Dpkg/Control/Tests/Entry.pm \ Dpkg/Control/Types.pm \ Dpkg/Deps.pm \ Dpkg/Dist/Files.pm \ @@ -218,6 +220,7 @@ test_scripts = \ t/Dpkg_Changelog.t \ t/Dpkg_Changelog_Ubuntu.t \ t/Dpkg_Control.t \ + t/Dpkg_Control_Tests.t \ t/Dpkg_Index.t \ t/Dpkg_Substvars.t \ t/Dpkg_IPC.t \ @@ -293,6 +296,9 @@ test_data = \ t/Dpkg_Control/bogus-armor-inline.dsc \ t/Dpkg_Control/bogus-armor-nested.dsc \ t/Dpkg_Control/bogus-armor-spaces.dsc \ + t/Dpkg_Control_Tests/tests-missing-fields \ + t/Dpkg_Control_Tests/tests-plain-text \ + t/Dpkg_Control_Tests/tests-valid \ t/Dpkg_Source_Quilt/parse/debian/patches/series \ t/Dpkg_Substvars/substvars1 \ t/Dpkg_Substvars/substvars2 \ diff --git a/scripts/t/Dpkg_Control_Tests.t b/scripts/t/Dpkg_Control_Tests.t new file mode 100644 index 000000000..b9905bacf --- /dev/null +++ b/scripts/t/Dpkg_Control_Tests.t @@ -0,0 +1,71 @@ +#!/usr/bin/perl +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +use strict; +use warnings; + +use Test::More tests => 5; + +BEGIN { + use_ok('Dpkg::Control::Tests'); +} + +my $srcdir = $ENV{srcdir} || '.'; +my $datadir = $srcdir . '/t/Dpkg_Control_Tests'; + +sub parse_tests { + my $path = shift; + + my $tests = Dpkg::Control::Tests->new(); + eval { + $tests->load($path); + 1; + } or return; + + return $tests; +} + +my $tests; + +$tests = parse_tests("$datadir/tests-missing-fields"); +is($tests, undef, 'autopkgtest missing required fields'); + +$tests = parse_tests("$datadir/tests-plain-text"); +is($tests, undef, 'autopkgtest is not in deb822 format'); + +my $expected = <<'TESTS'; +Tests: aaa, bbb, ccc + +Tests: danger, warning +Restrictions: rw-build-tree, needs-root, breaks-testbed + +Tests: depends +Depends: @, @builddeps@, extra-package + +Tests: dir +Tests-Directory: . + +Tests: feature + +Tests: class +Classes: self-test + +Test-Command: command arg1 arg2 + +TESTS + +$tests = parse_tests("$datadir/tests-valid"); +ok(defined $tests, 'Valid autopkgtest control file'); +is($tests->output(), $expected, 'autopkgtest control file dumped'); diff --git a/scripts/t/Dpkg_Control_Tests/tests-missing-fields b/scripts/t/Dpkg_Control_Tests/tests-missing-fields new file mode 100644 index 000000000..7f7794de5 --- /dev/null +++ b/scripts/t/Dpkg_Control_Tests/tests-missing-fields @@ -0,0 +1,7 @@ +Tests: aaa + +Test-Command: command + +Other: + +Tests: bbb diff --git a/scripts/t/Dpkg_Control_Tests/tests-plain-text b/scripts/t/Dpkg_Control_Tests/tests-plain-text new file mode 100644 index 000000000..a29d38868 --- /dev/null +++ b/scripts/t/Dpkg_Control_Tests/tests-plain-text @@ -0,0 +1,6 @@ +This is a plain text file +that does not contain + + any of the expected fields nor values + +and should fail to load. diff --git a/scripts/t/Dpkg_Control_Tests/tests-valid b/scripts/t/Dpkg_Control_Tests/tests-valid new file mode 100644 index 000000000..c0ad60b27 --- /dev/null +++ b/scripts/t/Dpkg_Control_Tests/tests-valid @@ -0,0 +1,18 @@ +Tests: aaa, bbb, ccc + +Tests: danger, warning +Restrictions: rw-build-tree, needs-root, breaks-testbed + +Tests: depends +Depends: @, @builddeps@, extra-package + +Tests: dir +Tests-Directory: . + +Tests: feature +Features: + +Tests: class +Classes: self-test + +Test-Command: command arg1 arg2 |