Dpkg_Dist_Files.t 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 => 23;
  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-src_2.0+1A~rc1-1.dsc' => {
  24. filename => 'pkg-src_2.0+1A~rc1-1.dsc',
  25. section => 'source',
  26. priority => 'extra',
  27. },
  28. 'pkg-src_2.0+1A~rc1-1.tar.xz' => {
  29. filename => 'pkg-src_2.0+1A~rc1-1.tar.xz',
  30. section => 'source',
  31. priority => 'extra',
  32. },
  33. 'pkg-templ_1.2.3_arch.type' => {
  34. filename => 'pkg-templ_1.2.3_arch.type',
  35. package => 'pkg-templ',
  36. package_type => 'type',
  37. version => '1.2.3',
  38. arch => 'arch',
  39. section => 'section',
  40. priority => 'priority',
  41. },
  42. 'pkg-arch_2.0.0_amd64.deb' => {
  43. filename => 'pkg-arch_2.0.0_amd64.deb',
  44. package => 'pkg-arch',
  45. package_type => 'deb',
  46. version => '2.0.0',
  47. arch => 'amd64',
  48. section => 'admin',
  49. priority => 'required',
  50. },
  51. 'pkg-indep_0.0.1-2_all.deb' => {
  52. filename => 'pkg-indep_0.0.1-2_all.deb',
  53. package => 'pkg-indep',
  54. package_type => 'deb',
  55. version => '0.0.1-2',
  56. arch => 'all',
  57. section => 'net',
  58. priority => 'standard',
  59. },
  60. 'other_0.txt' => {
  61. filename => 'other_0.txt',
  62. section => 'text',
  63. priority => 'optional',
  64. },
  65. 'BY-HAND-file' => {
  66. filename => 'BY-HAND-file',
  67. section => 'webdocs',
  68. priority => 'optional',
  69. },
  70. 'added-on-the-fly' => {
  71. filename => 'added-on-the-fly',
  72. section => 'void',
  73. priority => 'wish',
  74. },
  75. );
  76. my $dist = Dpkg::Dist::Files->new();
  77. $dist->load("$datadir/files-byhand") or error('cannot parse file');
  78. $expected = <<'FILES';
  79. BY-HAND-file webdocs optional
  80. other_0.txt text optional
  81. pkg-arch_2.0.0_amd64.deb admin required
  82. pkg-indep_0.0.1-2_all.deb net standard
  83. pkg-templ_1.2.3_arch.type section priority
  84. FILES
  85. is($dist->output(), $expected, 'Parsed dist file');
  86. foreach my $f ($dist->get_files()) {
  87. my $filename = $f->{filename};
  88. is_deeply($f, $expected{$filename},
  89. "Detail for individual dist file $filename, via get_files()");
  90. my $fs = $dist->get_file($filename);
  91. is_deeply($fs, $expected{$filename},
  92. "Detail for individual dist file $filename, via get_file()");
  93. }
  94. $expected = <<'FILES';
  95. BY-HAND-file webdocs optional
  96. added-on-the-fly void wish
  97. other_0.txt text optional
  98. pkg-arch_2.0.0_amd64.deb void imperative
  99. pkg-templ_1.2.3_arch.type section priority
  100. FILES
  101. $dist->add_file('added-on-the-fly', 'void', 'wish');
  102. is_deeply($dist->get_file('added-on-the-fly'), $expected{'added-on-the-fly'},
  103. 'Get added file added-on-the-fly');
  104. $dist->add_file('pkg-arch_2.0.0_amd64.deb', 'void', 'imperative');
  105. my %expected_pkg_arch = %{$expected{'pkg-arch_2.0.0_amd64.deb'}};
  106. $expected_pkg_arch{section} = 'void';
  107. $expected_pkg_arch{priority} = 'imperative';
  108. is_deeply($dist->get_file('pkg-arch_2.0.0_amd64.deb'), \%expected_pkg_arch,
  109. 'Get modified file pkg-arch_2.0.0_amd64.deb');
  110. $dist->del_file('pkg-indep_0.0.1-2_all.deb');
  111. is($dist->get_file('unknown'), undef, 'Get unknown file');
  112. is($dist->get_file('pkg-indep_0.0.1-2_all.deb'), undef, 'Get deleted file');
  113. is($dist->output(), $expected, 'Modified dist object');
  114. $expected = <<'FILES';
  115. pkg-src_2.0+1A~rc1-1.dsc source extra
  116. pkg-src_2.0+1A~rc1-1.tar.xz source extra
  117. FILES
  118. $dist->reset();
  119. $dist->add_file('pkg-src_2.0+1A~rc1-1.dsc', 'source', 'extra');
  120. $dist->add_file('pkg-src_2.0+1A~rc1-1.tar.xz', 'source', 'extra');
  121. is_deeply($dist->get_file('pkg-src_2.0+1A~rc1-1.dsc'),
  122. $expected{'pkg-src_2.0+1A~rc1-1.dsc'},
  123. 'Get added file pkg-src_2.0+1A~rc1-1.dsc');
  124. is_deeply($dist->get_file('pkg-src_2.0+1A~rc1-1.tar.xz'),
  125. $expected{'pkg-src_2.0+1A~rc1-1.tar.xz'},
  126. 'Get added file pkg-src_2.0+1A~rc1-1.tar.xz');
  127. is($dist->output, $expected, 'Added source files');
  128. $expected = <<'FILES';
  129. pkg-arch_2.0.0_amd64.deb admin required
  130. pkg-indep_0.0.1-2_all.deb net standard
  131. pkg-templ_1.2.3_arch.type section priority
  132. FILES
  133. $dist->reset();
  134. $dist->load("$datadir/files-byhand") or error('cannot parse file');
  135. $dist->filter(remove => sub { $_[0]->{priority} eq 'optional' });
  136. is($dist->output(), $expected, 'Filter remove piority optional');
  137. $expected = <<'FILES';
  138. BY-HAND-file webdocs optional
  139. other_0.txt text optional
  140. FILES
  141. $dist->reset();
  142. $dist->load("$datadir/files-byhand") or error('cannot parse file');
  143. $dist->filter(keep => sub { $_[0]->{priority} eq 'optional' });
  144. is($dist->output(), $expected, 'Filter keep priority optional');
  145. $expected = <<'FILES';
  146. BY-HAND-file webdocs optional
  147. FILES
  148. $dist->reset();
  149. $dist->load("$datadir/files-byhand") or error('cannot parse file');
  150. $dist->filter(remove => sub { $_[0]->{section} eq 'text' },
  151. keep => sub { $_[0]->{priority} eq 'optional' });
  152. is($dist->output(), $expected, 'Filter remove section text, keep priority optional');
  153. 1;