400_Dpkg_Deps.t 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/usr/bin/perl
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. use Test::More tests => 20;
  16. use strict;
  17. use warnings;
  18. use Dpkg::Arch qw(get_host_arch);
  19. use_ok('Dpkg::Deps');
  20. my $field_multiline = ' , , libgtk2.0-common (= 2.10.13-1) , libatk1.0-0 (>=
  21. 1.13.2), libc6 (>= 2.5-5), libcairo2 (>= 1.4.0), libcupsys2 (>= 1.2.7),
  22. libfontconfig1 (>= 2.4.0), libglib2.0-0 ( >= 2.12.9), libgnutls13 (>=
  23. 1.6.3-0), libjpeg62, python (<< 2.5) , , ';
  24. 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)';
  25. my $dep_multiline = deps_parse($field_multiline);
  26. $dep_multiline->sort();
  27. is($dep_multiline->output(), $field_multiline_sorted, 'Parse, sort and output');
  28. my $dep_subset = deps_parse('libatk1.0-0 (>> 1.10), libc6, libcairo2');
  29. is($dep_multiline->implies($dep_subset), 1, 'Dep implies subset of itself');
  30. is($dep_subset->implies($dep_multiline), undef, "Subset doesn't imply superset");
  31. my $dep_opposite = deps_parse('python (>= 2.5)');
  32. is($dep_opposite->implies($dep_multiline), 0, 'Opposite condition implies NOT the depends');
  33. my $dep_or1 = deps_parse('a|b (>=1.0)|c (>= 2.0)');
  34. my $dep_or2 = deps_parse('x|y|a|b|c (<= 0.5)|c (>=1.5)|d|e');
  35. is($dep_or1->implies($dep_or2), 1, 'Implication between OR 1/2');
  36. is($dep_or2->implies($dep_or1), undef, 'Implication between OR 2/2');
  37. my $dep_ma_any = deps_parse('libcairo2:any');
  38. my $dep_ma_native = deps_parse('libcairo2');
  39. #my $dep_ma_native2 = deps_parse('libcairo2:native');
  40. is($dep_ma_native->implies($dep_ma_any), 1, 'foo -> foo:any');
  41. #is($dep_ma_native2->implies($dep_ma_any), 1, 'foo:native -> foo:any');
  42. is($dep_ma_any->implies($dep_ma_native), undef, 'foo:any !-> foo');
  43. #is($dep_ma_any->implies($dep_ma_native2), undef, 'foo:any !-> foo:native');
  44. my $field_arch = 'libc6 (>= 2.5) [!alpha !hurd-i386], libc6.1 [alpha], libc0.1 [hurd-i386]';
  45. my $dep_i386 = deps_parse($field_arch, reduce_arch => 1, host_arch => 'i386');
  46. my $dep_alpha = deps_parse($field_arch, reduce_arch => 1, host_arch => 'alpha');
  47. my $dep_hurd = deps_parse($field_arch, reduce_arch => 1, host_arch => 'hurd-i386');
  48. is($dep_i386->output(), 'libc6 (>= 2.5)', 'Arch reduce 1/3');
  49. is($dep_alpha->output(), 'libc6.1', 'Arch reduce 2/3');
  50. is($dep_hurd->output(), 'libc0.1', 'Arch reduce 3/3');
  51. my $facts = Dpkg::Deps::KnownFacts->new();
  52. $facts->add_installed_package('mypackage', '1.3.4-1', get_host_arch(), 'no');
  53. $facts->add_installed_package('mypackage2', '1.3.4-1', 'somearch', 'no');
  54. $facts->add_installed_package('pkg-ma-foreign', '1.3.4-1', 'somearch', 'foreign');
  55. $facts->add_installed_package('pkg-ma-foreign2', '1.3.4-1', get_host_arch(), 'foreign');
  56. $facts->add_installed_package('pkg-ma-allowed', '1.3.4-1', 'somearch', 'allowed');
  57. $facts->add_installed_package('pkg-ma-allowed2', '1.3.4-1', 'somearch', 'allowed');
  58. $facts->add_installed_package('pkg-ma-allowed3', '1.3.4-1', get_host_arch(), 'allowed');
  59. $facts->add_provided_package('myvirtual', undef, undef, 'mypackage');
  60. my $field_duplicate = 'libc6 (>= 2.3), libc6 (>= 2.6-1), mypackage (>=
  61. 1.3), myvirtual | something, python (>= 2.5), mypackage2, pkg-ma-foreign,
  62. pkg-ma-foreign2, pkg-ma-allowed:any, pkg-ma-allowed2, pkg-ma-allowed3';
  63. my $dep_dup = deps_parse($field_duplicate);
  64. $dep_dup->simplify_deps($facts, $dep_opposite);
  65. is($dep_dup->output(), 'libc6 (>= 2.6-1), mypackage2, pkg-ma-allowed2', 'Simplify deps');
  66. my $field_dup_union = 'libc6 (>> 2.3), libc6 (>= 2.6-1), fake (<< 2.0),
  67. fake(>> 3.0), fake (= 2.5), python (<< 2.5), python (= 2.4)';
  68. my $dep_dup_union = deps_parse($field_dup_union, union => 1);
  69. $dep_dup_union->simplify_deps($facts);
  70. is($dep_dup_union->output(), 'libc6 (>> 2.3), fake (<< 2.0), fake (>> 3.0), fake (= 2.5), python (<< 2.5)', 'Simplify union deps');
  71. $dep_dup_union = deps_parse('sipsak (<= 0.9.6-2.1), sipsak (<= 0.9.6-2.2)', union => 1);
  72. $dep_dup_union->simplify_deps($facts);
  73. is($dep_dup_union->output(), 'sipsak (<= 0.9.6-2.2)', 'Simplify union deps 2');
  74. my $dep_red = deps_parse('abc | xyz, two, abc');
  75. $dep_red->simplify_deps($facts, $dep_opposite);
  76. is($dep_red->output(), 'abc, two', 'Simplification respect order');
  77. is("$dep_red", $dep_red->output(), 'Stringification == output()');
  78. my $dep_empty1 = deps_parse('');
  79. is($dep_empty1->output(), '', 'Empty dependency');
  80. my $dep_empty2 = deps_parse(' , , ', union => 1);
  81. is($dep_empty2->output(), '', "' , , ' is also an empty dependency");
  82. $SIG{__WARN__} = sub {};
  83. my $dep_bad_multiline = deps_parse("a, foo\nbar, c");
  84. ok(!defined($dep_bad_multiline), 'invalid dependency split over multiple line');
  85. delete $SIG{__WARN__};