summaryrefslogtreecommitdiffstats
path: root/t/scripts/Lintian/Relation
diff options
context:
space:
mode:
Diffstat (limited to 't/scripts/Lintian/Relation')
-rwxr-xr-xt/scripts/Lintian/Relation/01-basic.t19
-rwxr-xr-xt/scripts/Lintian/Relation/02-architecture.t19
-rwxr-xr-xt/scripts/Lintian/Relation/03-duplicates.t29
-rwxr-xr-xt/scripts/Lintian/Relation/04-multiarch.t64
-rwxr-xr-xt/scripts/Lintian/Relation/05-invalid.t66
-rwxr-xr-xt/scripts/Lintian/Relation/06-build-profiles.t24
-rw-r--r--t/scripts/Lintian/Relation/07-implies.t46
7 files changed, 267 insertions, 0 deletions
diff --git a/t/scripts/Lintian/Relation/01-basic.t b/t/scripts/Lintian/Relation/01-basic.t
new file mode 100755
index 0000000..7838957
--- /dev/null
+++ b/t/scripts/Lintian/Relation/01-basic.t
@@ -0,0 +1,19 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 2;
+
+use Lintian::Relation;
+
+my $relation = Lintian::Relation->new->load('pkgA, altA | altB');
+
+ok($relation->satisfies('pkgA'), 'Satisfies');
+ok(!$relation->satisfies('altA'), 'Satisfies alt');
+
+# Local Variables:
+# indent-tabs-mode: nil
+# cperl-indent-level: 4
+# End:
+# vim: syntax=perl sw=4 sts=4 sr et
diff --git a/t/scripts/Lintian/Relation/02-architecture.t b/t/scripts/Lintian/Relation/02-architecture.t
new file mode 100755
index 0000000..3bdefbe
--- /dev/null
+++ b/t/scripts/Lintian/Relation/02-architecture.t
@@ -0,0 +1,19 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More tests => 2;
+
+use Lintian::Relation;
+
+my $relation
+ = Lintian::Relation->new->load_norestriction('pkgA [i386], pkgB [amd64]');
+
+ok($relation->satisfies('pkgA:any'), 'Implies arch alt [i386]');
+ok($relation->satisfies('pkgB:any'), 'Implies arch alt [amd64]');
+
+# Local Variables:
+# indent-tabs-mode: nil
+# cperl-indent-level: 4
+# End:
+# vim: syntax=perl sw=4 sts=4 sr et
diff --git a/t/scripts/Lintian/Relation/03-duplicates.t b/t/scripts/Lintian/Relation/03-duplicates.t
new file mode 100755
index 0000000..84d22c6
--- /dev/null
+++ b/t/scripts/Lintian/Relation/03-duplicates.t
@@ -0,0 +1,29 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 2;
+
+use Lintian::Relation;
+
+my $relation_a
+ = Lintian::Relation->new->load_norestriction(
+ 'pkgA, pkgB, pkgC, pkgA | pkgD');
+
+my $relation_b
+ = Lintian::Relation->new->load_norestriction(
+ 'pkgA, pkgB, pkgC, pkgD | pkgE');
+
+is_deeply(
+ $relation_a->redundancies,
+ (['pkgA:any', 'pkgA:any | pkgD:any']),
+ 'Find redundancies'
+);
+is($relation_b->redundancies, 0, 'No redundancies');
+
+# Local Variables:
+# indent-tabs-mode: nil
+# cperl-indent-level: 4
+# End:
+# vim: syntax=perl sw=4 sts=4 sr et
diff --git a/t/scripts/Lintian/Relation/04-multiarch.t b/t/scripts/Lintian/Relation/04-multiarch.t
new file mode 100755
index 0000000..7f18b6c
--- /dev/null
+++ b/t/scripts/Lintian/Relation/04-multiarch.t
@@ -0,0 +1,64 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More tests => 12;
+
+use Lintian::Relation;
+
+my $orig = 'pkgA:any, pkgB, pkgC:i386';
+my $relation = Lintian::Relation->new->load($orig);
+
+ok($relation->satisfies('pkgA:any'), 'pkgA:any satisfies pkgA:any');
+
+ok($relation->satisfies('pkgB'), 'pkgB satisfies pkgB');
+
+ok(!$relation->satisfies('pkgC'), 'pkgC:i386 does not satisfy pkgC');
+ok($relation->satisfies('pkgC:i386'), 'pkgC:i386 satisfies pkgC:i386');
+
+ok($relation->satisfies('pkgB:any'), 'pkgB satisfies pkgB:any');
+
+ok(!$relation->satisfies('pkgA'), 'pkgA:any does not satisfy pkgA');
+
+ok(!$relation->satisfies('pkgC:any'), 'pkgC:i386 does not satisfy pkgC:any');
+
+is($relation->to_string, $orig, 'reconstituted eq original');
+
+my @redundancies1
+ = Lintian::Relation->new->load('pkgD, pkgD:any')->redundancies;
+is_deeply(
+ \@redundancies1,
+ [['pkgD', 'pkgD:any']],
+ 'pkgD and pkgD:any are redundant'
+);
+
+TODO: {
+ local $TODO = ':X => :Y cases are not implemented (in general)';
+
+ my @redundancies2
+ = Lintian::Relation->new->load('pkgD:i386, pkgD:any')->redundancies;
+ is_deeply(
+ \@redundancies2,
+ [['pkgD:i386', 'pkgD:any']],
+ 'pkgD:i386 and pkgD:any are redundant'
+ );
+}
+
+my @redundancies3
+ = Lintian::Relation->new->load('pkgD:i386, pkgD')->redundancies;
+is_deeply(\@redundancies3, [],'pkgD:i386 and pkgD are not redundant');
+
+my @redundancies4
+ = Lintian::Relation->new->load('pkgD:i386, pkgD:i386 (>= 1.0)')
+ ->redundancies;
+is_deeply(
+ \@redundancies4,
+ [['pkgD:i386', 'pkgD:i386 (>= 1.0)']],
+ 'Can detect pkgD:i386 redundancies'
+);
+
+# Local Variables:
+# indent-tabs-mode: nil
+# cperl-indent-level: 4
+# End:
+# vim: syntax=perl sw=4 sts=4 sr et
diff --git a/t/scripts/Lintian/Relation/05-invalid.t b/t/scripts/Lintian/Relation/05-invalid.t
new file mode 100755
index 0000000..9b42d62
--- /dev/null
+++ b/t/scripts/Lintian/Relation/05-invalid.t
@@ -0,0 +1,66 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More;
+
+use Lintian::Relation;
+
+test_relation(
+ 'pkg%any (>= 1.0) , pkgB | _gf , pkgC(>=2.0)',
+ 'satisfied' => [
+ 'pkgB | _gf', # partly unparsable, but identity holds
+ 'pkgC (>= 1.0)', # regular entry
+ ],
+ 'not-satisfied' => [
+ 'pkg', # unparsable
+ 'pkg%any', # unparsable
+ 'pkgB', # OR relation with unparsable entry
+ '_gf', # OR relation
+ ],
+ 'unparsable' => ['_gf', 'pkg%any (>= 1.0)'],
+ 'reconstituted' => 'pkg%any (>= 1.0), pkgB | _gf, pkgC (>= 2.0)'
+);
+
+done_testing;
+
+sub test_relation {
+ my ($text, %tests) = @_;
+
+ my $relation_under_test = Lintian::Relation->new->load($text);
+
+ my $tests = 0;
+ if (my $reconstituted = $tests{'reconstituted'}) {
+ is($relation_under_test->to_string,
+ $reconstituted, "Reconstitute $text");
+ $tests++;
+ }
+
+ for my $other_relation (@{$tests{'satisfied'} // [] }) {
+ ok($relation_under_test->satisfies($other_relation),
+ "'$text' satisfies '$other_relation'");
+ $tests++;
+ }
+
+ for my $other_relation (@{$tests{'not-satisfied'} // [] }) {
+ ok(
+ !$relation_under_test->satisfies($other_relation),
+ "'$text' does NOT satisfy '$other_relation'"
+ );
+ $tests++;
+ }
+
+ if (my $unparsable = $tests{'unparsable'}) {
+ my @actual = $relation_under_test->unparsable_predicates;
+ is_deeply(\@actual, $unparsable, "Unparsable entries for '$text'");
+ }
+
+ cmp_ok($tests, '>=', 1, "Ran at least one test on '$text'");
+ return;
+}
+
+# Local Variables:
+# indent-tabs-mode: nil
+# cperl-indent-level: 4
+# End:
+# vim: syntax=perl sw=4 sts=4 sr et
diff --git a/t/scripts/Lintian/Relation/06-build-profiles.t b/t/scripts/Lintian/Relation/06-build-profiles.t
new file mode 100755
index 0000000..824572d
--- /dev/null
+++ b/t/scripts/Lintian/Relation/06-build-profiles.t
@@ -0,0 +1,24 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More tests => 3;
+
+use Lintian::Relation;
+
+my $relation = Lintian::Relation->new->load_norestriction(
+ 'pkgA (<= 1.0) <stage1 nocheck> <nobiarch>, pkgB (<< 1.0) <!nodoc>');
+
+ok($relation->satisfies('pkgA:any'),
+ 'Satisfies restrictions <stage1 nocheck> <nobiarch>');
+ok($relation->satisfies('pkgB:any'), 'Satisfies restriction <!nodoc>');
+
+my $rel = Lintian::Relation->new->load('pkgC <foo bar> <baz>');
+
+is($rel->to_string, 'pkgC <foo bar> <baz>', 'Reconstitute pkgC');
+
+# Local Variables:
+# indent-tabs-mode: nil
+# cperl-indent-level: 4
+# End:
+# vim: syntax=perl sw=4 sts=4 sr et
diff --git a/t/scripts/Lintian/Relation/07-implies.t b/t/scripts/Lintian/Relation/07-implies.t
new file mode 100644
index 0000000..85c7f74
--- /dev/null
+++ b/t/scripts/Lintian/Relation/07-implies.t
@@ -0,0 +1,46 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+
+use Lintian::Relation;
+
+my @TESTS = (
+ # A, B, A->I(B), A->I_I(B), B->I(A), B->I_I(A), line
+ # - with "I" being "satisfies" and "I_I" being "satisfies_inverse".
+ ['foo (= 1.0)', 'foo (= 2.0)', 0, 1, 0, 1, __LINE__],
+ ['foo (>= 1.0)', 'foo (= 2.0)', 0, 0, 1, 0, __LINE__],
+ ['foo (>= 2.0)', 'foo (>= 1.0)', 1, 0, 0, 0, __LINE__],
+ ['foo (>> 1.0)', 'foo (>= 1.0)', 1, 0, 0, 0, __LINE__],
+ ['foo (>> 2.0)', 'foo (>> 1.0)', 1, 0, 0, 0, __LINE__],
+ ['foo (<= 1.0)', 'foo (<= 2.0)', 1, 0, 0, 0, __LINE__],
+ ['foo (<< 1.0)', 'foo (<= 1.0)', 1, 0, 0, 0, __LINE__],
+ ['foo (<< 1.0)', 'foo (<< 2.0)', 1, 0, 0, 0, __LINE__],
+);
+
+plan tests => scalar(@TESTS) * 4;
+
+for my $test (@TESTS) {
+ my ($a_raw, $b_raw, $a_i_b, $a_ii_b, $b_i_a, $b_ii_a, $lno) = @{$test};
+
+ my $relation_a = Lintian::Relation->new->load($a_raw);
+ my $relation_b = Lintian::Relation->new->load($b_raw);
+
+ is($relation_a->satisfies($relation_b),
+ $a_i_b, "$a_raw satisfies $b_raw (case 1, line $lno)");
+ is($relation_a->satisfies_inverse($relation_b),
+ $a_ii_b,"$test->[0] satisfies inverse $test->[1] (case 2, line $lno)");
+
+ is($relation_b->satisfies($relation_a),
+ $b_i_a,"$b_raw satisfies $a_raw (case 3, line $test->[6])");
+ is($relation_b->satisfies_inverse($relation_a),
+ $b_ii_a, "$b_raw satisfies inverse $a_raw (case 4, line $lno)");
+}
+
+# Local Variables:
+# indent-tabs-mode: nil
+# cperl-indent-level: 4
+# End:
+# vim: syntax=perl sw=4 sts=4 sr et