Dpkg_Dist_Files.t 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 => 26;
  18. use Test::Dpkg qw(:paths);
  19. use_ok('Dpkg::Dist::Files');
  20. my $datadir = test_get_data_path('t/Dpkg_Dist_Files');
  21. my $expected;
  22. my %expected = (
  23. 'pkg-src_4:2.0+1A~rc1-1.dsc' => {
  24. filename => 'pkg-src_4:2.0+1A~rc1-1.dsc',
  25. section => 'source',
  26. priority => 'extra',
  27. },
  28. 'pkg-src_4:2.0+1A~rc1-1.tar.xz' => {
  29. filename => 'pkg-src_4: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. 'another:filename' => {
  71. filename => 'another:filename',
  72. section => 'by-hand',
  73. priority => 'extra',
  74. },
  75. 'added-on-the-fly' => {
  76. filename => 'added-on-the-fly',
  77. section => 'void',
  78. priority => 'wish',
  79. },
  80. );
  81. my $dist = Dpkg::Dist::Files->new();
  82. $dist->load("$datadir/files-byhand") or error('cannot parse file');
  83. $expected = <<'FILES';
  84. BY-HAND-file webdocs optional
  85. other_0.txt text optional
  86. pkg-arch_2.0.0_amd64.deb admin required
  87. pkg-indep_0.0.1-2_all.deb net standard
  88. pkg-templ_1.2.3_arch.type section priority
  89. FILES
  90. is($dist->output(), $expected, 'Parsed dist file');
  91. foreach my $f ($dist->get_files()) {
  92. my $filename = $f->{filename};
  93. is_deeply($f, $expected{$filename},
  94. "Detail for individual dist file $filename, via get_files()");
  95. my $fs = $dist->get_file($filename);
  96. is_deeply($fs, $expected{$filename},
  97. "Detail for individual dist file $filename, via get_file()");
  98. }
  99. is($dist->parse_filename('file%invalid'), undef, 'invalid filename');
  100. $expected = <<'FILES';
  101. BY-HAND-file webdocs optional
  102. added-on-the-fly void wish
  103. other_0.txt text optional
  104. pkg-arch_2.0.0_amd64.deb void imperative
  105. pkg-templ_1.2.3_arch.type section priority
  106. FILES
  107. $dist->add_file('added-on-the-fly', 'void', 'wish');
  108. is_deeply($dist->get_file('added-on-the-fly'), $expected{'added-on-the-fly'},
  109. 'Get added file added-on-the-fly');
  110. $dist->add_file('pkg-arch_2.0.0_amd64.deb', 'void', 'imperative');
  111. my %expected_pkg_arch = %{$expected{'pkg-arch_2.0.0_amd64.deb'}};
  112. $expected_pkg_arch{section} = 'void';
  113. $expected_pkg_arch{priority} = 'imperative';
  114. is_deeply($dist->get_file('pkg-arch_2.0.0_amd64.deb'), \%expected_pkg_arch,
  115. 'Get modified file pkg-arch_2.0.0_amd64.deb');
  116. $dist->del_file('pkg-indep_0.0.1-2_all.deb');
  117. is($dist->get_file('unknown'), undef, 'Get unknown file');
  118. is($dist->get_file('pkg-indep_0.0.1-2_all.deb'), undef, 'Get deleted file');
  119. is($dist->output(), $expected, 'Modified dist object');
  120. $expected = <<'FILES';
  121. another:filename by-hand extra
  122. pkg-src_4:2.0+1A~rc1-1.dsc source extra
  123. pkg-src_4:2.0+1A~rc1-1.tar.xz source extra
  124. FILES
  125. $dist->reset();
  126. $dist->add_file('pkg-src_4:2.0+1A~rc1-1.dsc', 'source', 'extra');
  127. $dist->add_file('pkg-src_4:2.0+1A~rc1-1.tar.xz', 'source', 'extra');
  128. $dist->add_file('another:filename', 'by-hand', 'extra');
  129. is_deeply($dist->get_file('pkg-src_4:2.0+1A~rc1-1.dsc'),
  130. $expected{'pkg-src_4:2.0+1A~rc1-1.dsc'},
  131. 'Get added file pkg-src_4:2.0+1A~rc1-1.dsc');
  132. is_deeply($dist->get_file('pkg-src_4:2.0+1A~rc1-1.tar.xz'),
  133. $expected{'pkg-src_4:2.0+1A~rc1-1.tar.xz'},
  134. 'Get added file pkg-src_4:2.0+1A~rc1-1.tar.xz');
  135. is_deeply($dist->get_file('another:filename'),
  136. $expected{'another:filename'},
  137. 'Get added file another:filename');
  138. is($dist->output, $expected, 'Added source files');
  139. $expected = <<'FILES';
  140. BY-HAND-file webdocs optional
  141. other_0.txt text optional
  142. pkg-arch_2.0.0_amd64.deb admin required
  143. pkg-frag-a_0.0_arch.type section priority
  144. pkg-frag-b_0.0_arch.type section priority
  145. pkg-indep_0.0.1-2_all.deb net standard
  146. pkg-templ_1.2.3_arch.type section priority
  147. FILES
  148. $dist->reset();
  149. $dist->load_dir($datadir) or error('cannot parse fragment files');
  150. is($dist->output(), $expected, 'Parse fragment directory');
  151. $expected = <<'FILES';
  152. pkg-arch_2.0.0_amd64.deb admin required
  153. pkg-indep_0.0.1-2_all.deb net standard
  154. pkg-templ_1.2.3_arch.type section priority
  155. FILES
  156. $dist->reset();
  157. $dist->load("$datadir/files-byhand") or error('cannot parse file');
  158. $dist->filter(remove => sub { $_[0]->{priority} eq 'optional' });
  159. is($dist->output(), $expected, 'Filter remove piority optional');
  160. $expected = <<'FILES';
  161. BY-HAND-file webdocs optional
  162. other_0.txt text optional
  163. FILES
  164. $dist->reset();
  165. $dist->load("$datadir/files-byhand") or error('cannot parse file');
  166. $dist->filter(keep => sub { $_[0]->{priority} eq 'optional' });
  167. is($dist->output(), $expected, 'Filter keep priority optional');
  168. $expected = <<'FILES';
  169. BY-HAND-file webdocs optional
  170. FILES
  171. $dist->reset();
  172. $dist->load("$datadir/files-byhand") or error('cannot parse file');
  173. $dist->filter(remove => sub { $_[0]->{section} eq 'text' },
  174. keep => sub { $_[0]->{priority} eq 'optional' });
  175. is($dist->output(), $expected, 'Filter remove section text, keep priority optional');
  176. 1;