600_Dpkg_Changelog.t 8.6 KB

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