Dpkg_Dist_Files.t 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 => 8;
  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. );
  61. my $dist = Dpkg::Dist::Files->new();
  62. $dist->load("$datadir/files-byhand") or error('cannot parse file');
  63. $expected = 'pkg-templ_1.2.3_arch.type section priority
  64. pkg-arch_2.0.0_amd64.deb admin required
  65. pkg-indep_0.0.1-2_all.deb net standard
  66. other_0.txt text optional
  67. BY-HAND-file webdocs optional
  68. ';
  69. is($dist->output(), $expected, 'Parsed dist file');
  70. foreach my $f ($dist->get_files()) {
  71. is_deeply($f, $expected{$f->{filename}},
  72. "Detail for individual dist file $f->{filename}");
  73. }
  74. $expected = 'pkg-templ_1.2.3_arch.type section priority
  75. pkg-arch_2.0.0_amd64.deb void imperative
  76. other_0.txt text optional
  77. BY-HAND-file webdocs optional
  78. added-on-the-fly void wish
  79. ';
  80. $dist->add_file('added-on-the-fly', 'void', 'wish');
  81. $dist->add_file('pkg-arch_2.0.0_amd64.deb', 'void', 'imperative');
  82. $dist->del_file('pkg-indep_0.0.1-2_all.deb');
  83. is($dist->output(), $expected, 'Modified dist object');
  84. 1;