Use precreated mock environments when rebuilding source packages
[Fedora-Rebuild.git] / t / 08is_buildable_cycle.t
blob8ec19c8f4d0b017e8b32436f90e8daab7b5e2b92
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
5 use Test::Simple tests => 6;
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 $A = build_package(
43 'A',
44 {},
45 { 'A' => [[Fedora::Rebuild::RPM::ANY, '']] },
46 { 'A' => [[Fedora::Rebuild::RPM::ANY, '']] },
49 my $B = build_package(
50 'B',
51 {},
52 {},
53 { 'A' => [[Fedora::Rebuild::RPM::ANY, '']] },
56 my $C = build_package(
57 'C',
58 {},
59 { 'D' => [[Fedora::Rebuild::RPM::ANY, '']] },
60 { 'D' => [[Fedora::Rebuild::RPM::ANY, '']] },
63 my $D = build_package(
64 'D',
65 {},
66 { 'C' => [[Fedora::Rebuild::RPM::ANY, '']] },
67 { 'C' => [[Fedora::Rebuild::RPM::ANY, '']] },
70 my $E = build_package(
71 'E',
72 {},
73 {},
74 { 'D' => [[Fedora::Rebuild::RPM::ANY, '']] },
77 my $F = build_package(
78 'F',
79 {},
80 {},
81 { 'C' => [[Fedora::Rebuild::RPM::ANY, '']] },
84 # Prepare set of packages
85 my $packages = Fedora::Rebuild::Set::Package->new();
86 $packages->insert($A);
87 $packages->insert($B);
88 $packages->insert($C);
89 $packages->insert($D);
90 $packages->insert($E);
91 $packages->insert($F);
93 # Prepare solver
94 my $solver = Fedora::Rebuild::Solver->new(packages => $packages,
95 dependencyfilter => sub {0});
97 # Test
98 my $message;
100 # Cycle with 1 edge
101 ok($solver->is_buildable($A, \$message),
102 "A build-requires itself: $message");
103 ok($solver->is_buildable($B, \$message),
104 "B build-requires reflexive A: $message");
106 # Cycle with 2 edges
107 ok($solver->is_buildable($D, \$message),
108 "D build-requires C that requires D that requires C: $message");
109 ok($solver->is_buildable($C, \$message),
110 "C build-requires D that requires C that requires D: $message");
111 ok($solver->is_buildable($E, \$message),
112 "E build-requires D that requires C that requires D: $message");
113 ok($solver->is_buildable($F, \$message),
114 "F build-requires C that requires D that requires C: $message");