Document mock mode
[Fedora-Rebuild.git] / t / 07is_installable_cycle.t
blob95ec8fd691b2237fc44a03e9d9db167960a11061
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
5 use Test::Simple tests => 5;
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) = @_;
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(
37 $name => $runrequires
39 ));
40 return $package;
43 my $a = build_package(
44 'a',
45 {},
46 { 'a' => [[Fedora::Rebuild::RPM::ANY, '']] },
49 my $b = build_package(
50 'b',
51 {},
52 { 'a' => [[Fedora::Rebuild::RPM::ANY, '']] },
55 my $c = build_package(
56 'c',
57 {},
58 { 'd' => [[Fedora::Rebuild::RPM::ANY, '']] },
61 my $d = build_package(
62 'd',
63 {},
64 { 'c' => [[Fedora::Rebuild::RPM::ANY, '']] },
67 my $e = build_package(
68 'e',
69 {},
70 { 'd' => [[Fedora::Rebuild::RPM::ANY, '']] },
73 # Prepare set of packages
74 my $packages = Fedora::Rebuild::Set::Package->new();
75 $packages->insert($a);
76 $packages->insert($b);
77 $packages->insert($c);
78 $packages->insert($d);
79 $packages->insert($e);
81 # Prepare solver
82 my $solver = Fedora::Rebuild::Solver->new(packages => $packages,
83 dependencyfilter => sub {0});
85 # Test
86 my $message;
88 # Cycle with 1 edge
89 ok($solver->is_installable($a, 'a', \$message),
90 "a requires itself: $message");
91 ok($solver->is_installable($b, 'b', \$message),
92 "b requires reflexive a: $message");
94 # Cycle with 2 edges
95 ok($solver->is_installable($d, 'd', \$message),
96 "d requires c that requires d: $message");
97 ok($solver->is_installable($c, 'c', \$message),
98 "c requires d that requires c: $message");
99 ok($solver->is_installable($e, 'e', \$message),
100 "e requiers d that requires c that requires d: $message");