Fedora::Rebuild option pyrpkg added
[Fedora-Rebuild.git] / t / 06is_buildable_filter.t
blob25b32e7146148874d29086b1f5129c8cb2531616
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
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;
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',
45 'foo' =>
46 [[Fedora::Rebuild::RPM::EQUAL|Fedora::Rebuild::RPM::GREATER, '1']],
48 {},
49 {},
52 my $b = build_package(
53 'b',
54 {},
55 { 'foo' => [[Fedora::Rebuild::RPM::ANY, '']] },
56 {},
59 my $B = build_package(
60 'B',
61 {},
62 {},
63 { 'foo' => [[Fedora::Rebuild::RPM::ANY, '']] },
66 my $C = build_package(
67 'C',
68 {},
69 {},
70 { 'b' => [[Fedora::Rebuild::RPM::ANY, '']] },
73 my $D = build_package(
74 'D',
75 {},
76 {},
77 { 'foo' => [[Fedora::Rebuild::RPM::EQUAL, '0']] },
80 my $E = build_package(
81 'E',
82 {},
83 {},
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
101 sub do_test {
102 my ($filter_name, $filter_sub, @excpected_results) = @_;
103 my $message;
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: " .
114 "$message");
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: " .
119 "$message");
122 # Test
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',
127 sub {
128 my ($name, $flag, $version) = @_;
129 $name eq 'foo';
130 }, 1, 1, 1, 1, 0);
132 do_test('Filter out foo = 0',
133 sub {
134 my ($name, $flag, $version) = @_;
135 $name eq 'foo' and $flag == Fedora::Rebuild::RPM::EQUAL and
136 $version eq '0';
137 }, 1, 1, 1, 1, 0);
139 do_test('Filter out any bar',
140 sub {
141 my ($name, $flag, $version) = @_;
142 $name eq 'bar' and $flag;
143 }, 1, 1, 1, 0, 0);