Test-Rail-Parser.t 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. #!/usr/bin/env perl
  2. use strict;
  3. use warnings;
  4. use FindBin;
  5. use lib "$FindBin::Bin/lib";
  6. use Scalar::Util qw{reftype};
  7. use TestRail::API;
  8. use Test::LWP::UserAgent::TestRailMock;
  9. use Test::Rail::Parser;
  10. use Test::More 'tests' => 126;
  11. use Test::Fatal qw{exception};
  12. use Test::Deep qw{cmp_deeply};
  13. use Capture::Tiny qw{capture capture_stderr};
  14. #Same song and dance as in TestRail-API.t
  15. my $apiurl = $ENV{'TESTRAIL_API_URL'};
  16. my $login = $ENV{'TESTRAIL_USER'};
  17. my $pw = $ENV{'TESTRAIL_PASSWORD'};
  18. my $step_results = $ENV{'TESTRAIL_STEP_RESULTS'};
  19. my $is_mock = (!$apiurl && !$login && !$pw);
  20. ($apiurl,$login,$pw) = ('http://testrail.local','teodesian@cpan.org','fake') if $is_mock;
  21. my ($debug,$browser);
  22. $debug = 1;
  23. if ($is_mock) {
  24. $browser = $Test::LWP::UserAgent::TestRailMock::mockObject;
  25. }
  26. #test exceptions...
  27. #TODO
  28. my $fcontents = "
  29. fake.test ..
  30. 1..2
  31. ok 1 - STORAGE TANKS SEARED
  32. #goo
  33. not ok 2 - NOT SO SEARED AFTER ARR
  34. ";
  35. my $tap;
  36. my $opts = {
  37. 'tap' => $fcontents,
  38. 'apiurl' => $apiurl,
  39. 'user' => $login,
  40. 'pass' => $pw,
  41. 'debug' => $debug,
  42. 'browser' => $browser,
  43. 'run' => 'TestingSuite',
  44. 'project' => 'TestProject',
  45. 'merge' => 1,
  46. 'step_results' => $step_results,
  47. };
  48. my $res = exception { $tap = Test::Rail::Parser->new($opts) };
  49. is($res,undef,"TR Parser doesn't explode on instantiation");
  50. isa_ok($tap,"Test::Rail::Parser");
  51. if (!$res) {
  52. $tap->run();
  53. is($tap->{'errors'},0,"No errors encountered uploading case results");
  54. }
  55. undef $tap;
  56. delete $opts->{'tap'};
  57. $opts->{'source'} = 't/fake.test';
  58. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  59. is($res,undef,"TR Parser doesn't explode on instantiation");
  60. isa_ok($tap,"Test::Rail::Parser");
  61. if (!$res) {
  62. $tap->run();
  63. is($tap->{'errors'},0,"No errors encountered uploading case results");
  64. }
  65. $fcontents = "fake.test...
  66. ok 1 - STORAGE TANKS SEARED
  67. # whee
  68. not ok 2 - NOT SO SEARED AFTER ARR
  69. # Failed test 'NOT SO SEARED AFTER ARR'
  70. # at t/fake.test line 10.
  71. # Looks like you failed 1 test of 2.
  72. ";
  73. like($tap->{'raw_output'},qr/SEARED\n# whee.*\n.*AFTER ARR\n\n.*Failed/msxi,"Full raw content uploaded in non step results mode");
  74. #Check that time run is being uploaded
  75. my $timeResults = $tap->{'tr_opts'}->{'testrail'}->getTestResults(1);
  76. if ( ( reftype($timeResults) || 'undef') eq 'ARRAY') {
  77. is( $timeResults->[0]->{'elapsed'}, '2s', "Plugin correctly sets elapsed time");
  78. } else {
  79. fail("Could not get test results to check elapsed time!");
  80. }
  81. #Check the time formatting routine.
  82. is(Test::Rail::Parser::_compute_elapsed(0,0),undef,"Elapsed computation correct at second boundary");
  83. is(Test::Rail::Parser::_compute_elapsed(0,61),'1m 1s',"Elapsed computation correct at minute boundary");
  84. is(Test::Rail::Parser::_compute_elapsed(0,3661),'1h 1m 1s',"Elapsed computation correct at hour boundary");
  85. is(Test::Rail::Parser::_compute_elapsed(0,86461),'24h 1m 1s',"Elapsed computation correct at day boundary");
  86. undef $tap;
  87. $opts->{'source'} = 't/faker.test';
  88. $opts->{'run'} = 'OtherOtherSuite';
  89. $opts->{'step_results'} = 'step_results';
  90. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  91. is($res,undef,"TR Parser doesn't explode on instantiation");
  92. isa_ok($tap,"Test::Rail::Parser");
  93. if (!$res) {
  94. $tap->run();
  95. is($tap->{'errors'},0,"No errors encountered uploading case results");
  96. is($tap->{'global_status'},5, "Test global result is FAIL when one subtest fails even if there are TODO passes");
  97. subtest 'Timestamp/elapsed printed in step results' => sub {
  98. foreach my $result (@{$tap->{'tr_opts'}->{'result_custom_options'}->{'step_results'}}) {
  99. like($result->{'content'}, qr/^\[.*\(.*\)\]/i, "Timestamp printed in step results");
  100. }
  101. };
  102. }
  103. #Default mode
  104. undef $tap;
  105. delete $opts->{'step_results'};
  106. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  107. is($res,undef,"TR Parser doesn't explode on instantiation");
  108. isa_ok($tap,"Test::Rail::Parser");
  109. if (!$res) {
  110. $tap->run();
  111. is($tap->{'errors'},0,"No errors encountered uploading case results");
  112. my @matches = $tap->{'raw_output'} =~ m/^(\[.*\(.*\)\])/msgi;
  113. ok(scalar(@matches),"Timestamps present in raw TAP");
  114. }
  115. #Default mode
  116. undef $tap;
  117. $fcontents = "
  118. fake.test ..
  119. 1..2
  120. ok 1 - STORAGE TANKS SEARED
  121. #Subtest NOT SO SEARED AFTER ARR
  122. ok 1 - STROGGIFY POPULATION CENTERS
  123. not ok 2 - STROGGIFY POPULATION CENTERS
  124. #goo
  125. not ok 2 - NOT SO SEARED AFTER ARR
  126. ";
  127. $opts->{'tap'} = $fcontents;
  128. delete $opts->{'source'};
  129. delete $opts->{'step_results'};
  130. $opts->{'run'} = 'TestingSuite';
  131. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  132. is($res,undef,"TR Parser doesn't explode on instantiation");
  133. isa_ok($tap,"Test::Rail::Parser");
  134. if (!$res) {
  135. $tap->run();
  136. is($tap->{'errors'},0,"No errors encountered uploading case results");
  137. }
  138. undef $tap;
  139. delete $opts->{'tap'};
  140. $opts->{'source'} = 't/skip.test';
  141. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  142. is($res,undef,"TR Parser doesn't explode on instantiation");
  143. isa_ok($tap,"Test::Rail::Parser");
  144. if (!$res) {
  145. $tap->run();
  146. is($tap->{'errors'},0,"No errors encountered uploading case results");
  147. }
  148. #Default mode skip (skip_all)
  149. undef $tap;
  150. $opts->{'source'} = 't/skipall.test';
  151. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  152. is($res,undef,"TR Parser doesn't explode on instantiation");
  153. isa_ok($tap,"Test::Rail::Parser");
  154. if (!$res) {
  155. $tap->run();
  156. is($tap->{'errors'},0,"No errors encountered uploading case results");
  157. like( $tap->{raw_output}, qr/cause I can/i, "SKIP_ALL reason recorded");
  158. is($tap->{'global_status'},6, "Test global result is SKIP on skip all");
  159. }
  160. #Ok, let's test the plan, config, and spawn bits.
  161. undef $tap;
  162. $opts->{'run'} = 'hoo hoo I do not exist';
  163. $opts->{'plan'} = 'mah dubz plan';
  164. $opts->{'configs'} = ['testPlatform1'];
  165. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  166. isnt($res,undef,"TR Parser explodes on instantiation when asking for run not in plan");
  167. undef $tap;
  168. $opts->{'run'} = 'TestingSuite';
  169. $opts->{'configs'} = ['testConfig'];
  170. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  171. is($res,undef,"TR Parser doesn't explode on instantiation looking for existing run in plan");
  172. isa_ok($tap,"Test::Rail::Parser");
  173. if (!$res) {
  174. $tap->run();
  175. is($tap->{'errors'},0,"No errors encountered uploading case results");
  176. }
  177. #Now, test spawning.
  178. undef $tap;
  179. $opts->{'run'} = 'TestingSuite2';
  180. $opts->{'configs'} = ['testPlatform1'];
  181. $opts->{'testsuite_id'} = 9;
  182. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  183. is($res,undef,"TR Parser doesn't explode on instantiation when spawning run in plan");
  184. isa_ok($tap,"Test::Rail::Parser");
  185. if (!$res) {
  186. $tap->run();
  187. is($tap->{'errors'},0,"No errors encountered uploading case results");
  188. }
  189. #Test spawning of builds not in plans.
  190. #Now, test spawning.
  191. undef $tap;
  192. delete $opts->{'testsuite_id'};
  193. delete $opts->{'plan'};
  194. delete $opts->{'configs'};
  195. $opts->{'testsuite'} = 'HAMBURGER-IZE HUMANITY';
  196. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  197. is($res,undef,"TR Parser doesn't explode on instantiation when spawning run in plan");
  198. isa_ok($tap,"Test::Rail::Parser");
  199. if (!$res) {
  200. $tap->run();
  201. is($tap->{'errors'},0,"No errors encountered uploading case results");
  202. }
  203. #Test spawning of plans and runs.
  204. undef $tap;
  205. $opts->{'run'} = 'BogoRun';
  206. $opts->{'plan'} = 'BogoPlan';
  207. $opts->{'testsuite_id'} = 9;
  208. delete $opts->{'testsuite'};
  209. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  210. is($res,undef,"TR Parser doesn't explode on instantiation when spawning run in plan");
  211. isa_ok($tap,"Test::Rail::Parser");
  212. if (!$res) {
  213. $tap->run();
  214. is($tap->{'errors'},0,"No errors encountered uploading case results");
  215. }
  216. #Check that per-section spawn works
  217. undef $tap;
  218. $opts->{'source'} = 't/fake.test';
  219. delete $opts->{'plan'};
  220. $opts->{'sections'} = ['fake.test'];
  221. delete $opts->{'step_results'};
  222. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  223. is($res,undef,"TR Parser doesn't explode on instantiation");
  224. isa_ok($tap,"Test::Rail::Parser");
  225. if (!$res) {
  226. $tap->run();
  227. is($tap->{'errors'},0,"No errors encountered uploading case results");
  228. }
  229. #Check that per-section spawn works
  230. undef $tap;
  231. $opts->{'plan'} = 'BogoPlan';
  232. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  233. is($res,undef,"TR Parser doesn't explode on instantiation");
  234. isa_ok($tap,"Test::Rail::Parser");
  235. if (!$res) {
  236. $tap->run();
  237. is($tap->{'errors'},0,"No errors encountered uploading case results");
  238. }
  239. undef $tap;
  240. $opts->{'sections'} = ['potzrebie'];
  241. delete $opts->{'plan'};
  242. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  243. isnt($res,undef,"TR Parser explodes on instantiation with invalid section");
  244. undef $tap;
  245. $opts->{'source'} = 't/notests.test';
  246. delete $opts->{'sections'};
  247. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  248. is($res,undef,"TR Parser doesn't explode on instantiation");
  249. isa_ok($tap,"Test::Rail::Parser");
  250. if (!$res) {
  251. $tap->run();
  252. is($tap->{'errors'},0,"No errors encountered uploading case results");
  253. is($tap->{'global_status'},5, "Test global result is FAIL by default on env fail");
  254. }
  255. undef $tap;
  256. $opts->{'source'} = 't/pass.test';
  257. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  258. is($res,undef,"TR Parser doesn't explode on instantiation");
  259. isa_ok($tap,"Test::Rail::Parser");
  260. if (!$res) {
  261. $tap->run();
  262. is($tap->{'errors'},0,"No errors encountered uploading case results");
  263. is($tap->{'global_status'},1, "Test global result is PASS on ok test");
  264. }
  265. undef $tap;
  266. $opts->{'source'} = 't/todo_pass.test';
  267. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  268. is($res,undef,"TR Parser doesn't explode on instantiation");
  269. isa_ok($tap,"Test::Rail::Parser");
  270. if (!$res) {
  271. $tap->run();
  272. is($tap->{'errors'},0,"No errors encountered uploading case results");
  273. is($tap->{'global_status'},8, "Test global result is TODO PASS on todo pass test");
  274. }
  275. undef $tap;
  276. $opts->{'step_results'} = 'bogus_garbage';
  277. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  278. like($res,qr/invalid step results/i,"Bogus step results name throws");
  279. undef $tap;
  280. $opts->{'source'} = 't/todo_pass_and_fail.test';
  281. $opts->{'step_results'} = 'step_results';
  282. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  283. is($res,undef,"TR Parser doesn't explode on instantiation");
  284. isa_ok($tap,"Test::Rail::Parser");
  285. if (!$res) {
  286. capture { $tap->run() };
  287. is($tap->{'errors'},1,"Errors encountered uploading case results for case that does not exist in TestRail");
  288. is($tap->{'global_status'},7, "Test global result is TODO FAIL on todo pass & fail test");
  289. my @desired_statuses = qw{1 8 7};
  290. my @got_statuses = map {$_->{'status_id'}} @{$tap->{'tr_opts'}->{'result_custom_options'}->{'step_results'}};
  291. my @desired_expected = ('OK', 'OK', 'OK');
  292. my @got_expected = map {$_->{'expected'}} @{$tap->{'tr_opts'}->{'result_custom_options'}->{'step_results'}};
  293. my @desired_actual = ('OK', 'TODO PASS', 'TODO FAIL');
  294. my @got_actual = map {$_->{'actual'}} @{$tap->{'tr_opts'}->{'result_custom_options'}->{'step_results'}};
  295. cmp_deeply(\@got_expected,\@desired_expected,"Expected status names look OK");
  296. cmp_deeply(\@got_actual,\@desired_actual,"Actual status names look OK");
  297. cmp_deeply(\@got_statuses,\@desired_statuses,"Step result status codes set correctly");
  298. like($tap->{'tr_opts'}->{'test_notes'},qr/ez duz it/i,"TODO reason captured in test notes");
  299. }
  300. undef $opts->{'step_results'};
  301. undef $tap;
  302. #Check bad plan w/ todo pass logic
  303. $fcontents = "
  304. todo_pass.test ..
  305. 1..2
  306. ok 1 - STORAGE TANKS SEARED #TODO todo pass
  307. # goo
  308. ";
  309. undef $opts->{'source'};
  310. $opts->{'tap'} = $fcontents;
  311. $opts->{'step_results'} = 'step_results';
  312. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  313. is($res,undef,"TR Parser doesn't explode on instantiation");
  314. isa_ok($tap,"Test::Rail::Parser");
  315. if (!$res) {
  316. $tap->run();
  317. is($tap->{'errors'},0,"No errors encountered uploading case results");
  318. is($tap->{'global_status'},5, "Test global result is FAIL on todo pass test w/ bad plan");
  319. my $srs = $tap->{'tr_opts'}->{'result_custom_options'}->{'step_results'};
  320. is($srs->[-1]->{'content'},"Bad Plan.","Bad plan noted in step results");
  321. }
  322. undef $opts->{'step_results'};
  323. #Check instant pizza
  324. $fcontents = "
  325. todo_pass.test ..
  326. 1..2
  327. ";
  328. undef $opts->{'source'};
  329. $opts->{'tap'} = $fcontents;
  330. $opts->{'step_results'} = 'step_results';
  331. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  332. is($res,undef,"TR Parser doesn't explode on instantiation");
  333. isa_ok($tap,"Test::Rail::Parser");
  334. if (!$res) {
  335. $tap->run();
  336. is($tap->{'errors'},0,"No errors encountered uploading case results");
  337. is($tap->{'global_status'},5, "Test global result is FAILURE when insta-bombout occurs");
  338. my $srs = $tap->{'tr_opts'}->{'result_custom_options'}->{'step_results'};
  339. is($srs->[-1]->{'content'},"Bad Plan.","Bad plan noted in step results");
  340. }
  341. $opts->{test_bad_status} = 'bogus_status';
  342. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  343. like($res,qr/bogus_status/,"TR Parser explodes on instantiation w bogus status");
  344. $opts->{test_bad_status} = 'blocked';
  345. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  346. is($res,undef,"TR Parser doesn't explode on instantiation");
  347. isa_ok($tap,"Test::Rail::Parser");
  348. if (!$res) {
  349. $tap->run();
  350. is($tap->{'errors'},0,"No errors encountered uploading case results");
  351. is($tap->{'global_status'},2, "Test global result is BLOCKED when insta-bombout occurs & custom status set");
  352. }
  353. undef $opts->{'step_results'};
  354. #Check unplanned tests
  355. $fcontents = "
  356. todo_pass.test ..
  357. 1..1
  358. ok 1 - STORAGE TANKS SEARED
  359. ok 2 - ZIPPPEEE
  360. ";
  361. $opts->{'tap'} = $fcontents;
  362. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  363. is($res,undef,"TR Parser doesn't explode on instantiation");
  364. isa_ok($tap,"Test::Rail::Parser");
  365. if (!$res) {
  366. $tap->run();
  367. is($tap->{'errors'},0,"No errors encountered uploading case results w/ unplanned tests");
  368. is($tap->{'global_status'},5, "Test global result is FAIL when unplanned test seen without case-per-ok");
  369. }
  370. undef $tap;
  371. #Check bad plan w/ todo pass logic
  372. $fcontents = "
  373. todo_pass.test ..
  374. 1..2
  375. ok 1 - STORAGE TANKS SEARED #TODO todo pass
  376. # goo
  377. % mark_status=todo_fail #Appears tanks weren't so sealed after all
  378. ";
  379. undef $opts->{'source'};
  380. $opts->{'tap'} = $fcontents;
  381. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  382. is($res,undef,"TR Parser doesn't explode on instantiation");
  383. isa_ok($tap,"Test::Rail::Parser");
  384. if (!$res) {
  385. $tap->run();
  386. is($tap->{'errors'},0,"No errors encountered uploading case results");
  387. is($tap->{'global_status'},7, "Test global result is respected when using global status override");
  388. }
  389. undef $opts->{'tap'};
  390. #Check autoclose functionality against Run with all tests in run status.
  391. undef $tap;
  392. $opts->{'source'} = 't/skip.test';
  393. $opts->{'run'} = 'FinalRun';
  394. $opts->{'autoclose'} = 1;
  395. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  396. is($res,undef,"TR Parser doesn't explode on instantiation");
  397. isa_ok($tap,"Test::Rail::Parser");
  398. if (!$res) {
  399. $tap->run();
  400. is($tap->{'errors'},0,"No errors encountered uploading case results");
  401. is($tap->{'run_closed'},1, "Run closed by parser when all tests done");
  402. }
  403. #Check autoclose functionality against Run with not all tests in run status.
  404. undef $tap;
  405. $opts->{'source'} = 't/todo_pass.test';
  406. $opts->{'run'} = 'BogoRun';
  407. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  408. is($res,undef,"TR Parser doesn't explode on instantiation");
  409. isa_ok($tap,"Test::Rail::Parser");
  410. if (!$res) {
  411. $tap->run();
  412. is($tap->{'errors'},0,"No errors encountered uploading case results");
  413. is($tap->{'run_closed'},undef, "Run not closed by parser when results are outstanding");
  414. }
  415. #Check that autoclose works against plan with all tests in run status
  416. undef $tap;
  417. $opts->{'source'} = 't/fake.test';
  418. $opts->{'run'} = 'FinalRun';
  419. $opts->{'plan'} = 'FinalPlan';
  420. $opts->{'configs'} = ['testConfig'];
  421. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  422. is($res,undef,"TR Parser doesn't explode on instantiation");
  423. isa_ok($tap,"Test::Rail::Parser");
  424. if (!$res) {
  425. $tap->run();
  426. is($tap->{'errors'},0,"No errors encountered uploading case results");
  427. is($tap->{'plan_closed'},1, "Plan closed by parser when all tests done");
  428. }
  429. #Check that autoclose works against plan with all tests not in run status
  430. undef $tap;
  431. $opts->{'run'} = 'BogoRun';
  432. $opts->{'plan'} = 'BogoPlan';
  433. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  434. is($res,undef,"TR Parser doesn't explode on instantiation");
  435. isa_ok($tap,"Test::Rail::Parser");
  436. if (!$res) {
  437. $tap->run();
  438. is($tap->{'errors'},0,"No errors encountered uploading case results");
  439. is($tap->{'plan_closed'},undef, "Plan not closed by parser when results are outstanding");
  440. }
  441. #Plan but no run 'splodes
  442. undef $tap;
  443. $opts->{'plan'} = 'CompletePlan';
  444. delete $opts->{'run'};
  445. delete $opts->{'configs'};
  446. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  447. like($res,qr/but no run passed/i,"TR Parser explodes on instantiation due to passing plan with no run");
  448. #Check that trying without spawn opts, using completed plan fails
  449. undef $tap;
  450. $opts->{'plan'} = 'ClosedPlan';
  451. $opts->{'run'} = 'BogoRun';
  452. delete $opts->{'testsuite_id'};
  453. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  454. like($res,qr/plan provided is completed/i,"TR Parser explodes on instantiation due to passing closed plan");
  455. #Check that the above two will just spawn a new plan in these cases
  456. $opts->{'testsuite_id'} = 9;
  457. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  458. is($res,undef,"TR Parser runs all the way through on completed run when spawning");
  459. #Check that trying without spawn opts, using completed run fails
  460. undef $tap;
  461. delete $opts->{'testsuite_id'};
  462. delete $opts->{'plan'};
  463. $opts->{'run'} = 'ClosedRun';
  464. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  465. like($res,qr/run provided is completed/i,"TR Parser explodes on instantiation due to passing closed run");
  466. #Check that the above two will just spawn a new run in these cases
  467. $opts->{'testsuite_id'} = 9;
  468. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  469. is($res,undef,"TR Parser runs all the way through on completed run when spawning");
  470. $fcontents = "
  471. todo_pass.test ..
  472. 1..2
  473. ok 1 - STORAGE TANKS SEARED #TODO todo pass
  474. # goo
  475. Bail out! #YOLO
  476. ";
  477. undef $opts->{'source'};
  478. $opts->{'tap'} = $fcontents;
  479. $opts->{'step_results'} = 'step_results';
  480. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  481. is($res,undef,"TR Parser runs all the way through on bailout");
  482. if (!$res) {
  483. $tap->run();
  484. is($tap->{'errors'},0,"No errors encountered uploading case results");
  485. is($tap->{'global_status'},5, "Test global result is FAIL on todo pass test w/ bailout");
  486. my $srs = $tap->{'tr_opts'}->{'result_custom_options'}->{'step_results'};
  487. is($srs->[-1]->{'content'},"Bail Out!.","Bailout noted in step results");
  488. }
  489. #Check section spawn recursion is done correctly
  490. undef $opts->{'tap'};
  491. $opts->{'source'} = 't/pass.test';
  492. $opts->{'testsuite_id'} = 5;
  493. $opts->{'project_id'} = 3;
  494. $opts->{'run'} = 'zippyRun';
  495. $opts->{'sections'} = ['Recursing section','grandchild'];
  496. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  497. is($res,undef,"TR Parser runs all the way through when recursing sections");
  498. if (!$res) {
  499. $tap->run();
  500. is($tap->{'errors'},0,"No errors encountered uploading case results");
  501. }
  502. #Check configuration group spawn is done correctly
  503. undef $opts->{'tap'};
  504. $opts->{'source'} = 't/pass.test';
  505. $opts->{'project_id'} = 9;
  506. $opts->{'run'} = 'TestingSuite';
  507. $opts->{'plan'} = 'mah dubz plan';
  508. $opts->{'config_group'} = 'noSuchGroup';
  509. $opts->{'configs'} = ['noSuchConfig'];
  510. $opts->{'sections'} = [];
  511. $res = exception { $tap = Test::Rail::Parser->new($opts) };
  512. is($res,undef,"TR Parser runs all the way through when spawning configurations");
  513. $fcontents = "
  514. todo_pass.test ..
  515. ok 1 - STORAGE TANKS SEARED #TODO todo pass
  516. # goo
  517. Bail out! #YOLO
  518. ";
  519. undef $opts->{'source'};
  520. $opts->{'tap'} = $fcontents;
  521. #Issue 143
  522. my $warns = capture_stderr { $tap = Test::Rail::Parser->new($opts) };
  523. is($warns, '', "No warnings parsing TAP with undef plans");
  524. #Issue 140
  525. $fcontents = "
  526. todo_pass.test ..
  527. ";
  528. undef $opts->{'source'};
  529. $opts->{'tap'} = $fcontents;
  530. $warns = capture_stderr { $tap = Test::Rail::Parser->new($opts) };
  531. is($warns, '', "No warnings parsing TAP with NOTESTS");