summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/changelog2spec.t33
-rw-r--r--t/conflicts.t78
-rw-r--r--t/determinism.t22
-rw-r--r--t/obsoletes.t53
-rw-r--r--t/ordep.t35
-rw-r--r--t/recommends.t32
-rw-r--r--t/requires.t95
-rw-r--r--t/richdeps.t198
-rw-r--r--t/testlib.pm26
9 files changed, 572 insertions, 0 deletions
diff --git a/t/changelog2spec.t b/t/changelog2spec.t
new file mode 100644
index 0000000..56de7c8
--- /dev/null
+++ b/t/changelog2spec.t
@@ -0,0 +1,33 @@
+#!/usr/bin/perl -w
+
+use strict;
+use Test::More tests => 11;
+
+sub onetest(@)
+{
+ my $expected = shift;
+ my $actual = `./changelog2spec --selftest @_`;
+ is($actual, $expected, "changelog2spec --selftest @_");
+}
+
+my @tests=(
+ # format is 1:specfile 2:expected-changes 3++:list-of-changes-files
+ [qw"rpm rpm python-rpm rpm"],
+ [qw"python-rpm python-rpm python-rpm rpm"],
+ [qw"antlr antlr antlr antlr-bootstrap"],
+ [qw"antlr anyunrelated anyunrelated"],
+ [qw"antlr-bootstrap antlr-bootstrap antlr antlr-bootstrap"],
+ [qw"antlr-bootstrap antlr antlr"],
+ [qw"antlr-bootstrap antlr antlr antlr-other"],
+ [qw"foo _service:obs_scm:foo foo _service:obs_scm:foo"],
+ [qw"_service:obs_scm:foo _service:obs_scm:foo foo _service:obs_scm:foo"],
+ [qw"_service:obs_scm:foo foo foo foo-bar"],
+ [qw"_service:obs_scm:foo-bar foo foo foo-other"],
+);
+for my $t (@tests) {
+ my @tmp=@$t;
+ my $file=shift(@tmp);
+ foreach(0..$#tmp) {$tmp[$_].=".changes"}
+ my $expected=shift(@tmp);
+ onetest($expected, $file, @tmp);
+}
diff --git a/t/conflicts.t b/t/conflicts.t
new file mode 100644
index 0000000..12c79ea
--- /dev/null
+++ b/t/conflicts.t
@@ -0,0 +1,78 @@
+#!/usr/bin/perl -w
+
+use strict;
+use Test::More tests => 13;
+
+require 't/testlib.pm';
+
+my $repo = <<'EOR';
+P: a = 1-1
+R: p
+P: b = 1-1 p
+P: c = 1-1 p
+P: d = 1-1
+C: b
+P: e = 1-1
+C: c
+P: f = 1-1
+C: p
+P: g = 1-1
+C: b c
+P: h = 1-1
+R: f
+P: i = 1-1
+P: j = 1-1
+P: k = 1-1
+R: j
+P: l = 1-1
+R: b d
+P: m = 1-1
+C: m
+EOR
+
+my $config = setuptest($repo, "Conflict: i:j");
+my @r;
+
+# test that conflicts can fix choices
+@r = expand($config, 'a');
+is_deeply(\@r, [undef, 'have choice for p needed by a: b c'], 'install a');
+
+@r = expand($config, 'a', 'd');
+is_deeply(\@r, [1, 'a', 'c', 'd'], 'install a d');
+
+@r = expand($config, 'a', 'e');
+is_deeply(\@r, [1, 'a', 'b', 'e'], 'install a e');
+
+# test test conflicting all providers works
+@r = expand($config, 'a', 'd', 'e');
+is_deeply(\@r, [undef, '(provider b is in conflict with d)', '(provider c is in conflict with e)', 'conflict for providers of p needed by a'], 'install a d e');
+
+@r = expand($config, 'a', 'f');
+is_deeply(\@r, [undef, '(provider b is in conflict with f)', '(provider c is in conflict with f)', 'conflict for providers of p needed by a'], 'install a f');
+
+# test that conflicting jobs work
+@r = expand($config, 'b', 'f');
+is_deeply(\@r, [undef, 'f conflicts with b'], 'install b f');
+
+@r = expand($config, 'b', 'h');
+is_deeply(\@r, [undef, '(provider f conflicts with b)', 'conflict for providers of f needed by h'], 'install b h');
+
+# test conflicts specified in the job
+@r = expand($config, 'i', '!i');
+is_deeply(\@r, [undef, 'i is in conflict'], 'install i !i');
+
+@r = expand($config, 'k', '!j');
+is_deeply(\@r, [undef, '(provider j is in conflict)', 'conflict for providers of j needed by k'], 'install k !j');
+
+# test conflicts from project config
+@r = expand($config, 'i', 'j');
+is_deeply(\@r, [undef, 'i conflicts with j', 'j conflicts with i'], 'install i j');
+
+@r = expand($config, 'i', 'k');
+is_deeply(\@r, [undef, '(provider j is in conflict with i)', 'conflict for providers of j needed by k'], 'install i k');
+
+@r = expand($config, 'l');
+is_deeply(\@r, [undef, 'd conflicts with b'], 'install l');
+
+@r = expand($config, 'm');
+is_deeply(\@r, [1, 'm'], 'install m');
diff --git a/t/determinism.t b/t/determinism.t
new file mode 100644
index 0000000..1d7ebc2
--- /dev/null
+++ b/t/determinism.t
@@ -0,0 +1,22 @@
+#!/usr/bin/perl -w
+
+use strict;
+use Test::More tests => 1;
+
+require 't/testlib.pm';
+
+my $repo = <<'EOR';
+P: a = 1-1
+R: b c
+P: b1 = 1-1 b
+C: c1
+P: b2 = 1-1 b
+P: c1 = 1-1 c
+P: c2 = 1-1 c
+EOR
+
+my $config = setuptest($repo, 'Prefer: b1 c1');
+my @r;
+
+@r = expand($config, 'a');
+is_deeply(\@r, [undef, 'b1 conflicts with c1'], 'install a');
diff --git a/t/obsoletes.t b/t/obsoletes.t
new file mode 100644
index 0000000..c464d83
--- /dev/null
+++ b/t/obsoletes.t
@@ -0,0 +1,53 @@
+#!/usr/bin/perl -w
+
+use strict;
+use Test::More tests => 9;
+
+require 't/testlib.pm';
+
+my $repo = <<'EOR';
+P: a = 1-1
+R: p
+P: b = 1-1 p
+P: c = 1-1 p
+P: d = 1-1
+O: b
+P: e = 1-1
+O: c
+P: f = 1-1
+O: p
+P: g = 1-1
+O: b c
+P: h = 1-1
+R: b d
+EOR
+
+my $config = setuptest($repo);
+my @r;
+
+@r = expand($config, 'a');
+is_deeply(\@r, [undef, 'have choice for p needed by a: b c'], 'install a');
+
+@r = expand($config, 'a', 'd');
+is_deeply(\@r, [1, 'a', 'c', 'd'], 'install a d');
+
+@r = expand($config, 'a', 'e');
+is_deeply(\@r, [1, 'a', 'b', 'e'], 'install a e');
+
+@r = expand($config, 'a', 'd', 'e');
+is_deeply(\@r, [undef, '(provider b is obsoleted by d)', '(provider c is obsoleted by e)', 'conflict for providers of p needed by a'], 'install a d e');
+
+@r = expand($config, 'a', 'f');
+is_deeply(\@r, [undef, 'have choice for p needed by a: b c'], 'install a f');
+
+@r = expand($config, 'b', 'd');
+is_deeply(\@r, [undef, 'd obsoletes b'], 'install b d');
+
+@r = expand($config, 'h');
+is_deeply(\@r, [undef, 'd obsoletes b'], 'install h');
+
+@r = expand($config, 'h', 'd');
+is_deeply(\@r, [undef, '(provider b is obsoleted by d)', 'conflict for providers of b needed by h'], 'install h d');
+
+@r = expand($config, 'h', 'b');
+is_deeply(\@r, [undef, '(provider d obsoletes b)', 'conflict for providers of d needed by h'], 'install h b');
diff --git a/t/ordep.t b/t/ordep.t
new file mode 100644
index 0000000..09f4f29
--- /dev/null
+++ b/t/ordep.t
@@ -0,0 +1,35 @@
+#!/usr/bin/perl -w
+
+use strict;
+use Test::More tests => 4;
+
+require 't/testlib.pm';
+
+my $repo = <<'EOR';
+P: a = 1-1
+R: x | y
+P: b = 1-1
+R: d | e
+P: c = 1-1
+R: d | f
+P: d = 1-1
+P: e = 1-1
+P: f = 1-1
+P: g = 1-1
+R: x | e | d
+EOR
+
+my $config = setuptest($repo, "Binarytype: deb\nPrefer: f\n");
+my @r;
+
+@r = expand($config, 'a');
+is_deeply(\@r, [undef, 'nothing provides x | y needed by a'], 'install a');
+
+@r = expand($config, 'b');
+is_deeply(\@r, [1, 'b', 'd'], 'install b');
+
+@r = expand($config, 'c');
+is_deeply(\@r, [1, 'c', 'f'], 'install c');
+
+@r = expand($config, 'g');
+is_deeply(\@r, [1, 'e', 'g'], 'install g');
diff --git a/t/recommends.t b/t/recommends.t
new file mode 100644
index 0000000..90372cc
--- /dev/null
+++ b/t/recommends.t
@@ -0,0 +1,32 @@
+#!/usr/bin/perl -w
+
+use strict;
+use Test::More tests => 4;
+
+require 't/testlib.pm';
+
+my $repo = <<'EOR';
+P: a = 1-1
+R: p
+P: b = 1-1 p
+P: c = 1-1 p
+P: d = 1-1
+r: b
+P: e = 1-1
+r: c
+EOR
+
+my $config = setuptest($repo);
+my @r;
+
+@r = expand($config, 'a');
+is_deeply(\@r, [undef, 'have choice for p needed by a: b c'], 'install a');
+
+@r = expand($config, 'a', 'd');
+is_deeply(\@r, [1, 'a', 'b', 'd'], 'install a d');
+
+@r = expand($config, 'a', 'e');
+is_deeply(\@r, [1, 'a', 'c', 'e'], 'install a e');
+
+@r = expand($config, 'a', 'd', 'e');
+is_deeply(\@r, [undef, 'have choice for p needed by a: b c'], 'install a d e');
diff --git a/t/requires.t b/t/requires.t
new file mode 100644
index 0000000..ab1f486
--- /dev/null
+++ b/t/requires.t
@@ -0,0 +1,95 @@
+#!/usr/bin/perl -w
+
+use strict;
+use Test::More tests => 20;
+
+require 't/testlib.pm';
+
+my $repo = <<'EOR';
+P: a = 1-1
+R: b
+P: b = 1-1
+P: c = 1-1
+R: p
+P: d = 1-1 p
+P: e = 1-1 p
+P: f = 1-1
+R: n
+P: ign2 = 1-1
+R: ign1
+P: ign3 = 1-1
+R: ign4
+P: ign5 = 1-1 ign4
+P: ign6 = 1-1
+R: ign7
+P: ign8 = 1-1
+R: ign7
+P: g = 1-1 h
+P: h = 1-1
+EOR
+
+my $config = setuptest($repo, 'Ignore: ign1 ign5 ign6:ign7');
+my $config2 = setuptest($repo, 'Prefer: d');
+my $config3 = setuptest($repo, 'Prefer: -d');
+my @r;
+
+@r = expand($config);
+is_deeply(\@r, [1], 'install nothing');
+
+@r = expand($config, 'n');
+is_deeply(\@r, [undef, 'nothing provides n'], 'install n');
+
+@r = expand($config, 'f');
+is_deeply(\@r, [undef, 'nothing provides n needed by f'], 'install f');
+
+@r = expand($config, "a");
+is_deeply(\@r, [1, 'a', 'b'], 'install a');
+
+@r = expand($config, "c");
+is_deeply(\@r, [undef, 'have choice for p needed by c: d e'], 'install c');
+
+@r = expand($config2, "c");
+is_deeply(\@r, [1, 'c', 'd'], 'install c with prefer');
+
+@r = expand($config3, "c");
+is_deeply(\@r, [1, 'c', 'e'], 'install c with neg prefer');
+
+@r = expand($config, "ign1");
+is_deeply(\@r, [undef, 'nothing provides ign1'], 'install ign1');
+
+@r = expand($config, "ign2");
+is_deeply(\@r, [1, 'ign2'], 'install ign2');
+
+@r = expand($config, "ign3");
+is_deeply(\@r, [1, 'ign3'], 'install ign3');
+
+@r = expand($config, "ign6");
+is_deeply(\@r, [1, 'ign6'], 'install ign6');
+
+@r = expand($config, "ign8");
+is_deeply(\@r, [undef, 'nothing provides ign7 needed by ign8'], 'install ign8');
+
+@r = expand($config, "ign2", "-ign2");
+is_deeply(\@r, [1, 'ign2'], 'install ign2 -ign2');
+
+@r = expand($config, "ign8", "-ign7");
+is_deeply(\@r, [1, 'ign8'], 'install ign8 -ign7');
+
+@r = expand($config2, "ign5", "-ign5");
+is_deeply(\@r, [1, 'ign5'], 'install ign5 -ign5');
+
+@r = expand($config2, "ign4", "-ign5");
+is_deeply(\@r, [1, 'ign5'], 'install ign4 -ign5');
+
+@r = expand($config, "ign5");
+is_deeply(\@r, [1, 'ign5'], 'install ign5');
+
+@r = expand($config, "ign4");
+is_deeply(\@r, [1, 'ign5'], 'install ign4');
+
+@r = expand($config, "h");
+is_deeply(\@r, [1, 'h'], 'install h');
+
+@r = expand($config, "--directdepsend--", "h");
+is_deeply(\@r, [undef, 'have choice for h: g h'], 'install --directdepsend-- h');
+
diff --git a/t/richdeps.t b/t/richdeps.t
new file mode 100644
index 0000000..ed7a1cc
--- /dev/null
+++ b/t/richdeps.t
@@ -0,0 +1,198 @@
+#!/usr/bin/perl -w
+
+use strict;
+use Test::More tests => 45;
+
+require 't/testlib.pm';
+
+my $repo = <<'EOR';
+P: a = 1-1
+R: (b if c) d
+P: b = 1-1
+P: c = 1-1
+P: d = 1-1
+R: c
+P: n1 = 1-1
+R: n
+P: n2 = 1-1
+C: d
+P: i = 1-1
+P: j = 1-1
+R: k
+P: k = 1-1
+C: (i and j)
+P: lr = 1-1
+R: (b if b)
+P: lc1 = 1-1
+C: (b if b)
+P: lc2 = 1-1
+C: (n if n)
+P: m = 1-1
+C: (b and (n if b))
+P: cx = 1-1
+C: (b and cx and d)
+P: ign1 = 1-1
+R: (ign and b)
+P: ign2 = 1-1
+R: (ign or b)
+P: ign3 = 1-1
+R: (b if ign)
+P: ign4 = 1-1
+R: (ign if b)
+P: bad1 = 1-1
+R: (n foo m)
+P: bad2 = 1-1
+C: (n foo m)
+P: sc = 1-1
+C: (a or sc) (n or sc)
+P: ifelse = 1-1
+R: (b if i else c)
+P: unless = 1-1
+C: (b unless i)
+P: unlesselse = 1-1
+C: (b unless i else c)
+P: wa = 1-1 wx
+P: wb = 1-1 wx wy
+P: wc = 1-1 wy
+EOR
+
+my $config = setuptest($repo, 'Ignore: ign');
+my @r;
+
+@r = expand($config, "()");
+is_deeply(\@r, [undef, 'cannot parse dependency ()'], 'install ()');
+
+@r = expand($config, "(n and )");
+is_deeply(\@r, [undef, 'cannot parse dependency (n and )'], 'install (n and )');
+
+@r = expand($config, "(n foo m)");
+is_deeply(\@r, [undef, 'cannot parse dependency (n foo m)'], 'install (n foo m)');
+
+@r = expand($config, "n");
+is_deeply(\@r, [undef, 'nothing provides n'], 'install n');
+
+@r = expand($config, "(n or o)");
+is_deeply(\@r, [undef, 'nothing provides (n or o)'], 'install (n or o)');
+
+@r = expand($config, "(n and o)");
+is_deeply(\@r, [undef, 'nothing provides (n and o)'], 'install (n and o)');
+
+@r = expand($config, "n1");
+is_deeply(\@r, [undef, "nothing provides n needed by n1"], "install n1");
+
+@r = expand($config, "(n2 and d)");
+is_deeply(\@r, [undef, 'n2 conflicts with d'], "install (n2 and d)");
+
+@r = expand($config, "(n2 or d)");
+is_deeply(\@r, [undef, "have choice for (n2 or d): d n2"], "install (n2 or d)");
+
+@r = expand($config, "a");
+is_deeply(\@r, [1, qw{a b c d}], "install a");
+
+@r = expand($config, 'i', 'j');
+is_deeply(\@r, [undef, '(provider k conflicts with i)', '(provider k conflicts with j)', "conflict for providers of k needed by j"], "install i j");
+
+# test corner cases
+@r = expand($config, "(b if b)");
+is_deeply(\@r, [1], 'install (b if b)');
+
+@r = expand($config, "(n if n)");
+is_deeply(\@r, [1], 'install (n if n)');
+
+@r = expand($config, "lr");
+is_deeply(\@r, [1, 'lr'], 'install lr');
+
+@r = expand($config, "lc1");
+is_deeply(\@r, [undef, '(provider b is in conflict with lc1)', 'conflict for providers of (b if b) needed by lc1'], 'install lc1');
+
+@r = expand($config, "lc2");
+is_deeply(\@r, [undef, 'lc2 conflicts with always true (n if n)'], 'install lc2');
+
+@r = expand($config, "m");
+is_deeply(\@r, [1, 'm'], 'install m');
+
+# complex config from the job
+@r = expand($config, 'b', 'c', 'd', '!(b and c and d)');
+is_deeply(\@r, [undef, 'conflicts with b', 'conflicts with c', 'conflicts with d'], 'install b c d !(b and c and d)');
+
+@r = expand($config, '!(n if n)');
+is_deeply(\@r, [undef, 'conflict with always true (n if n)'], 'install !(n if n)');
+
+@r = expand($config, 'b', 'cx', 'd');
+is_deeply(\@r, [undef, 'cx conflicts with b', 'cx conflicts with d'], 'install b cx d');
+
+@r = expand($config, 'ign');
+is_deeply(\@r, [undef, 'nothing provides ign'], 'install ign');
+
+@r = expand($config, 'ign1');
+is_deeply(\@r, [1, 'b', 'ign1'], 'install ign1');
+
+@r = expand($config, 'ign2');
+is_deeply(\@r, [1, 'ign2'], 'install ign2');
+
+@r = expand($config, 'ign3');
+is_deeply(\@r, [1, 'ign3'], 'install ign3');
+
+@r = expand($config, 'b', 'ign4');
+is_deeply(\@r, [1, 'b', 'ign4'], 'install b ign4');
+
+@r = expand($config, '(ign and b)');
+is_deeply(\@r, [undef, 'nothing provides (ign and b)'], 'install b');
+
+@r = expand($config, 'bad1');
+is_deeply(\@r, [undef, 'cannot parse dependency (n foo m) from bad1'], 'install bad1');
+
+@r = expand($config, 'bad2');
+is_deeply(\@r, [undef, 'cannot parse dependency (n foo m) from bad2'], 'install bad2');
+
+@r = expand($config, 'sc', 'b');
+is_deeply(\@r, [1, 'b', 'sc'], 'install sc b');
+
+@r = expand($config, 'ifelse');
+is_deeply(\@r, [undef, 'have choice for (b if i else c) needed by ifelse: c i'], 'install ifelse');
+
+@r = expand($config, 'ifelse', 'i');
+is_deeply(\@r, [1, 'b', 'i', 'ifelse'], 'install ifelse i');
+
+@r = expand($config, 'ifelse', 'c');
+is_deeply(\@r, [1, 'c', 'ifelse'], 'install ifelse c');
+
+@r = expand($config, 'unless', 'b');
+is_deeply(\@r, [1, 'b', 'i', 'unless'], 'install unless b');
+
+@r = expand($config, 'unless', 'b', '!i');
+is_deeply(\@r, [undef, '(provider i is in conflict)', 'conflict for providers of (b unless i) needed by unless'], 'install unless b !i');
+
+@r = expand($config, 'unlesselse', 'b', 'c');
+is_deeply(\@r, [undef, '(provider i is in conflict with unlesselse)', 'conflict for providers of (b unless i else c) needed by unlesselse'], 'install unlesselse b c');
+
+@r = expand($config, 'unlesselse', 'b');
+is_deeply(\@r, [1, 'b', 'i', 'unlesselse'], 'install unlesselse b');
+
+@r = expand($config, 'unlesselse', 'c');
+is_deeply(\@r, [1, 'c', 'unlesselse'], 'install unlesselse c');
+
+@r = expand($config, '(wx and wy)');
+is_deeply(\@r, [undef, 'have choice for (wx and wy): wa wb', 'have choice for (wx and wy): wb wc'], 'install (wx and wy)');
+
+@r = expand($config, '(wx with wy)');
+is_deeply(\@r, [1, 'wb'], 'install (wx with wy)');
+
+@r = expand($config, '(wx without wy)');
+is_deeply(\@r, [1, 'wa'], 'install (wx without wy)');
+
+@r = expand($config, '(wy without wx)');
+is_deeply(\@r, [1, 'wc'], 'install (wy without wx)');
+
+@r = expand($config, '(wa with wa)');
+is_deeply(\@r, [1, 'wa'], 'install (wa with wa)');
+
+@r = expand($config, '(wa with nnn)');
+is_deeply(\@r, [undef, 'nothing provides (wa with nnn)'], 'install (wa with nnn)');
+
+@r = expand($config, '(wa without wa)');
+is_deeply(\@r, [undef, 'nothing provides (wa without wa)'], 'install (wa without wa)');
+
+@r = expand($config, '(wa without nnn)');
+is_deeply(\@r, [1, 'wa'], 'install (wa without nnn)');
+
diff --git a/t/testlib.pm b/t/testlib.pm
new file mode 100644
index 0000000..d9ff33f
--- /dev/null
+++ b/t/testlib.pm
@@ -0,0 +1,26 @@
+
+use Build;
+
+sub expand {
+ my ($c, @r) = Build::expand(@_);
+ return ($c, sort(@r));
+}
+
+sub setuptest {
+ my ($repo, $conf) = @_;
+ my $l = '';
+ my $id = '';
+ for (split("\n", $repo)) {
+ $id = "$1.noarch-0/0/0:" if /^P: (\S+)/;
+ s/:/:$id/;
+ $l .= "$_\n";
+ }
+ local *F;
+ open(F, '<', \$l);
+ my $config = Build::read_config('noarch', [ split("\n", $conf || '') ]);
+ Build::readdeps($config, undef, \*F);
+ close F;
+ return $config;
+}
+
+1;