5 use Test
::Simple tests
=> 5*5;
7 use Fedora
::Rebuild
::Solver
;
8 use Fedora
::Rebuild
::Set
::Package
;
9 use Fedora
::Rebuild
::Package
;
10 use Fedora
::Rebuild
::RPM
;
14 # Create and return package with one binary package that always provides its
17 my ($name, $provides, $runrequires, $buildrequires) = @_;
19 my $package = Fedora
::Rebuild
::Package
->new(
27 $package->provides(shared_clone
(
30 $name => [[Fedora
::Rebuild
::RPM
::ANY
, '']],
35 $package->runrequires(shared_clone
(
36 { $name => $runrequires }
38 $package->requires(shared_clone
($buildrequires));
42 my $a = build_package
(
46 [[Fedora
::Rebuild
::RPM
::EQUAL
|Fedora
::Rebuild
::RPM
::GREATER
, '1']],
52 my $b = build_package
(
55 { 'foo' => [[Fedora
::Rebuild
::RPM
::ANY
, '']] },
59 my $B = build_package
(
63 { 'foo' => [[Fedora
::Rebuild
::RPM
::ANY
, '']] },
66 my $C = build_package
(
70 { 'b' => [[Fedora
::Rebuild
::RPM
::ANY
, '']] },
73 my $D = build_package
(
77 { 'foo' => [[Fedora
::Rebuild
::RPM
::EQUAL
, '0']] },
80 my $E = build_package
(
85 'foo' => [[Fedora
::Rebuild
::RPM
::EQUAL
, '0']],
86 'bar' => [[Fedora
::Rebuild
::RPM
::ANY
, '']]
91 # Prepare set of packages
92 my $packages = Fedora
::Rebuild
::Set
::Package
->new();
93 $packages->insert($a);
94 $packages->insert($b);
95 $packages->insert($B);
96 $packages->insert($C);
97 $packages->insert($D);
98 $packages->insert($E);
100 # Test group of packages
102 my ($filter_name, $filter_sub, @excpected_results) = @_;
105 my $solver = Fedora
::Rebuild
::Solver
->new(packages
=> $packages,
106 dependencyfilter
=> $filter_sub);
108 ok
($solver->is_buildable($a, \
$message) == shift @excpected_results,
109 "$filter_name, a build-requires nothing: $message");
110 ok
($solver->is_buildable($B, \
$message) == shift @excpected_results,
111 "$filter_name, B build-requires foo provided by a: $message");
112 ok
($solver->is_buildable($C, \
$message) == shift @excpected_results,
113 "$filter_name, C build-requires b that requires foo provided by a: " .
115 ok
($solver->is_buildable($D, \
$message) == shift @excpected_results,
116 "$filter_name, D build-requires non-existing foo = 0: $message");
117 ok
($solver->is_buildable($E, \
$message) == shift @excpected_results,
118 "$filter_name, E build-requires non-existing foo = 0 and bar: " .
123 do_test
('Explicit 0 filter', sub {0}, 1, 1, 1, 0, 0);
124 do_test
('Explicit 1 filter', sub {1}, 1, 1, 1, 1, 1);
126 do_test
('Filter out any foo',
128 my ($name, $flag, $version) = @_;
132 do_test
('Filter out foo = 0',
134 my ($name, $flag, $version) = @_;
135 $name eq 'foo' and $flag == Fedora
::Rebuild
::RPM
::EQUAL
and
139 do_test
('Filter out any bar',
141 my ($name, $flag, $version) = @_;
142 $name eq 'bar' and $flag;