Dpkg_Dist_Files.t 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 <https://www.gnu.org/licenses/>.
  15. use strict;
  16. use warnings;
  17. use Test::More tests => 17;
  18. use_ok('Dpkg::Dist::Files');
  19. my $srcdir = $ENV{srcdir} // '.';
  20. my $datadir = $srcdir . '/t/Dpkg_Dist_Files';
  21. my $expected;
  22. my %expected = (
  23. 'pkg-templ_1.2.3_arch.type' => {
  24. filename => 'pkg-templ_1.2.3_arch.type',
  25. package => 'pkg-templ',
  26. package_type => 'type',
  27. version => '1.2.3',
  28. arch => 'arch',
  29. section => 'section',
  30. priority => 'priority',
  31. },
  32. 'pkg-arch_2.0.0_amd64.deb' => {
  33. filename => 'pkg-arch_2.0.0_amd64.deb',
  34. package => 'pkg-arch',
  35. package_type => 'deb',
  36. version => '2.0.0',
  37. arch => 'amd64',
  38. section => 'admin',
  39. priority => 'required',
  40. },
  41. 'pkg-indep_0.0.1-2_all.deb' => {
  42. filename => 'pkg-indep_0.0.1-2_all.deb',
  43. package => 'pkg-indep',
  44. package_type => 'deb',
  45. version => '0.0.1-2',
  46. arch => 'all',
  47. section => 'net',
  48. priority => 'standard',
  49. },
  50. 'other_0.txt' => {
  51. filename => 'other_0.txt',
  52. section => 'text',
  53. priority => 'optional',
  54. },
  55. 'BY-HAND-file' => {
  56. filename => 'BY-HAND-file',
  57. section => 'webdocs',
  58. priority => 'optional',
  59. },
  60. 'added-on-the-fly' => {
  61. filename => 'added-on-the-fly',
  62. section => 'void',
  63. priority => 'wish',
  64. },
  65. );
  66. my $dist = Dpkg::Dist::Files->new();
  67. $dist->load("$datadir/files-byhand") or error('cannot parse file');
  68. $expected = <<'FILES';
  69. BY-HAND-file webdocs optional
  70. other_0.txt text optional
  71. pkg-arch_2.0.0_amd64.deb admin required
  72. pkg-indep_0.0.1-2_all.deb net standard
  73. pkg-templ_1.2.3_arch.type section priority
  74. FILES
  75. is($dist->output(), $expected, 'Parsed dist file');
  76. foreach my $f ($dist->get_files()) {
  77. my $filename = $f->{filename};
  78. is_deeply($f, $expected{$filename},
  79. "Detail for individual dist file $filename, via get_files()");
  80. my $fs = $dist->get_file($filename);
  81. is_deeply($fs, $expected{$filename},
  82. "Detail for individual dist file $filename, via get_file()");
  83. }
  84. $expected = <<'FILES';
  85. BY-HAND-file webdocs optional
  86. added-on-the-fly void wish
  87. other_0.txt text optional
  88. pkg-arch_2.0.0_amd64.deb void imperative
  89. pkg-templ_1.2.3_arch.type section priority
  90. FILES
  91. $dist->add_file('added-on-the-fly', 'void', 'wish');
  92. is_deeply($dist->get_file('added-on-the-fly'), $expected{'added-on-the-fly'},
  93. 'Get added file added-on-the-fly');
  94. $dist->add_file('pkg-arch_2.0.0_amd64.deb', 'void', 'imperative');
  95. my %expected_pkg_arch = %{$expected{'pkg-arch_2.0.0_amd64.deb'}};
  96. $expected_pkg_arch{section} = 'void';
  97. $expected_pkg_arch{priority} = 'imperative';
  98. is_deeply($dist->get_file('pkg-arch_2.0.0_amd64.deb'), \%expected_pkg_arch,
  99. 'Get modified file pkg-arch_2.0.0_amd64.deb');
  100. $dist->del_file('pkg-indep_0.0.1-2_all.deb');
  101. is($dist->get_file('unknown'), undef, 'Get unknown file');
  102. is($dist->get_file('pkg-indep_0.0.1-2_all.deb'), undef, 'Get deleted file');
  103. is($dist->output(), $expected, 'Modified dist object');
  104. 1;