400_Dpkg_Deps.t 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # -*- mode: cperl;-*-
  2. use Test::More tests => 15;
  3. use strict;
  4. use warnings;
  5. use_ok('Dpkg::Deps');
  6. my $field_multiline = " , , libgtk2.0-common (= 2.10.13-1) , libatk1.0-0 (>=
  7. 1.13.2), libc6 (>= 2.5-5), libcairo2 (>= 1.4.0), libcupsys2 (>= 1.2.7),
  8. libfontconfig1 (>= 2.4.0), libglib2.0-0 ( >= 2.12.9), libgnutls13 (>=
  9. 1.6.3-0), libjpeg62, python (<< 2.5) , , ";
  10. my $field_multiline_sorted = "libatk1.0-0 (>= 1.13.2), libc6 (>= 2.5-5), libcairo2 (>= 1.4.0), libcupsys2 (>= 1.2.7), libfontconfig1 (>= 2.4.0), libglib2.0-0 (>= 2.12.9), libgnutls13 (>= 1.6.3-0), libgtk2.0-common (= 2.10.13-1), libjpeg62, python (<< 2.5)";
  11. my $dep_multiline = Dpkg::Deps::parse($field_multiline);
  12. $dep_multiline->sort();
  13. is($dep_multiline->dump(), $field_multiline_sorted, "Parse, sort and dump");
  14. my $dep_subset = Dpkg::Deps::parse("libatk1.0-0 (>> 1.10), libc6, libcairo2");
  15. is($dep_multiline->implies($dep_subset), 1, "Dep implies subset of itself");
  16. is($dep_subset->implies($dep_multiline), undef, "Subset doesn't imply superset");
  17. my $dep_opposite = Dpkg::Deps::parse("python (>= 2.5)");
  18. is($dep_opposite->implies($dep_multiline), 0, "Opposite condition implies NOT the depends");
  19. my $dep_or1 = Dpkg::Deps::parse("a|b (>=1.0)|c (>= 2.0)");
  20. my $dep_or2 = Dpkg::Deps::parse("x|y|a|b|c (<= 0.5)|c (>=1.5)|d|e");
  21. is($dep_or1->implies($dep_or2), 1, "Implication between OR 1/2");
  22. is($dep_or2->implies($dep_or1), undef, "Implication between OR 2/2");
  23. my $field_arch = "libc6 (>= 2.5) [!alpha !hurd-i386], libc6.1 [alpha], libc0.1 [hurd-i386]";
  24. my $dep_i386 = Dpkg::Deps::parse($field_arch, reduce_arch => 1, host_arch => 'i386');
  25. my $dep_alpha = Dpkg::Deps::parse($field_arch, reduce_arch => 1, host_arch => 'alpha');
  26. my $dep_hurd = Dpkg::Deps::parse($field_arch, reduce_arch => 1, host_arch => 'hurd-i386');
  27. is($dep_i386->dump(), "libc6 (>= 2.5)", "Arch reduce 1/3");
  28. is($dep_alpha->dump(), "libc6.1", "Arch reduce 2/3");
  29. is($dep_hurd->dump(), "libc0.1", "Arch reduce 3/3");
  30. my $facts = Dpkg::Deps::KnownFacts->new();
  31. $facts->add_installed_package("mypackage", "1.3.4-1");
  32. $facts->add_provided_package("myvirtual", undef, undef, "mypackage");
  33. my $field_duplicate = "libc6 (>= 2.3), libc6 (>= 2.6-1), mypackage (>=
  34. 1.3), myvirtual | something, python (>= 2.5)";
  35. my $dep_dup = Dpkg::Deps::parse($field_duplicate);
  36. $dep_dup->simplify_deps($facts, $dep_opposite);
  37. is($dep_dup->dump(), "libc6 (>= 2.6-1)", "Simplify deps");
  38. my $field_dup_union = "libc6 (>> 2.3), libc6 (>= 2.6-1), fake (<< 2.0),
  39. fake(>> 3.0), fake (= 2.5), python (<< 2.5), python (= 2.4)";
  40. my $dep_dup_union = Dpkg::Deps::parse($field_dup_union, union => 1);
  41. $dep_dup_union->simplify_deps($facts);
  42. is($dep_dup_union->dump(), "libc6 (>> 2.3), fake (<< 2.0), fake (>> 3.0), fake (= 2.5), python (<< 2.5)", "Simplify union deps");
  43. my $dep_red = Dpkg::Deps::parse("abc | xyz, two, abc");
  44. $dep_red->simplify_deps($facts, $dep_opposite);
  45. is($dep_red->dump(), "abc, two", "Simplification respect order");
  46. my $dep_empty1 = Dpkg::Deps::parse("");
  47. is($dep_empty1->dump(), "", "Empty dependency");
  48. my $dep_empty2 = Dpkg::Deps::parse(" , , ", union => 1);
  49. is($dep_empty2->dump(), "", "' , , ' is also an empty dependency");