600_Dpkg_Changelog.t 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. # -*- 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 strict;
  16. use warnings;
  17. use File::Basename;
  18. BEGIN {
  19. my $no_examples = 4;
  20. my $no_err_examples = 1;
  21. my $no_tests = $no_examples * 5
  22. + $no_err_examples * 2
  23. + 26 # countme
  24. + 13 # fields
  25. + 22;
  26. require Test::More;
  27. import Test::More tests => $no_tests;
  28. }
  29. BEGIN {
  30. use_ok('Dpkg::Changelog');
  31. use_ok('Dpkg::Changelog::Debian');
  32. use_ok('Dpkg::Vendor', qw(get_current_vendor));
  33. };
  34. my $srcdir = $ENV{srcdir} || '.';
  35. my $datadir = $srcdir . '/t/600_Dpkg_Changelog';
  36. my $vendor = get_current_vendor();
  37. #########################
  38. foreach my $file ("$datadir/countme", "$datadir/shadow", "$datadir/fields",
  39. "$datadir/regressions") {
  40. my $changes = Dpkg::Changelog::Debian->new(verbose => 0);
  41. $changes->load($file);
  42. open(CLOG, "<", "$file") || die "Can't open $file\n";
  43. my $content = join("", <CLOG>);
  44. close(CLOG);
  45. cmp_ok($content, 'eq', "$changes", "string output of Dpkg::Changelog on $file");
  46. my $errors = $changes->get_parse_errors();
  47. my $basename = basename( $file );
  48. is($errors, '', "Parse example changelog $file without errors" );
  49. my @data = @$changes;
  50. ok(@data, "data is not empty");
  51. my $str;
  52. if ($file eq "$datadir/countme") {
  53. # test range options
  54. cmp_ok( @data, '==', 7, "no options -> count" );
  55. my $all_versions = join( '/', map { $_->get_version() } @data);
  56. sub check_options {
  57. my ($changes, $data, $options, $count, $versions,
  58. $check_name) = @_;
  59. my @cnt = $changes->get_range($options);
  60. cmp_ok( @cnt, '==', $count, "$check_name -> count" );
  61. if ($count == @$data) {
  62. is_deeply( \@cnt, $data, "$check_name -> returns all" );
  63. } else {
  64. is( join( "/", map { $_->get_version() } @cnt),
  65. $versions, "$check_name -> versions" );
  66. }
  67. }
  68. check_options( $changes, \@data,
  69. { count => 3 }, 3, '2:2.0-1/1:2.0~rc2-3/1:2.0~rc2-2',
  70. 'positive count' );
  71. check_options( $changes, \@data,
  72. { count => -3 }, 3,
  73. '1:2.0~rc2-1sarge2/1:2.0~rc2-1sarge1/1.5-1',
  74. 'negative count' );
  75. check_options( $changes, \@data,
  76. { count => 1 }, 1, '2:2.0-1',
  77. 'count 1' );
  78. check_options( $changes, \@data,
  79. { count => 1, default_all => 1 }, 1, '2:2.0-1',
  80. 'count 1 (d_a 1)' );
  81. check_options( $changes, \@data,
  82. { count => -1 }, 1, '1.5-1',
  83. 'count -1' );
  84. check_options( $changes, \@data,
  85. { count => 3, offset => 2 }, 3,
  86. '1:2.0~rc2-2/1:2.0~rc2-1sarge3/1:2.0~rc2-1sarge2',
  87. 'positve count + positive offset' );
  88. check_options( $changes, \@data,
  89. { count => -3, offset => 4 }, 3,
  90. '1:2.0~rc2-3/1:2.0~rc2-2/1:2.0~rc2-1sarge3',
  91. 'negative count + positive offset' );
  92. check_options( $changes, \@data,
  93. { count => 4, offset => 5 }, 2,
  94. '1:2.0~rc2-1sarge1/1.5-1',
  95. 'positve count + positive offset (>max)' );
  96. check_options( $changes, \@data,
  97. { count => -4, offset => 2 }, 2,
  98. '2:2.0-1/1:2.0~rc2-3',
  99. 'negative count + positive offset (<0)' );
  100. check_options( $changes, \@data,
  101. { count => 3, offset => -4 }, 3,
  102. '1:2.0~rc2-1sarge3/1:2.0~rc2-1sarge2/1:2.0~rc2-1sarge1',
  103. 'positve count + negative offset' );
  104. check_options( $changes, \@data,
  105. { count => -3, offset => -3 }, 3,
  106. '1:2.0~rc2-3/1:2.0~rc2-2/1:2.0~rc2-1sarge3',
  107. 'negative count + negative offset' );
  108. check_options( $changes, \@data,
  109. { count => 5, offset => -2 }, 2,
  110. '1:2.0~rc2-1sarge1/1.5-1',
  111. 'positve count + negative offset (>max)' );
  112. check_options( $changes, \@data,
  113. { count => -5, offset => -4 }, 3,
  114. '2:2.0-1/1:2.0~rc2-3/1:2.0~rc2-2',
  115. 'negative count + negative offset (<0)' );
  116. check_options( $changes, \@data,
  117. { count => 7 }, 7, '',
  118. 'count 7 (max)' );
  119. check_options( $changes, \@data,
  120. { count => -7 }, 7, '',
  121. 'count -7 (-max)' );
  122. check_options( $changes, \@data,
  123. { count => 10 }, 7, '',
  124. 'count 10 (>max)' );
  125. check_options( $changes, \@data,
  126. { count => -10 }, 7, '',
  127. 'count -10 (<-max)' );
  128. check_options( $changes, \@data,
  129. { from => '1:2.0~rc2-1sarge3' }, 4,
  130. '2:2.0-1/1:2.0~rc2-3/1:2.0~rc2-2/1:2.0~rc2-1sarge3',
  131. 'from => "1:2.0~rc2-1sarge3"' );
  132. check_options( $changes, \@data,
  133. { since => '1:2.0~rc2-1sarge3' }, 3,
  134. '2:2.0-1/1:2.0~rc2-3/1:2.0~rc2-2',
  135. 'since => "1:2.0~rc2-1sarge3"' );
  136. $SIG{'__WARN__'} = sub {};
  137. check_options( $changes, \@data,
  138. { since => 0 }, 7, '',
  139. 'since => 0 returns all');
  140. delete $SIG{'__WARN__'};
  141. check_options( $changes, \@data,
  142. { to => '1:2.0~rc2-1sarge2' }, 3,
  143. '1:2.0~rc2-1sarge2/1:2.0~rc2-1sarge1/1.5-1',
  144. 'to => "1:2.0~rc2-1sarge2"' );
  145. check_options( $changes, \@data,
  146. { until => '1:2.0~rc2-1sarge2' }, 2,
  147. '1:2.0~rc2-1sarge1/1.5-1',
  148. 'until => "1:2.0~rc2-1sarge2"' );
  149. #TODO: test combinations
  150. }
  151. if ($file eq "$datadir/fields") {
  152. my $str = $changes->dpkg({ all => 1 });
  153. my $expected = 'Source: fields
  154. Version: 2.0-0etch1
  155. Distribution: stable
  156. Urgency: high
  157. Maintainer: Frank Lichtenheld <frank@lichtenheld.de>
  158. Date: Sun, 13 Jan 2008 15:49:19 +0100
  159. Closes: 1000000 1111111 2222222
  160. Changes:
  161. fields (2.0-0etch1) stable; urgency=low
  162. .
  163. * Upload to stable (Closes: #1111111, #2222222)
  164. * Fix more stuff. (LP: #54321, #2424242)
  165. .
  166. fields (2.0-1) unstable frozen; urgency=medium
  167. .
  168. [ Frank Lichtenheld ]
  169. * Upload to unstable (Closes: #1111111, #2222222)
  170. * Fix stuff. (LP: #12345, #424242)
  171. .
  172. [ Raphaël Hertzog ]
  173. * New upstream release.
  174. - implements a
  175. - implements b
  176. * Update S-V.
  177. .
  178. fields (2.0~b1-1) unstable; urgency=low,xc-userfield=foobar
  179. .
  180. * Beta
  181. .
  182. fields (1.0) experimental; urgency=high,xb-userfield2=foobar
  183. .
  184. * First upload (Closes: #1000000)
  185. Xb-Userfield2: foobar
  186. Xc-Userfield: foobar
  187. ';
  188. if ($vendor eq 'Ubuntu') {
  189. $expected =~ s/^(Closes:.*)/$1\nLaunchpad-Bugs-Fixed: 12345 54321 424242 2424242/m;
  190. }
  191. cmp_ok($str,'eq',$expected,"fields handling");
  192. $str = $changes->dpkg({ offset => 1, count => 2 });
  193. $expected = 'Source: fields
  194. Version: 2.0-1
  195. Distribution: unstable frozen
  196. Urgency: medium
  197. Maintainer: Frank Lichtenheld <djpig@debian.org>
  198. Date: Sun, 12 Jan 2008 15:49:19 +0100
  199. Closes: 1111111 2222222
  200. Changes:
  201. fields (2.0-1) unstable frozen; urgency=medium
  202. .
  203. [ Frank Lichtenheld ]
  204. * Upload to unstable (Closes: #1111111, #2222222)
  205. * Fix stuff. (LP: #12345, #424242)
  206. .
  207. [ Raphaël Hertzog ]
  208. * New upstream release.
  209. - implements a
  210. - implements b
  211. * Update S-V.
  212. .
  213. fields (2.0~b1-1) unstable; urgency=low,xc-userfield=foobar
  214. .
  215. * Beta
  216. Xc-Userfield: foobar
  217. ';
  218. if ($vendor eq 'Ubuntu') {
  219. $expected =~ s/^(Closes:.*)/$1\nLaunchpad-Bugs-Fixed: 12345 424242/m;
  220. }
  221. cmp_ok($str,'eq',$expected,"fields handling 2");
  222. $str = $changes->rfc822({ offset => 2, count => 2 });
  223. $expected = 'Source: fields
  224. Version: 2.0~b1-1
  225. Distribution: unstable
  226. Urgency: low
  227. Maintainer: Frank Lichtenheld <frank@lichtenheld.de>
  228. Date: Sun, 11 Jan 2008 15:49:19 +0100
  229. Changes:
  230. fields (2.0~b1-1) unstable; urgency=low,xc-userfield=foobar
  231. .
  232. * Beta
  233. Xc-Userfield: foobar
  234. Source: fields
  235. Version: 1.0
  236. Distribution: experimental
  237. Urgency: high
  238. Maintainer: Frank Lichtenheld <djpig@debian.org>
  239. Date: Sun, 10 Jan 2008 15:49:19 +0100
  240. Closes: 1000000
  241. Changes:
  242. fields (1.0) experimental; urgency=high,xb-userfield2=foobar
  243. .
  244. * First upload (Closes: #1000000)
  245. Xb-Userfield2: foobar
  246. ';
  247. cmp_ok($str, 'eq', $expected, "fields handling 3");
  248. # Test Dpkg::Changelog::Entry methods
  249. is($data[1]->get_version(), "2.0-1", "get_version");
  250. is($data[1]->get_source(), "fields", "get_source");
  251. is(scalar $data[1]->get_distributions(), "unstable", "get_distribution");
  252. is(join("|", $data[1]->get_distributions()), "unstable|frozen",
  253. "get_distributions");
  254. is($data[3]->get_optional_fields(),
  255. "Urgency: high\nCloses: 1000000\nXb-Userfield2: foobar\n",
  256. "get_optional_fields");
  257. is($data[1]->get_maintainer(), 'Frank Lichtenheld <djpig@debian.org>',
  258. "get_maintainer");
  259. is($data[1]->get_timestamp(), 'Sun, 12 Jan 2008 15:49:19 +0100',
  260. "get_timestamp");
  261. my @items = $data[1]->get_change_items();
  262. is($items[0], " [ Frank Lichtenheld ]\n", "change items 1");
  263. is($items[4], " * New upstream release.
  264. - implements a
  265. - implements b
  266. ", "change items 2");
  267. is($items[5], " * Update S-V.\n", "change items 3");
  268. }
  269. SKIP: {
  270. skip("avoid spurious warning with only one entry", 2)
  271. if @data == 1;
  272. my $oldest_version = $data[-1]->{Version};
  273. $str = $changes->dpkg({ since => $oldest_version });
  274. $str = $changes->rfc822();
  275. ok( 1 );
  276. $str = $changes->rfc822({ since => $oldest_version });
  277. ok( 1 );
  278. }
  279. }
  280. foreach my $test (( [ "$datadir/misplaced-tz", 6 ])) {
  281. my $file = shift @$test;
  282. my $changes = Dpkg::Changelog::Debian->new(verbose => 0);
  283. $changes->load($file);
  284. my @errors = $changes->get_parse_errors();
  285. ok(@errors, 'errors occured');
  286. is_deeply( [ map { $_->[1] } @errors ], $test, 'check line numbers' );
  287. }