[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[lintian] 01/01: L::Relation: Fix some broken corner-cases in implies



This is an automated email from the git hooks/post-receive script.

nthykier pushed a commit to branch master
in repository lintian.

commit b1e788192f1d5bcd25be34dfa4d050f48ed06211
Author: Niels Thykier <niels@thykier.net>
Date:   Sat Apr 9 15:42:09 2016 +0000

    L::Relation: Fix some broken corner-cases in implies
    
    Signed-off-by: Niels Thykier <niels@thykier.net>
---
 debian/changelog                        |  3 +++
 lib/Lintian/Relation.pm                 | 20 +++++++++---------
 t/scripts/Lintian/Relation/07-implies.t | 36 +++++++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+), 10 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index a676e74..70caa31 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -37,6 +37,9 @@ lintian (2.5.44) UNRELEASED; urgency=medium
   * lib/Lintian/Check.pm:
     + [JW,NT] Flag a duplicate word as a spelling error.  This affects
       several tags plus spellintian.  (Closes: #800476)
+  * lib/Lintian/Relation.pm:
+    + [JW,NT] Fix broken implication with "P (<< V)" relations.
+      (Closes: #819560)
 
  -- Niels Thykier <niels@thykier.net>  Sun, 03 Apr 2016 18:48:59 +0000
 
diff --git a/lib/Lintian/Relation.pm b/lib/Lintian/Relation.pm
index a71c066..85ddde7 100644
--- a/lib/Lintian/Relation.pm
+++ b/lib/Lintian/Relation.pm
@@ -542,7 +542,7 @@ sub implies_element {
         } elsif ($$p[2] eq '>=') {
             return versions_gt($$p[3], $$q[3]) ? 0 : undef;
         } elsif ($$p[2] eq '=') {
-            return versions_equal($$p[3], $$q[3]);
+            return versions_equal($$p[3], $$q[3]) ? 1 : 0;
         }
     }
 
@@ -554,7 +554,7 @@ sub implies_element {
         } elsif ($$p[2] eq '>=') {
             return versions_gt($$p[3], $$q[3]) ? 0 : undef;
         } elsif ($$p[2] eq '=') {
-            return versions_lte($$p[3], $$q[3]);
+            return versions_lte($$p[3], $$q[3]) ? 1 : 0;
         } else {
             return versions_lte($$p[3], $$q[3]) ? 1 : undef;
         }
@@ -566,9 +566,9 @@ sub implies_element {
         if ($$p[2] eq '>>' or $$p[2] eq '>=') {
             return versions_gte($$p[3], $$p[3]) ? 0 : undef;
         } elsif ($$p[2] eq '<<') {
-            return versions_lte($$p[3], $$q[3]);
+            return versions_lte($$p[3], $$q[3]) ? 1 : undef;
         } elsif ($$p[2] eq '=') {
-            return versions_lt($$p[3], $$q[3]);
+            return versions_lt($$p[3], $$q[3]) ? 1 : 0;
         } else {
             return versions_lt($$p[3], $$q[3]) ? 1 : undef;
         }
@@ -581,7 +581,7 @@ sub implies_element {
         } elsif ($$p[2] eq '<=') {
             return versions_lt($$p[3], $$q[3]) ? 0 : undef;
         } elsif ($$p[2] eq '=') {
-            return versions_gte($$p[3], $$q[3]);
+            return versions_gte($$p[3], $$q[3]) ? 1 : 0;
         } else {
             return versions_gte($$p[3], $$q[3]) ? 1 : undef;
         }
@@ -590,9 +590,9 @@ sub implies_element {
         if ($$p[2] eq '<<' or $$p[2] eq '<=') {
             return versions_lte($$p[3], $$q[3]) ? 0 : undef;
         } elsif ($$p[2] eq '>>') {
-            return versions_gte($$p[3], $$q[3]);
+            return versions_gte($$p[3], $$q[3]) ? 1 : undef;
         } elsif ($$p[2] eq '=') {
-            return versions_gt($$p[3], $$q[3]);
+            return versions_gt($$p[3], $$q[3]) ? 1 : 0;
         } else {
             return versions_gt($$p[3], $$q[3]) ? 1 : undef;
         }
@@ -718,10 +718,10 @@ and pass that in as RELATION instead of the string.
 # do most of the work.
 sub implies_element_inverse {
     my ($self, $p, $q) = @_;
-    my $result = $self->implies_element($q, $p);
+    my $result = $self->implies_element($p, $q);
 
-    return not $result if defined $result;
-    return;
+    return if not defined($result);
+    return $result ? 0 : 1;
 }
 
 # This internal function does the heavily lifting for AND, OR, and NOT
diff --git a/t/scripts/Lintian/Relation/07-implies.t b/t/scripts/Lintian/Relation/07-implies.t
new file mode 100644
index 0000000..444e2cf
--- /dev/null
+++ b/t/scripts/Lintian/Relation/07-implies.t
@@ -0,0 +1,36 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Lintian::Relation;
+use Test::More;
+
+my @TESTS = (
+    # A, B, A->I(B), A->I_I(B), B->I(A), B->I_I(A), line
+    # - with "I" being "implies" and "I_I" being "implies_inverse".
+    ['foo (= 1.0)', 'foo (= 2.0)', 0, 1, 0, 1, __LINE__],
+    ['foo (>= 1.0)', 'foo (= 2.0)', undef, undef, 1, 0, __LINE__],
+    ['foo (>= 2.0)', 'foo (>= 1.0)', 1, 0, undef, undef, __LINE__],
+    ['foo (>> 1.0)', 'foo (>= 1.0)', 1, 0, undef, undef, __LINE__],
+    ['foo (>> 2.0)', 'foo (>> 1.0)', 1, 0, undef, undef, __LINE__],
+    ['foo (<= 1.0)', 'foo (<= 2.0)', 1, 0, undef, undef, __LINE__],
+    ['foo (<< 1.0)', 'foo (<= 1.0)', 1, 0, undef, undef, __LINE__],
+    ['foo (<< 1.0)', 'foo (<< 2.0)', 1, 0, undef, undef, __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 $a = Lintian::Relation->new($a_raw);
+    my $b = Lintian::Relation->new($b_raw);
+    is($a->implies($b), $a_i_b, "$a_raw implies $b_raw (case 1, line $lno)");
+    is($a->implies_inverse($b),
+        $a_ii_b, "$test->[0] implies inverse $test->[1] (case 2, line $lno)");
+
+    is($b->implies($a), $b_i_a,
+        "$b_raw implies $a_raw (case 3, line $test->[6])");
+    is($b->implies_inverse($a),
+        $b_ii_a, "$b_raw implies inverse $a_raw (case 4, line $lno)");
+}
+

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/lintian/lintian.git


Reply to: