aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@mandriva.org>2004-04-06 14:41:35 +0000
committerRafael Garcia-Suarez <rgarciasuarez@mandriva.org>2004-04-06 14:41:35 +0000
commitbf257bc422b2d2448888fba95cba4ea148aa97f9 (patch)
treea2c627003ea4feaf89e397f113fe3b3c2752477d
parentef428d6cb520165ab91952852563f3a973dce2db (diff)
downloadperl-URPM-bf257bc422b2d2448888fba95cba4ea148aa97f9.tar
perl-URPM-bf257bc422b2d2448888fba95cba4ea148aa97f9.tar.gz
perl-URPM-bf257bc422b2d2448888fba95cba4ea148aa97f9.tar.bz2
perl-URPM-bf257bc422b2d2448888fba95cba4ea148aa97f9.tar.xz
perl-URPM-bf257bc422b2d2448888fba95cba4ea148aa97f9.zip
Deprecate the pseudo-packages URPM::Build, URPM::Resolve and URPM::Signature.
Documentation fixes. Tidy up the tests (and add a few ones.)
-rw-r--r--URPM.pm34
-rw-r--r--t/rpmdb.t50
-rw-r--r--t/synthesis.t192
3 files changed, 152 insertions, 124 deletions
diff --git a/URPM.pm b/URPM.pm
index a17d7f3..9a72587 100644
--- a/URPM.pm
+++ b/URPM.pm
@@ -3,6 +3,12 @@ package URPM;
use strict;
use DynaLoader;
+# different files, but same package
+# require them here to avoid dependencies
+use URPM::Build;
+use URPM::Resolve;
+use URPM::Signature;
+
our @ISA = qw(DynaLoader);
our $VERSION = '0.94';
@@ -172,7 +178,7 @@ URPM - Perl module to manipulate RPM files
# loading and parsing a synthesis file
my $urpm = new URPM;
$urpm->parse_synthesis("synthesis.sample.cz");
- $a->traverse(sub {
+ $urpm->traverse(sub {
# retrieve all packages from the dependency list
# ...
});
@@ -238,6 +244,28 @@ and adds them to the URPM object. Allowed options are
keep_all_tags => 0 / 1
callback => sub { ... }
+=item $urpm->search($name, %options)
+
+Search an RPM by name or by part of name in the list of RPMs represented by
+this $urpm. The behaviour of the search is influenced by several options:
+
+ strict_name => 0 / 1
+ strict_fullname => 0 / 1
+ src => 0 / 1
+
+=item $urpm->traverse($callback)
+
+Executes the callback for each package in the depslist, passing a
+C<URPM::Package> object as argument the callback.
+
+=item $urpm->traverse_tag($tag, $names, $callback)
+
+$tag may be one of C<name>, C<whatprovides>, C<whatrequires>, C<whatconflicts>,
+C<group>, C<triggeredby>, or C<path>.
+$names is a reference to an array, holding the acceptable values of the said
+tag for the searched variables.
+Then, $callback is called for each matching package in the depslist.
+
=item $urpm->verify_rpm($file, %options)
Verifies an RPM file.
@@ -327,7 +355,7 @@ of an RPM package.
=item $package->compare($evr)
-=item $package->compare_pkg($lpkg, $rpkg)
+=item $package->compare_pkg($other_pkg)
=item $package->conf_files()
@@ -391,6 +419,8 @@ of an RPM package.
=item $package->fullname()
+Returns a 4 element list: name, version, release and architecture.
+
=item $package->get_tag($tagname)
=item $package->get_tag_modifiers($tagname)
diff --git a/t/rpmdb.t b/t/rpmdb.t
index 8d93fd2..cae396c 100644
--- a/t/rpmdb.t
+++ b/t/rpmdb.t
@@ -1,41 +1,45 @@
+#!/usr/bin/perl
use strict ;
use warnings ;
-
-sub ok {
- my ($no, $ok) = @_ ;
-
- print "ok $no\n" if $ok ;
- print "not ok $no\n" unless $ok ;
- printf "# Failed test at line %d\n", (caller)[2] unless $ok ;
-}
-
+use Test::More tests => 7;
use URPM;
-print "1..5\n";
-
-my ($count, @all_pkgs_extern, @all_pkgs);
+my ($count, @all_pkgs_extern, %all_pkgs, @all_pkgs);
+my ($pkg_perl, $count_perl, $pkg_perl_extern);
{
my $db;
- ok(1, $db = URPM::DB::open);
+ ok($db = URPM::DB::open, 'DB opened');
@all_pkgs_extern = sort { $a cmp $b } split '\n', `rpm -qa`;
- ok(2, @all_pkgs_extern > 0);
+ ok(@all_pkgs_extern > 0, 'There are RPMs');
$count = $db->traverse(sub {
- my ($pkg) = @_;
- my ($name, $version, $release, $arch) = $pkg->fullname;
- #- arch is void for -pubkey- package.
- push @all_pkgs, "$name-$version-$release";
- });
+ my ($pkg) = @_;
+ my ($name, $version, $release, $arch) = $pkg->fullname;
+ #- arch is void for -pubkey- package.
+ my $fullname = "$name-$version-$release";
+ $all_pkgs{$fullname}++;
+ if ($name eq 'perl') { $pkg_perl_extern = $fullname }
+ });
+ @all_pkgs = keys %all_pkgs;
+
+ $count_perl = $db->traverse_tag('name', ['perl'], sub {
+ my ($pkg) = @_;
+ my ($name, $version, $release) = $pkg->fullname;
+ $pkg_perl = "$name-$version-$release";
+ });
}
-ok(3, $count == @all_pkgs_extern);
-ok(4, $count == @all_pkgs);
+is($count, @all_pkgs_extern,
+ 'traversed same num of packages than given by rpm -qa');
+is($count, @all_pkgs,
+ 'traversed each package once');
+is($count_perl, 1, q(there's exactly 1 "perl" package));
+is($pkg_perl, $pkg_perl_extern, '... with the correct fullname');
my @all_pkgs_sorted = sort { $a cmp $b } @all_pkgs;
my $bad_pkgs = 0;
foreach (0..$#all_pkgs_sorted) {
$all_pkgs_sorted[$_] eq $all_pkgs_extern[$_] or ++$bad_pkgs;
}
-ok(5, $bad_pkgs == 0);
-
+is($bad_pkgs, 0, 'no mismatch between package lists');
diff --git a/t/synthesis.t b/t/synthesis.t
index 23102a7..4050493 100644
--- a/t/synthesis.t
+++ b/t/synthesis.t
@@ -2,142 +2,136 @@
use strict ;
use warnings ;
-
-sub ok {
- my ($no, $ok) = @_ ;
-
- print "ok $no\n" if $ok ;
- print "not ok $no\n" unless $ok ;
- printf "# Failed test at line %d\n", (caller)[2] unless $ok ;
-}
-
+use Test::More tests => 86;
use URPM;
my $file1 = 'synthesis.sample.cz';
-local *F;
-open F, "| gzip -9 >$file1";
-print F q{
+open my $f, "| gzip -9 >$file1";
+print $f q{
glibc-devel@provides@glibc-devel == 6:2.2.4-25mdk
glibc-devel@requires@/sbin/install-info@glibc == 2.2.4@kernel-headers@kernel-headers >= 2.2.1@/bin/sh@/bin/sh@/bin/sh@rpmlib(PayloadFilesHavePrefix) <= 4.0-1@rpmlib(CompressedFileNames) <= 3.0.4-1
glibc-devel@conflicts@texinfo < 3.11@gcc < 2.96-0.50mdk
glibc-devel@obsoletes@libc-debug@libc-headers@libc-devel@linuxthreads-devel@glibc-debug
glibc-devel@info@glibc-devel-2.2.4-25mdk.i586@6@45692097@Development/C
};
-close F;
+close $f;
END { unlink $file1 }
-print "1..80\n";
-
my $a = new URPM;
-ok(1, $a);
+ok($a);
my ($first, $end) = $a->parse_synthesis($file1);
-ok(2, $first == 0 && $end == 0);
-ok(3, @{$a->{depslist}} == 1);
-ok(4, keys(%{$a->{provides}}) == 3);
-ok(5, defined $a->{provides}{'glibc-devel'});
-ok(6, exists $a->{provides}{'/bin/sh'});
-ok(7, ! defined $a->{provides}{'/bin/sh'});
-ok(8, exists $a->{provides}{'/sbin/install-info'});
-ok(9, ! defined $a->{provides}{'/sbin/install-info'});
+ok($first == 0 && $end == 0);
+ok(@{$a->{depslist}} == 1);
+ok(keys(%{$a->{provides}}) == 3);
+ok(defined $a->{provides}{'glibc-devel'});
+ok(exists $a->{provides}{'/bin/sh'});
+ok(! defined $a->{provides}{'/bin/sh'});
+ok(exists $a->{provides}{'/sbin/install-info'});
+ok(! defined $a->{provides}{'/sbin/install-info'});
my $pkg = $a->{depslist}[0];
-ok(10, $pkg);
-ok(11, $pkg->name eq 'glibc-devel');
-ok(12, $pkg->version eq '2.2.4');
-ok(13, $pkg->release eq '25mdk');
-ok(14, $pkg->arch eq 'i586');
-ok(15, $pkg->fullname eq 'glibc-devel-2.2.4-25mdk.i586');
+ok($pkg);
+ok($pkg->name eq 'glibc-devel');
+ok($pkg->version eq '2.2.4');
+ok($pkg->release eq '25mdk');
+ok($pkg->arch eq 'i586');
+ok($pkg->fullname eq 'glibc-devel-2.2.4-25mdk.i586');
+ok(!defined $pkg->buildarchs);
+ok(!defined $pkg->buildhost);
+is($pkg->buildtime,0);
+ok(!defined $pkg->changelog_name);
+ok(!defined $pkg->changelog_text);
+ok(!defined $pkg->changelog_time);
my ($name, $version, $release, $arch, @l) = $pkg->fullname;
-ok(16, @l == 0);
-ok(17, $name eq 'glibc-devel');
-ok(18, $version eq '2.2.4');
-ok(19, $release eq '25mdk');
-ok(20, $arch eq 'i586');
-
-ok(21, $pkg->epoch == 6);
-ok(22, $pkg->size == 45692097);
-ok(23, $pkg->group eq 'Development/C');
-ok(24, $pkg->filename eq 'glibc-devel-2.2.4-25mdk.i586.rpm');
-ok(25, defined $pkg->id);
-ok(26, $pkg->id == 0);
-ok(27, $pkg->set_id(6) == 0);
-ok(28, $pkg->id == 6);
-ok(29, $pkg->set_id == 6);
-ok(30, ! defined $pkg->id);
-ok(31, ! defined $pkg->set_id(0));
-ok(32, defined $pkg->id);
-ok(33, $pkg->id == 0);
+ok(@l == 0);
+ok($name eq 'glibc-devel');
+ok($version eq '2.2.4');
+ok($release eq '25mdk');
+ok($arch eq 'i586');
+
+ok($pkg->epoch == 6);
+ok($pkg->size == 45692097);
+ok($pkg->group eq 'Development/C');
+ok($pkg->filename eq 'glibc-devel-2.2.4-25mdk.i586.rpm');
+ok(defined $pkg->id);
+ok($pkg->id == 0);
+ok($pkg->set_id(6) == 0);
+ok($pkg->id == 6);
+ok($pkg->set_id == 6);
+ok(! defined $pkg->id);
+ok(! defined $pkg->set_id(0));
+ok(defined $pkg->id);
+ok($pkg->id == 0);
my @obsoletes = $pkg->obsoletes;
-ok(34, @obsoletes == 5);
-ok(35, $obsoletes[0] eq 'libc-debug');
-ok(36, $obsoletes[4] eq 'glibc-debug');
+ok(@obsoletes == 5);
+ok($obsoletes[0] eq 'libc-debug');
+ok($obsoletes[4] eq 'glibc-debug');
my @conflicts = $pkg->conflicts;
-ok(37, @conflicts == 2);
-ok(38, $conflicts[0] eq 'texinfo < 3.11');
-ok(39, $conflicts[1] eq 'gcc < 2.96-0.50mdk');
+ok(@conflicts == 2);
+ok($conflicts[0] eq 'texinfo < 3.11');
+ok($conflicts[1] eq 'gcc < 2.96-0.50mdk');
my @requires = $pkg->requires;
-ok(40, @requires == 9);
-ok(41, $requires[0] eq '/sbin/install-info');
-ok(42, $requires[8] eq 'rpmlib(CompressedFileNames) <= 3.0.4-1');
+ok(@requires == 9);
+ok($requires[0] eq '/sbin/install-info');
+ok($requires[8] eq 'rpmlib(CompressedFileNames) <= 3.0.4-1');
my @provides = $pkg->provides;
-ok(43, @provides == 1);
-ok(44, $provides[0] eq 'glibc-devel == 6:2.2.4-25mdk');
+ok(@provides == 1);
+ok($provides[0] eq 'glibc-devel == 6:2.2.4-25mdk');
my @files = $pkg->files;
-ok(45, @files == 0);
-
-ok(46, $pkg->compare("6:2.2.4-25mdk") == 0);
-ok(47, $pkg->compare("2.2.4-25mdk") == 0);
-ok(48, $pkg->compare("2.2.4") == 0);
-ok(49, $pkg->compare("2.2.3") > 0);
-ok(50, $pkg->compare("2.2") > 0);
-ok(51, $pkg->compare("2") > 0);
-ok(52, $pkg->compare("2.2.4.0") < 0);
-ok(53, $pkg->compare("2.2.5") < 0);
-ok(54, $pkg->compare("2.1.7") > 0);
-ok(55, $pkg->compare("2.3.1") < 0);
-ok(56, $pkg->compare("2.2.31") < 0);
-ok(57, $pkg->compare("2.2.4-25") > 0);
-ok(58, $pkg->compare("2.2.4-25.1mdk") < 0);
-ok(59, $pkg->compare("2.2.4-24mdk") > 0);
-ok(60, $pkg->compare("2.2.4-26mdk") < 0);
-ok(61, $pkg->compare("6:2.2.4-26mdk") < 0);
-ok(62, $pkg->compare("7:2.2.4-26mdk") < 0);
-ok(63, $pkg->compare("7:2.2.4-24mdk") < 0);
-
-ok(64, $a->traverse() == 1);
+ok(@files == 0);
+
+ok($pkg->compare("6:2.2.4-25mdk") == 0);
+ok($pkg->compare("2.2.4-25mdk") == 0);
+ok($pkg->compare("2.2.4") == 0);
+ok($pkg->compare("2.2.3") > 0);
+ok($pkg->compare("2.2") > 0);
+ok($pkg->compare("2") > 0);
+ok($pkg->compare("2.2.4.0") < 0);
+ok($pkg->compare("2.2.5") < 0);
+ok($pkg->compare("2.1.7") > 0);
+ok($pkg->compare("2.3.1") < 0);
+ok($pkg->compare("2.2.31") < 0);
+ok($pkg->compare("2.2.4-25") > 0);
+ok($pkg->compare("2.2.4-25.1mdk") < 0);
+ok($pkg->compare("2.2.4-24mdk") > 0);
+ok($pkg->compare("2.2.4-26mdk") < 0);
+ok($pkg->compare("6:2.2.4-26mdk") < 0);
+ok($pkg->compare("7:2.2.4-26mdk") < 0);
+ok($pkg->compare("7:2.2.4-24mdk") < 0);
+
+ok($a->traverse() == 1);
my $test = 0;
-ok(65, $a->traverse(sub { my ($pkg) = @_; $test = $pkg->name eq 'glibc-devel' }) == 1);
-ok(66, $test);
-ok(67, $a->traverse_tag('name', [ 'glibc-devel' ]) == 1);
-ok(68, $a->traverse_tag('name', [ 'glibc' ]) == 0);
+ok($a->traverse(sub { my ($pkg) = @_; $test = $pkg->name eq 'glibc-devel' }) == 1);
+ok($test);
+ok($a->traverse_tag('name', [ 'glibc-devel' ]) == 1);
+ok($a->traverse_tag('name', [ 'glibc' ]) == 0);
$test = 0;
-ok(69, $a->traverse_tag('name', [ 'glibc-devel' ], sub { my ($pkg) = @_; $test = $pkg->name eq 'glibc-devel' }) == 1);
-ok(70, $test);
+ok($a->traverse_tag('name', [ 'glibc-devel' ], sub { my ($pkg) = @_; $test = $pkg->name eq 'glibc-devel' }) == 1);
+ok($test);
@conflicts = $pkg->conflicts_nosense;
-ok(71, @conflicts == 2);
-ok(72, $conflicts[0] eq 'texinfo');
-ok(73, $conflicts[1] eq 'gcc');
+ok(@conflicts == 2);
+ok($conflicts[0] eq 'texinfo');
+ok($conflicts[1] eq 'gcc');
@requires = $pkg->requires_nosense;
-ok(74, @requires == 9);
-ok(75, $requires[0] eq '/sbin/install-info');
-ok(76, $requires[1] eq 'glibc');
-ok(77, $requires[3] eq 'kernel-headers');
-ok(78, $requires[8] eq 'rpmlib(CompressedFileNames)');
+ok(@requires == 9);
+ok($requires[0] eq '/sbin/install-info');
+ok($requires[1] eq 'glibc');
+ok($requires[3] eq 'kernel-headers');
+ok($requires[8] eq 'rpmlib(CompressedFileNames)');
@provides = $pkg->provides_nosense;
-ok(79, @provides == 1);
-ok(80, $provides[0] eq 'glibc-devel');
-
+ok(@provides == 1);
+ok($provides[0] eq 'glibc-devel');