Document mock mode
[Fedora-Rebuild.git] / t / 04is_buildable.t
blobc79ab849d6ec5fc7510bb24ee57fbf0561dfd150
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
5 use Test::Simple tests => 8;
7 use Fedora::Rebuild::Solver;
8 use Fedora::Rebuild::Set::Package;
9 use Fedora::Rebuild::Package;
10 use Fedora::Rebuild::RPM;
11 use threads::shared;
13 # Prepare packages
14 # Create and return package with one binary package that always provides its
15 # unversioned name.
16 sub build_package {
17 my ($name, $provides, $runrequires, $buildrequires) = @_;
19 my $package = Fedora::Rebuild::Package->new(
20 'name' => $name,
21 workdir => 't/tmp',
22 dist => 'foo',
23 target => 'foo',
24 message => 'foo',
27 $package->provides(shared_clone(
29 $name => {
30 $name => [[Fedora::Rebuild::RPM::ANY, '']],
31 %$provides
34 ));
35 $package->runrequires(shared_clone(
36 { $name => $runrequires }
37 ));
38 $package->requires(shared_clone($buildrequires));
39 return $package;
42 my $B1 = build_package(
43 'B1',
44 {},
45 {},
46 { 'a' => [[Fedora::Rebuild::RPM::ANY, '']] }
49 my $B2 = build_package(
50 'B2',
51 {},
52 {},
53 {'a' => [[Fedora::Rebuild::RPM::ANY, '']]}
56 my $C = build_package(
57 'C',
59 'dual' =>
60 [[Fedora::Rebuild::RPM::EQUAL|Fedora::Rebuild::RPM::GREATER, '1']],
62 {},
63 { 'nonexistent' => [[Fedora::Rebuild::RPM::ANY, '']] }
66 my $a = build_package(
67 'a',
69 'dual' =>
70 [[Fedora::Rebuild::RPM::EQUAL|Fedora::Rebuild::RPM::GREATER, '1']],
72 {},
76 my $b1 = build_package(
77 'b1',
78 {},
79 { 'a' => [[Fedora::Rebuild::RPM::ANY, '']] },
80 {},
83 my $b2 = build_package(
84 'b2',
85 {},
86 {'a' => [[Fedora::Rebuild::RPM::ANY, '']]},
87 {},
90 my $c = build_package(
91 'c',
93 'dual' =>
94 [[Fedora::Rebuild::RPM::EQUAL|Fedora::Rebuild::RPM::GREATER, '1']],
96 { 'nonexistent' => [[Fedora::Rebuild::RPM::ANY, '']] },
97 {},
100 my $D = build_package(
101 'D',
104 {'b1' => [[Fedora::Rebuild::RPM::ANY, '']]},
107 my $E = build_package(
108 'E',
112 'b1' => [[Fedora::Rebuild::RPM::ANY, '']],
113 'b2' => [[Fedora::Rebuild::RPM::ANY, '']],
117 my $F = build_package(
118 'F',
122 'a' => [[Fedora::Rebuild::RPM::ANY, '']],
123 'dual' => [[Fedora::Rebuild::RPM::ANY, '']],
127 my $G = build_package(
128 'G',
132 'dual' => [
133 [Fedora::Rebuild::RPM::GREATER, '1'],
134 [Fedora::Rebuild::RPM::LESS, '1'],
135 [Fedora::Rebuild::RPM::GREATER, '2'],
140 my $H = build_package(
141 'H',
144 { 'c' => [[Fedora::Rebuild::RPM::ANY, '']] },
147 # Prepare set of packages
148 my $packages = Fedora::Rebuild::Set::Package->new();
149 $packages->insert($B1);
150 $packages->insert($B2);
151 $packages->insert($C);
152 $packages->insert($a);
153 $packages->insert($b1);
154 $packages->insert($b2);
155 $packages->insert($c);
156 $packages->insert($D);
157 $packages->insert($E);
158 $packages->insert($F);
159 $packages->insert($G);
160 $packages->insert($H);
162 # Prepare solver
163 my $solver = Fedora::Rebuild::Solver->new(packages => $packages,
164 dependencyfilter => sub {0});
166 # Test
167 my $message;
169 # Direct dependencies
170 ok($solver->is_buildable($a, \$message),
171 "a build-requires nothing: $message");
172 ok($solver->is_buildable($B1, \$message),
173 "B1 build-requires a: $message");
174 ok(! $solver->is_buildable($C, \$message),
175 "C build-requires nonexistent: $message");
177 # Indirect dependencies
178 ok($solver->is_buildable($D, \$message),
179 "D build-requires b1 that requires a: $message");
180 ok($solver->is_buildable($E, \$message),
181 "E build-requires b1 and b2, both require a: $message");
182 ok(! $solver->is_buildable($H, \$message),
183 "H build-requires c that is not installable: $message");
185 # More provides, one is not installable.
186 # XXX: This is not deterministic as it depend on hash ordering.
187 ok($solver->is_buildable($F, \$message),
188 "F build-requires a and dual, dual is provided by installable a and " .
189 "uninstallable c: $message");
191 # More provides, one is not installable, but all requires cannot be satisfied
192 # at the same time.
193 ok(! $solver->is_buildable($G, \$message),
194 "G build-requires versioned dual's, they cannot be satisfied at the " .
195 "same time: $message");