test.pl 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use Path::Tiny;
  4. use Test::More tests => 29;
  5. use lib 'lib/';
  6. sub set_target {
  7. $RBM::config->{run}{target} = [@_];
  8. }
  9. sub set_distribution {
  10. $RBM::config->{run}{distribution} = $_[0];
  11. }
  12. sub set_step {
  13. $RBM::config->{step} = $_[0];
  14. }
  15. BEGIN { use_ok('RBM') };
  16. chdir 'test';
  17. RBM::load_config;
  18. RBM::set_default_env;
  19. ok($RBM::config, 'load config');
  20. my @tests = (
  21. {
  22. name => 'simple',
  23. config => [ 'a', 'option_a' ],
  24. expected => 'a',
  25. },
  26. {
  27. name => 'project',
  28. config => [ 'a', 'project_a' ],
  29. expected => 'a',
  30. },
  31. {
  32. name => 'target',
  33. target => ['target_a'],
  34. config => [ 'a', 'option_a' ],
  35. expected => 'target a',
  36. },
  37. {
  38. name => 'target project',
  39. target => ['target_b'],
  40. config => [ 'a', 'option_a' ],
  41. expected => 'b',
  42. },
  43. {
  44. name => 'triple target - 1',
  45. target => [ 'target_a', 'target_b', 'target_c' ],
  46. config => [ 'a', 'option_a' ],
  47. expected => 'b',
  48. },
  49. {
  50. name => 'triple target - 2',
  51. target => [ 'target_c', 'target_a', 'target_b' ],
  52. config => [ 'a', 'option_a' ],
  53. expected => 'c',
  54. },
  55. {
  56. name => 'target redirect - 1',
  57. target => [ 'target_d' ],
  58. config => [ 'a', 'option_a' ],
  59. expected => 'target a',
  60. },
  61. {
  62. name => 'target redirect - 2',
  63. target => [ 'target_e' ],
  64. config => [ 'a', 'option_a' ],
  65. expected => 'b',
  66. },
  67. {
  68. name => 'target redirect - 3',
  69. target => [ 'target_f' ],
  70. config => [ 'a', 'option_a' ],
  71. expected => 'c',
  72. },
  73. {
  74. name => 'template func c',
  75. config => [ 'a', 'tmpl_c1' ],
  76. expected => 'a',
  77. },
  78. {
  79. name => 'template func pc',
  80. config => [ 'a', 'tmpl_pc1' ],
  81. expected => 'project b',
  82. },
  83. {
  84. name => 'template func pc + target',
  85. target => [ 'target_a' ],
  86. config => [ 'a', 'tmpl_pc1' ],
  87. expected => 't a',
  88. },
  89. {
  90. name => 'proj target - 1',
  91. target => [ 'b:target_a' ],
  92. config => [ 'a', 'option_a' ],
  93. expected => 'a',
  94. },
  95. {
  96. name => 'proj target - 2',
  97. target => [ 'b:target_a' ],
  98. config => [ 'a', 'tmpl_pc1' ],
  99. expected => 't a',
  100. },
  101. {
  102. name => 'perl sub',
  103. config => [ 'a', 'option_d/a' ],
  104. expected => 'A a',
  105. },
  106. {
  107. name => 'step config',
  108. step => 'build',
  109. config => [ 'c', 'option_e' ],
  110. expected => 'build e',
  111. },
  112. {
  113. name => 'redirect step config',
  114. step => 'redirect',
  115. config => [ 'c', 'option_e' ],
  116. expected => 'build e',
  117. },
  118. {
  119. name => 'step + target config',
  120. step => 'build',
  121. target => [ 'version_2' ],
  122. config => [ 'c', 'option_e' ],
  123. expected => 'build e - v2',
  124. },
  125. {
  126. name => 'option overriding',
  127. step => 'build',
  128. config => [ 'a', 'Z' ],
  129. expected => 'aZa AZa aZa',
  130. },
  131. {
  132. name => 'srpm step',
  133. step => 'srpm',
  134. config => [ 'c', 'option_rpm' ],
  135. expected => '1',
  136. },
  137. {
  138. name => 'deb-src step',
  139. step => 'deb-src',
  140. config => [ 'c', 'option_deb' ],
  141. expected => '1',
  142. },
  143. {
  144. name => 'build + steps config - 1',
  145. target => [ 'version_1' ],
  146. build => [ 'c', 'build' ],
  147. files => { 'out/c-1' => "1-build e\n" },
  148. },
  149. {
  150. name => 'build + steps and targets config',
  151. target => [ 'version_2' ],
  152. build => [ 'c', 'build' ],
  153. files => { 'out/c-2' => "2-build e - v2\n" },
  154. },
  155. {
  156. name => 'multi-projects build',
  157. target => [],
  158. build => [ 'r3', 'build', { pkg_type => 'build' } ],
  159. files => {
  160. 'out/r1' => "1 - build\n",
  161. 'out/r2' => "1 - build\n2 - build\n",
  162. 'out/r3' => "1 - build\n2 - build\n3 - build\n",
  163. },
  164. },
  165. {
  166. name => 'mercurial repo',
  167. target => [],
  168. config => [ 'mozmill-automation', 't' ],
  169. expected => '432611daa42c7608d32b04c89ac26fbcea6a61663419aa88ead87116e212a004',
  170. },
  171. {
  172. name => 'mercurial repo build',
  173. target => [],
  174. build => [ 'mozmill-automation', 'build' ],
  175. files => {
  176. 'out/mozmill-automation-bbad7215c713_sha256sum.txt' =>
  177. '13660d3f3ebbc363056ccbd3794f8f78a940dd394a464093bee5fc0575ee4090 '
  178. . "mozmill-automation-bbad7215c713.tar\n",
  179. },
  180. },
  181. {
  182. name => 'build using files and directories as input',
  183. target => [],
  184. build => [ 'files_project', 'build', { pkg_type => 'build' } ],
  185. files => {
  186. 'out/files_project-57a38d32f55ac3bec035f8531bbf4574d81c6ffc41a47bfc959dc8113b86be14' =>
  187. "1\n2\n3\n4\n1\n2\n",
  188. },
  189. },
  190. );
  191. foreach my $test (@tests) {
  192. set_target($test->{target} ? @{$test->{target}} : ());
  193. set_step($test->{step} ? $test->{step} : 'rbm_init');
  194. if ($test->{config}) {
  195. is(
  196. RBM::project_config(@{$test->{config}}),
  197. $test->{expected},
  198. $test->{name}
  199. );
  200. }
  201. if ($test->{build}) {
  202. unlink keys %{$test->{files}};
  203. RBM::build_run(@{$test->{build}});
  204. my $res = grep { path($_)->slurp_utf8 ne $test->{files}{$_} } keys %{$test->{files}};
  205. ok(!$res, $test->{name});
  206. }
  207. }