Use createrepo_c instead of createrepo
[Fedora-Rebuild.git] / t / 02is_satisfied.t
blob23d8cf14c62aaa83d928a7637b6f71d02a22c7cd
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
5 use Test::Simple tests => 4 + 3*5*5 + 3;
7 use Fedora::Rebuild::RPM;
9 # The ok() labels have format "REQUIRES ? COMMA_SEPARATED_PROVIDES".
11 # Non-flag-qualified cases
12 ok(
13 Fedora::Rebuild::RPM::is_satisfied(
14 'a', Fedora::Rebuild::RPM::ANY, '',
16 'a' => [ [Fedora::Rebuild::RPM::ANY, ''] ]
18 ), 'a ? a'
21 ok(
22 ! Fedora::Rebuild::RPM::is_satisfied(
23 'a', Fedora::Rebuild::RPM::ANY, '',
25 'b' => [ [Fedora::Rebuild::RPM::ANY, ''] ]
27 ), 'a ? b'
30 ok(
31 Fedora::Rebuild::RPM::is_satisfied(
32 'a', Fedora::Rebuild::RPM::ANY, '',
34 'b' => [ [Fedora::Rebuild::RPM::ANY, ''] ],
35 'a' => [ [Fedora::Rebuild::RPM::ANY, ''] ],
36 'c' => [ [Fedora::Rebuild::RPM::ANY, ''] ]
38 ), 'a ? b, a, c'
41 ok(
42 ! Fedora::Rebuild::RPM::is_satisfied(
43 'a', Fedora::Rebuild::RPM::ANY, '',
46 ), 'a ? '
50 # A matrix case. See module comments for the matrices. There should be 3*5*5
51 # cases in total.
52 sub test_matrix_cell {
53 my ($order, $rflag, $pflag, $result) = @_;
55 my ($rversion, $pversion) = ('1', '1');
56 if ($order < 0) {
57 $rversion = '0';
58 } elsif ($order > 0) {
59 $rversion = '2';
62 ok(
63 $result == Fedora::Rebuild::RPM::is_satisfied(
64 'a', $rflag, $rversion,
66 'a' => [ [$pflag, $pversion] ]
69 'a ' . Fedora::Rebuild::RPM::flag_as_string($rflag) . " $rversion" .
70 ' ? a ' . Fedora::Rebuild::RPM::flag_as_string($pflag) .
71 " $pversion"
75 # Test whole matrix of flags (5*5) for given version order
76 sub test_matrix {
77 my ($order, @results) = @_;
79 my @flags = (
80 Fedora::Rebuild::RPM::LESS,
81 Fedora::Rebuild::RPM::LESS|Fedora::Rebuild::RPM::EQUAL,
82 Fedora::Rebuild::RPM::EQUAL,
83 Fedora::Rebuild::RPM::GREATER|Fedora::Rebuild::RPM::EQUAL,
84 Fedora::Rebuild::RPM::GREATER
87 my $i = 0;
88 for my $rflag (@flags) {
89 for my $pflag (@flags) {
90 test_matrix_cell($order, $rflag, $pflag, $results[$i++]);
96 test_matrix(
97 # (labelCompare($rversion,$pversion) = $order) == 0:
99 # pflag
100 # < <= == >= >
101 1, 1, 0, 0, 0, # rflag <
102 1, 1, 1, 1, 0, # <=
103 0, 1, 1, 1, 0, # ==
104 0, 1, 1, 1, 1, # =>
105 0, 0, 0, 1, 1 # >
108 test_matrix(
109 # (labelCompare($rversion,$pversion) = $order) > 0:
111 # pflag
112 # < <= == >= >
113 1, 1, 1, 1, 1, # rflag <
114 1, 1, 1, 1, 1, # <=
115 0, 0, 0, 1, 1, # ==
116 0, 0, 0, 1, 1, # =>
117 0, 0, 0, 1, 1 # >
120 test_matrix(
121 # (labelCompare($rversion,$pversion) = $order) < 0:
123 # pflag
124 # < <= == >= >
125 1, 1, 0, 0, 0, # rflag <
126 1, 1, 0, 0, 0, # <=
127 1, 1, 0, 0, 0, # ==
128 1, 1, 1, 1, 1, # =>
129 1, 1, 1, 1, 1 # >
133 # Some generic tests
135 Fedora::Rebuild::RPM::is_satisfied(
136 'a', Fedora::Rebuild::RPM::GREATER|Fedora::Rebuild::RPM::EQUAL, '1',
138 'a' => [ [Fedora::Rebuild::RPM::ANY, ''] ]
140 ), 'a >= 1 ? a'
144 Fedora::Rebuild::RPM::is_satisfied(
145 'a', Fedora::Rebuild::RPM::GREATER|Fedora::Rebuild::RPM::EQUAL, '1',
147 'a' => [ [Fedora::Rebuild::RPM::EQUAL, '2'] ]
149 ), 'a >= 1 ? a = 2'
153 ! Fedora::Rebuild::RPM::is_satisfied(
154 'a', Fedora::Rebuild::RPM::GREATER|Fedora::Rebuild::RPM::EQUAL, '1',
156 'a' => [ [Fedora::Rebuild::RPM::EQUAL, '0'] ]
158 ), 'a >= 1 ? a = 0'